<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!--spring boot项目的parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<groupId>com.wyait.boot</groupId>
<artifactId>spring-boot-jsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<!--spring boot 引入Web模块。自动配置:tomcat、springmvc、jackson等 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--tomcat 的支持. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--添加<scope>provided</scope>,因为provided表明该包只在编译和测试的时候用 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!--配置spring boot之maven插件 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
③ 配置application.properties,并添加jsp支持
④ 编写DemoApplication
⑤ 编写Controller 和 user对象
@Controller
public class HelloController {
/**
*
* @描述:跳转到thymeleaf页面
* @创建人:wyait
* @创建时间:2017年6月27日10:40:22
* @param map
* @return
*/
@RequestMapping("/hello")
publicString toDemo(ModelMap map) {
Useruser = new User();
user.setId(5L);
user.setAge(26);
user.setName("张三");
map.addAttribute("user",user);
return"hello";
}
}
⑥ 编写jsp页面
<%@ pagelanguage="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>This is Spring Bootjsp</title>
</head>
<body>
<h2>这是一个jsp页面</h2>
<hr/>
<p>我叫${user.name },今年${user.age },编号:${user.id}</p>
</body>
</html>
⑦ 启动,访问:http://127.0.0.1:8080/hello
本文转自 wyait 51CTO博客,原文链接:http://blog.51cto.com/wyait/1967356,如需转载请自行联系原作者