上一篇:springboot 1.5.4 之web开发(三)
1 Spring Boot添加JSP支持Spring Boot默认是不支持jsp的,集成使用步骤:
spring-boot相关项目源码,
码云地址:https://git.oschina.net/wyait/springboot1.5.4.git
github地址:https://github.com/wyait/spring-boot-1.5.4.git
② pom依赖
<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
项目源码,
码云地址:https://git.oschina.net/wyait/springboot1.5.4.git
github地址:https://github.com/wyait/spring-boot-1.5.4.git
spring boot系列文章:
spring boot 1.5.4 集成devTools(五)
spring boot 1.5.4 集成JdbcTemplate(六)
spring boot 1.5.4 集成spring-Data-JPA(七)
spring boot 1.5.4 定时任务和异步调用(十)
spring boot 1.5.4 整合log4j2(十一)
spring boot 1.5.4 整合 mybatis(十二)
spring boot 1.5.4 整合 druid(十三)
spring boot 1.5.4 之监控Actuator(十四)
spring boot 1.5.4 整合webService(十五)
spring boot 1.5.4 整合redis、拦截器、过滤器、监听器、静态资源配置(十六)
spring boot 1.5.4 整合rabbitMQ(十七)