一 页面以html/JSP显示
1.在pom文件中引入依赖【spring-boot-starter-thymeleaf,nekohtml】
<!-- JSP页面***************START-->
<!-- servlet 依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- tomcat 的支持.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSP页面***************END -->
<!-- HTML***************Start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<!-- 允许使用非严格的 HTML 语法 -->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
<!-- HTML***************end-->
2.在配置文件application.properties中加入属性
server.port=80
#jsp (**前面的斜杆不能漏**)
spring.mvc.view.prefix=/WEB-INF/views/system/
spring.mvc.view.suffix=.jsp
#html (**前面的斜杆不能漏**)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.model=LEGACYHTML5
3.控制层
@Controller
@RequestMapping("user")
public class LoginController {
/**
* HTML
* @return
*/
@RequestMapping("login")
public String login(){
return "index";
}
/**
* JSP
* @return
*/
@RequestMapping("index")
public String index(){
return "login";
}
}
4.测试页面
http://localhost/user/login
http://localhost/user/index
(中文显示乱码,jsp行添加
<%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%>
)