Spring Boot学习笔记-整合Jsp (二)
来源:互联网 发布:服务器监控软件 编辑:程序博客网 时间:2024/05/21 10:37
- 首先添加Jsp依赖
<!-- JSP --><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></dependency>
此时整个pom.xml文件如下:
<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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.chen</groupId> <artifactId>springbootlearn</artifactId> <version>1.0.0</version> <packaging>war</packaging> <name>springbootlearn</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <!-- 直接继承Spring boot比较简单 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.0.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- JSP --> <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> </dependency> <!-- Test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!-- Sping boot build tools --> <build> <finalName>springbootlearn</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build></project>
- 创建application.properties文件,指定Jsp路径及后缀
spring.mvc.view.prefix: /WEB-INF/templates/spring.mvc.view.suffix: .jsp
- 在WEB-INF/templates下创建helloJsp.jsp,jsp代码如下:
<%@ page language="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><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>SpringBootLearn--hellojsp</title></head><body>This is a Jsp page.<br />${hello}</body></html>
- 编写控制器代码(我懒,直接在App启动类添加了)
@RequestMapping("/helloJsp") public ModelAndView helloJsp(Map<String, Object> map) { map.put("hello", "SpringBoot"); return new ModelAndView("helloJsp",map); }
- 开始运行,结果如下:
0 0
- Spring Boot学习笔记-整合Jsp (二)
- spring boot学习笔记(二)
- Spring Boot学习笔记(二)
- Spring Boot 学习笔记(二)
- Spring Boot学习总结(2)——Spring Boot整合Jsp
- spring boot 学习(二)spring boot 框架整合 thymeleaf
- spring boot 学习(二)spring boot 框架整合 thymeleaf
- (三) Spring Boot学习笔记之Spring Boot整合Logback
- Spring Boot学习笔记-整合Mybatis (三)
- Spring Boot 学习笔记--整合Redis
- Spring读书学习笔记(二)——Spring boot
- [三]Spring Boot 整合jsp
- spring boot + mybatis + jsp整合
- Spring-Boot学习(3)-----Spring-Boot整合mybatis
- Spring boot 学习笔记—带来的好处(二)
- Spring Boot 学习笔记(二)——使用
- Spring-Boot学习笔记(二) 配置文件之初步使用
- Spring Boot学习笔记----mybatis注解(二)
- XML中>,<,&,',"的转义
- jvm-类加载器
- 字符串的子串问题详解
- 洗发牌程序2(用getpid取得进程识别码实现)
- android基础学习6——intent实现数据传递
- Spring Boot学习笔记-整合Jsp (二)
- Android开发命名规范和编码规范
- 关于tpshop5的单字母函数M,D。
- 在Ubuntu 14.04 LTS中添加和删除PPA软件源
- SVG defs元素
- 使用javabean把小写金额转换成大写金额
- python os.path模块常用方法详解
- 基于proteus的51单片机仿真实例五十七、定时器/计数器T0的定时实例
- 操作系统开发技术(Linux内核编译)-新系统调用设计实验