1、建立项目
Java Controller
1 package com.springboot.jsp.controller; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.ui.Model; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.ResponseBody; 7 8 import java.util.HashMap; 9 import java.util.Map; 10 11 /****************************** 12 * @author : liuyang 13 * <p>ProjectName:12-jsp </p> 14 * @ClassName : MyController 15 * @date : 2018/7/27 0027 16 * @time : 21:48 17 * @createTime 2018-07-27 21:48 18 * @version : 2.0 19 * @description : 20 * 21 * 22 * 23 *******************************/ 24 25 @Controller 26 public class MyController { 27 28 29 @RequestMapping("/boot/json") 30 public @ResponseBody 31 Object json() { 32 33 Map<String, Object> map = new HashMap<>(); 34 map.put("name", "张三"); 35 map.put("age", "12"); 36 return map; 37 38 } 39 40 41 @RequestMapping("/my/index") 42 public String index(Model model) { 43 model.addAttribute("say", "去你妈的"); 44 return "index"; 45 } 46 }
2、设置项目pom
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 6 <groupId>com.springboot</groupId> 7 <artifactId>12-jsp</artifactId> 8 <version>0.0.1-SNAPSHOT</version> 9 <packaging>war</packaging> 10 11 <name>12-jsp</name> 12 <description>Spring Boot</description> 13 14 <parent> 15 <groupId>org.springframework.boot</groupId> 16 <artifactId>spring-boot-starter-parent</artifactId> 17 <version>2.0.3.RELEASE</version> 18 <relativePath/> <!-- lookup parent from repository --> 19 </parent> 20 21 <properties> 22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 24 <java.version>1.8</java.version> 25 </properties> 26 27 <dependencies> 28 <dependency> 29 <groupId>org.springframework.boot</groupId> 30 <artifactId>spring-boot-starter-web</artifactId> 31 </dependency> 32 33 <dependency> 34 <groupId>org.springframework.boot</groupId> 35 <artifactId>spring-boot-starter-test</artifactId> 36 <scope>test</scope> 37 </dependency> 38 39 <!--引入Spring Boot内嵌的Tomcat对JSP的解析包--> 40 <dependency> 41 <groupId>org.apache.tomcat.embed</groupId> 42 <artifactId>tomcat-embed-jasper</artifactId> 43 </dependency> 44 45 <!--servlet依赖的jar包start--> 46 <dependency> 47 <groupId>javax.servlet</groupId> 48 <artifactId>javax.servlet-api</artifactId> 49 </dependency> 50 51 <!--jsp依赖jar包--> 52 <dependency> 53 <groupId>javax.servlet.jsp</groupId> 54 <artifactId>javax.servlet.jsp-api</artifactId> 55 <version>2.3.1</version> 56 </dependency> 57 58 <!--jstl标签依赖的jar包--> 59 <dependency> 60 <groupId>javax.servlet</groupId> 61 <artifactId>jstl</artifactId> 62 </dependency> 63 64 </dependencies> 65 66 <build> 67 <plugins> 68 <plugin> 69 <groupId>org.springframework.boot</groupId> 70 <artifactId>spring-boot-maven-plugin</artifactId> 71 </plugin> 72 </plugins> 73 74 75 <!--指定资源存放位置,IDE中需要特别加入的,必须加--> 76 <resources> 77 <!--XML文档存在的话,指定编译位置,应用于Mybatis使用--> 78 <resource> 79 <directory> 80 src/main/java 81 </directory> 82 <includes> 83 <include>**/*.xml</include> 84 </includes> 85 </resource> 86 <!--所有配置文件存放于此--> 87 <resource> 88 <directory> 89 src/main/resources 90 </directory> 91 <includes> 92 <include>**/*.*</include> 93 </includes> 94 </resource> 95 96 <!--所有静态和页面的资源,必须加的--> 97 <resource> 98 <directory> 99 src/main/webapp 100 </directory> 101 <targetPath>META-INF/webapp</targetPath> 102 <includes> 103 <include>**/*.*</include> 104 </includes> 105 </resource> 106 </resources> 107 </build> 108 109 110 </project>
3、设置JSP访问
yaml
1 spring: 2 mvc: 3 view: 4 prefix: / 5 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包访问没有文件夹名称,如果需要项目名称,需要设置,如图