Thymeleaf模板
关于Thymeleaf的优点:它就是html页面。
1.相关pom依赖配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Springboot官方文档建议在开发是将缓存关闭,就在application.properties文件中加入以下代码:
spring.thymeleaf.cache=false
注:正式环境还是要将缓存开启的
对应后台代码:
package com.wang.springboot01.Entity;
import lombok.Data;
/**
* @author wang
* @site https://blog.csdn.net/qq_45432593
* @create 2020-11-27 16:09
*/
@Data
public class User {
private Integer uid;
private String uname;
private String pwd;
public User() {
}
public User(Integer uid, String uname, String pwd) {
this.uid = uid;
this.uname = uname;
this.pwd = pwd;
}
}
package com.wang.springboot01.Controller;
import com.wang.springboot01.Entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* @author wang
* @site https://blog.csdn.net/qq_45432593
* @create 2020-11-27 16:10
*/
@Controller
@RequestMapping("/thymeleaf")
public class UserController {
@RequestMapping("/list")
public String hello(HttpServletRequest request){
/**
* 1.获取单个值
* 2.能够在html页面进行遍历展示
* 3.如何在html页面转义html代码块
*/
request.setAttribute("msg","传单个字符串");
List<User> userList=new ArrayList<>();