Reflect grouping in directory structure
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.example.thymeleaf.webmvc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE)
|
||||
public class TestController {
|
||||
|
||||
@GetMapping("/greeting")
|
||||
@RegisterReflectionForBinding(IndexModel.class)
|
||||
public String index(@RequestParam(defaultValue = "world") String name, Model model) {
|
||||
model.addAttribute("model", new IndexModel("Hello", name));
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping("/authors")
|
||||
@RegisterReflectionForBinding(Author.class)
|
||||
public String authors(Model model) {
|
||||
model.addAttribute("authors", List.of(new Author("Brian Goetz"), new Author("Joshua Bloch")));
|
||||
return "authors";
|
||||
}
|
||||
|
||||
public record IndexModel(String greeting, String name) {
|
||||
}
|
||||
|
||||
public record Author(String name) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.example.thymeleaf.webmvc;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ThymeleafWebMvcApplication {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
SpringApplication.run(ThymeleafWebMvcApplication.class, args);
|
||||
Thread.currentThread().join(); // To be able to measure memory consumption
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user