123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.sf.controller;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- @Controller
- @RequestMapping("/thymeleaf")
- public class HelloController {
- // http://localhost:8080/springmvc_demo/thymeleaf/hello
- @GetMapping("/hello")
- public String hello(Model model) {
- // 通过前缀和后缀拼接后的页面名字
- // /WEB-INF/templates/hello.html
- model.addAttribute("name", "Hello Thymeleaf");
- return "hello";
- }
- // http://localhost:8080/springmvc_demo/thymeleaf/testThymeleaf
- // 转发和重定向
- @GetMapping("/testThymeleaf")
- public String testThymeleaf() {
- // /WEB-INF/templates/test.html
- return "test";
- }
- // http://localhost:8080/springmvc_demo/thymeleaf/testForward
- @GetMapping("/testForward")
- public String testForward() {
- // /WEB-INF/templates/test.html
- return "forward:/thymeleaf/testThymeleaf";
- }
- // http://localhost:8080/springmvc_demo/thymeleaf/testRedirect
- @GetMapping("/testRedirect")
- public String testRedirect() {
- return "redirect:/thymeleaf/testThymeleaf";
- }
- }
|