☰
-
Php 95
-
Java 94
-
Javascript 37
-
Regex 18
-
Git 17
-
Security 16
-
Docker 07
-
Python 58
-
Machine Learning 14
-
Book Highlights
Java
/
Spring Boot
- 1 Basics 9
-
Classes S
-
Objects S
-
Arrays S
-
Variables S
-
Loops S
-
Numbers S
-
Strings S
-
Exceptions S
-
Regexp S
- 2 OOP 9
-
Inheritance
-
Polymorphism
-
Static S
-
Abstract
-
Interfaces
-
Constructors S
-
Packages
-
Nested Classes
-
Final
- 3 Compiler 2
-
Sublime Text S
-
Apache Ant
- 4 Collections 8
-
Lists
-
Comparable S
-
Sets
-
Maps
-
Generics
-
Properties
-
Streams
-
Json
- 5 Threads 4
-
Create Thread S
-
Sleep
-
Lock
-
Scheduler
- 6 Design Patterns 4
-
Singleton
-
Observer
-
Strategy
-
Mediator
- 7 Swing 12
-
Frame
-
Panel
-
Listener
-
Combo Box
-
Label
-
Image
-
Menu
-
Table
-
Layout
-
Drawing
-
Timer
-
Designer
- 8 I/O 7
-
Streams IO
-
Socket
-
Watching Files
-
Mail
-
Logger
-
Clipboard
-
Encrypt S
- 9 Effective 7
-
Constructors S
-
Dependency Injection
-
Composition
-
Interfaces Default
-
Import Static S
-
Enums
-
Lambdas
- 10 Junit 5
-
About Junit S
-
Test Case
-
Suite Test
-
Annotations
-
Exceptions
- 11 Lambdas 7
-
Expressions S
-
Functional Interfaces
-
Streams
-
Common Operations
-
Default Methods
-
Static Methods S
-
Single Responsibility
- 12 JavaFX 6
-
Openjfx
-
Scene Builder
-
First App
-
Jar Archive
-
On Action
-
Change Listener
- 13 Maven 4
-
Demo
-
Spring Boot
-
Junit
-
Guava
- 14 Spring Boot 8
-
Quick start S
-
Rest service
-
Consuming Rest
-
Templates
-
Security
-
Command Line
-
Scheduling Tasks
-
Ajax
R
Q
TEMPLATES
Generate a new Spring Boot project (start.spring.io or IDE). As dependencies use Spring Web, Thymealf and Spring Boot DevTools.
/**
* /webcontent/src/main/java/com/example/App.java
*/
package com.example.webcontent;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
The GreetingController handle GET requests for /greeting.
It returns the name of the View responsible to render html content.
package com.example.webcontent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class GreetingController {
/**
* RequestParam binds the value of GET username
* into the name parameter of greeting() method
*/
@GetMapping("/greeting")
public String greeting(
@RequestParam(name="username", required=false, defaultValue="guest")
String str, Model model) {
model.addAttribute("name", str);
return "greeting";
}
}
Thymeleaf parses the greeting.html template.
# /src/main/resources/templates/greeting.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.trymeleaf.org">
<head>
<title>MyPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'"/>
</body>
</html>
With Spring Boot DevTools you don't need to restart the server.
./mvnx spring-boot:run
http://localhost:8080/greeting
#Hello, guest!
http://localhost:8080/greeting?username=John
#Hello, John!
You can also build a single executable JAR file (contains all dependencies).
./mvnw clean package
cd target/
java -jar webcontent-0.0.1-SNAPSHOT.jar
# pom.xml
<version>0.0.1-SNAPSHOT</version>
➥ Questions
Last update: 500 days ago