代码结构:

第十八章 springboot + thymeleaf

1、ThymeleafController

 1 package com.xxx.firstboot.web;
 2 
 3 import org.springframework.stereotype.Controller;
 4 import org.springframework.ui.Model;
 5 import org.springframework.web.bind.annotation.RequestMapping;
 6 import org.springframework.web.bind.annotation.RequestMethod;
 7 import org.springframework.web.bind.annotation.RequestParam;
 8 import org.springframework.web.bind.annotation.ResponseBody;
 9 
10 import io.swagger.annotations.Api;
11 import io.swagger.annotations.ApiOperation;
12 
13 @Api("测试Thymeleaf和devtools")
14 @Controller
15 @RequestMapping("/thymeleaf")
16 public class ThymeleafController {
17 
18     @ApiOperation("第一个thymeleaf程序")
19     @RequestMapping(value = "/greeting", method = RequestMethod.GET)
20     public String greeting(@RequestParam(name = "name", required = false, defaultValue = "world") String name,
21                            Model model) {
22         model.addAttribute("xname", name);
23         return "index";
24     }
25 
26     @ApiOperation("thymeleaf ajax")
27     @ResponseBody
28     @RequestMapping(value = "/ajax", method = RequestMethod.GET)
29     public String ajax(@RequestParam("username") String username) {
30         return username;
31     }
32 
33 }
View Code

相关文章: