spring-boot-jsp
来源:互联网 发布:四大工资2017 知乎 编辑:程序博客网 时间:2024/06/05 00:37
JSP Spring Boot官方不推荐使用,建议使用Thymeleaf。
创建Maven web project
使用STS新建一个Maven Web Project ,项目取名为:spring-boot-jsp
在pom.xml文件添加依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.3.RELEASE</version></parent><!-- web支持: 1、web mvc; 2、restful; 3、jackjson支持; 4、aop ........ --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- servlet依赖. --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope></dependency> <!-- JSTL--> <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>Jdk编译版本:<build> <finalName>spring-boot-jsp</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins></build>配置application.properties支持jsp添加src/main/resources/application.properties内容# 页面默认前缀目录spring.mvc.view.prefix=/WEB-INF/jsp/# 响应页面默认后缀spring.mvc.view.suffix=.jsp# 自定义属性,可以在Controller中读取application.hello=Hello cpit From application编写Controller@Controllerpublic class HelloController { @Value("${application.hello:Hello Angel}") private String hello; @RequestMapping("/helloJsp") public String helloJsp(Map<String, Object> map) { System.out.println("HelloController.helloJsp().hello=" + hello); map.put("hello", hello); return "helloJsp"; }}编写JSP页面在 src/main 下面创建 webapp/WEB-INF/jsp 目录用来存放我们的jsp页面:hello.jsp<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type"content="text/html; charset=UTF-8"><title>Insert title here</title></head><body>${hello} </body></html>编写启动类:App.java@SpringBootApplicationpublic class App extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(App.class, args); }}
右键Run As Java Application访问:http://127.0.0.1:8080/hello 可以访问到:
热部署:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId></dependency>加入siteMesh引入jar包<dependency> <groupId>org.sitemesh</groupId> <artifactId>sitemesh</artifactId> <version>3.0.1</version></dependency>配置化:@Configurationpublic class WebConfig extends WebMvcConfigurerAdapter{ @Bean public FilterRegistrationBean siteMeshFilter(){ FilterRegistrationBean fitler = new FilterRegistrationBean(); WebSiteMeshFilter siteMeshFilter = new WebSiteMeshFilter(); fitler.setFilter(siteMeshFilter); return fitler; }}引入静态资源(css,js,图片….)添加application.properties内容spring.resources.static-locations=classpath:/static/1.png路径:src/main/resource/static/images/<img src="/images/1.png" />
代码下载:http://download.csdn.net/detail/qq_30364013/9775039
0 0
- Spring Boot JSP
- spring boot jsp
- spring boot + jsp
- Spring boot-jsp
- spring boot tomcat jsp
- Spring Boot JSP 404
- spring-boot-jsp
- Spring Boot+JSP
- spring boot之jsp
- Spring Boot 集成JSP
- Spring Boot与Jsp
- Spring-Boot使用jsp
- Spring Boot (二) Spring Boot for JSP
- spring-boot,jdbc,jsp配置
- Spring-Boot 与jsp/freemarkerDemo
- Spring Boot 添加JSP支持
- Spring Boot 添加JSP支持
- Spring boot(11) 使用jsp
- spring jar包详解及jar包下载
- WPF metro扁平化UI控件库:MahApps.Metro
- log4jdbc记录SQL信息
- 谷歌浏览器发生个人资料错误
- java-JDBC-ResultSet详解(java数据库操作)
- spring-boot-jsp
- SSH 框架整合(maven版本 xml配置方式 连接池c3p0)
- linux命令记录
- Jenkins 部署
- VS2010 C/C++实用操作
- 史上最全的MonkeyRunner自动化测试从入门到精通(9)
- memset()函数及其作用
- React Native进阶之Animated动画库详解
- Hibernate框架的修改问题