1、Thymeleaf模板
关于Thymeleaf的优点,我只说一条:它就是html页面。下面直接上代码
相关pom依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
我们习惯将application.properties改成application.yml这样层级结构更好展示
Spring Boot官方文档建议在开发时将缓存关闭,那就在application.properties文件中加入下面这行
spring.thymeleaf.cache=false
application.yml
server:
port: 80
servlet:
context-path: /
# 关闭缓存thymeleaf,等待正式运行时开启
spring:
thymeleaf:
cache: false
user类
package com.ljy.springboot01.entity;
import lombok.Data;
/**
* @author ljy
* @site www.fellingss.com
* @company
* @create 2019-12-28 19:53
*/
@Data
public class User {
private Integer uid;
private String uname;
private String upwd;
public User(Integer uid, String uname, String upwd) {
this.uid = uid;
this.uname = uname;
this.upwd = upwd;
}
public User() {
}
}
UserController
package com.ljy.springboot01.controller;
import com.ljy.springboot01.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
/**
* @author ljy
* @site www.fellingss.com
* @company
* @create 2019-12-28 19:44
* 介绍thymeleaf模板引擎的应用
*/
@Controller
@RequestMapping("/thymeleaf")
public class UserController {
@RequestMapping("/list")
public ModelAndView list(){
System.out.println("这是list");
ModelAndView mv = new ModelAndView();