1、建立项目
Java Controller
package com.springboot.jsp.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import java.util.HashMap;
import java.util.Map; /******************************
* @author : liuyang
* <p>ProjectName:12-jsp </p>
* @ClassName : MyController
* @date : 2018/7/27 0027
* @time : 21:48
* @createTime 2018-07-27 21:48
* @version : 2.0
* @description :
*
*
*
*******************************/ @Controller
public class MyController { @RequestMapping("/boot/json")
public @ResponseBody
Object json() { Map<String, Object> map = new HashMap<>();
map.put("name", "张三");
map.put("age", "12");
return map; } @RequestMapping("/my/index")
public String index(Model model) {
model.addAttribute("say", "去你妈的");
return "index";
}
}
2、设置项目pom
<?xml version="1.0" encoding="UTF-8"?>
<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>com.springboot</groupId>
<artifactId>12-jsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging> <name>12-jsp</name>
<description>Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!--引入Spring Boot内嵌的Tomcat对JSP的解析包-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency> <!--servlet依赖的jar包start-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency> <!--jsp依赖jar包-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency> <!--jstl标签依赖的jar包-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins> <!--指定资源存放位置,IDE中需要特别加入的,必须加-->
<resources>
<!--XML文档存在的话,指定编译位置,应用于Mybatis使用-->
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<!--所有配置文件存放于此-->
<resource>
<directory>
src/main/resources
</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource> <!--所有静态和页面的资源,必须加的-->
<resource>
<directory>
src/main/webapp
</directory>
<targetPath>META-INF/webapp</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build> </project>
3、设置JSP访问
yaml
spring:
mvc:
view:
prefix: /
suffix: .jsp
4、JSP访问
http://www.cnblogs.com/liuyangfirst/p/8372291.html#3966869
5、打包
验证打包
6、复制war包,放入tomcat下
7、启动tomcat
8、访问
9、打jar包
10、打包
验证生成
11、进入文件所在文件夹
选中路径,输入cmd,回车 ----快捷进入文件夹命令位置
输入命令行
12、访问地址
注意:
jar包访问没有文件夹名称,如果需要项目名称,需要设置,如图