SpringBoot集成jsp
1.在pom.xml加入相应的依赖和定义位置
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
.....
<build>
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>*.*</include>
</includes>
</resource>
</resources>
2.在application.properties加上配置视图解析器
#配置视图解析器
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
3.创建controller.java
@Controller
public class IndexController {
@RequestMapping(value = "/say")
public ModelAndView say() {
ModelAndView mv = new ModelAndView();
mv.addObject("message","Hello,SpringBoot");
mv.setViewName("say");
return mv;
}
@RequestMapping(value = "/index")
public String index(Model model) {
model.addAttribute("message","HelloWorld");
return "say";
}
}
4.在src.main在创建webapp文件夹再创建show.jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>