Spring Boot系列02-Spring Boot + JSP 整合进行网页开发
2017-10-26 13:21
615 查看
IDE创建Maven项目
MVC展示层模板Spring Boot官方不推荐使用JSP,但是像我这有已经用惯了JSP,再换FreeMarker/Velocity学习成本有点大。
还用JSP,有两块需要注意的地方。
需要创建Maven web项目,在IDE中创建maven项目时,ArtifactId选maven-archtype-webapp
需要在src/main/resources目录下的核心配置文件application.properties中追加如下配置
application.properties
spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp
最简单pom依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <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> </dependencies>
JSP页面开发
新建源文件夹src/main/webapp在src/main/webapp下创建WEB-INF/views文件夹
tt.jsp内容如下
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="zh"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Full Layout - jQuery EasyUI Demo</title> </head> <body> <input type="button" value="点我" onclick="f()"/> <input type="text" style="height:100px;width:90%" id="input"/> </body> </html>
Java后端代码
driver.TesterMan.javapackage driver; import java.util.Map; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @EnableAutoConfiguration @Controller public class TesterMan{ public static void main(String[] args) throws Exception { SpringApplication.run(TesterMan.class, args); System.out.println("spring boot running ..."); } @RequestMapping("/tt") public String index(Map<String,Object> ){ return "/tt"; } }
测试
以java application运行程序
在浏览器访问localhost:8080/tt
看到一个按钮控件、一个文本框控件,说明Spring Boot + Jsp整合成功
相关文章推荐
- 在Spring Boot 应用中使用JSP开发网页
- 在SpringBoot中使用JSP开发网页
- SpringMVC经典系列-02基于Spring2.5注解的方式进行项目开发---【LinusZhu】
- Spring Boot整合Dubbo开发系列(一)----一个简单的示例
- SpringBoot整合mybatis进行快速开发
- 在Spring Boot 应用中使用JSP开发网页
- 被版本更新坑到哭系列:SpringBoot整合Kafka
- idea整合 spring boot jsp mybatis
- [原]Java web学习系列之 Java web开发中的Spring整合Hibernate
- Spring Boot 系列(五)web开发-Thymeleaf、FreeMarker模板引擎
- springboot+rabbitMq整合开发实战一
- Spring Boot系列八 spring boot集成jsp、restful接口、springmvc基本功能
- Spring Boot学习总结(2)——Spring Boot整合Jsp
- [Gradle中文教程系列]-跟我学Gradle-8.7.多模块项目之 - spring boot + gradle + 构建公共jsp页面的多模块项目
- spring-boot整合mybatis(使用Fiddler抓包工具进行测试)
- 【SpringBoot教程六】:SpringBoot+JSP 开发
- Spring boot 整合CXF开发web service示例
- Spring Boot、Mybatis框架整合开发Java RESTful Web Service
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- springboot开发笔记(5.2 整合rocketmq)