TP1 : Initiation avec SpringBoot
Environnement utilisé :
• Spring Tools Suite (4)
Préparation du projet :
Choisir les dépendances ; Spring Web, Thymeleaf, et Spring Boot DevTools.
Exemple 1
@SpringBootApplication
@RestController
public class FirstAppApplication {
public static void main(String[] args) {
[Link]([Link], args);
@RequestMapping(value = "/")
public String hello() {
return "Hello World";
}
Exemple 2
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World")
String name) {
return [Link]("Hello %s!", name);
}
Exemple3 :
Créer une page nommé « [Link] » dans le répertoire : src/main/resources/static/
<!DOCTYPE HTML>
<html>
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p>Welcome Message <a href="/">here</a></p>
</body>
</html>
Tester l’URL : htt://localhost : 8080/[Link]
Refaire avec :
<p>Welcome Message <a href="/hello?name=Admin">here</a></p>