1、首先,安装环境
eclipse中, Help->Eclipse Marketplace,安装Spring Tools
2、安装好后,新建工程,选择Spring Starter Project
3、填写项目信息 Packaging 选择 war
4、选择依赖的starter,(此示例中选择Aspects、Actuator、Web)
5、修改 application.properties。此处修改了端口,和查找视图的规则
6、在src/main/webapp/WEB-INF/jsp建立一个index.jsp的文件
内容为
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> test <b>Test</b> </body> </html>
7、新建一个TestController.java
内容为
package com.example.bootdemo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class TestController { @RequestMapping("/index") public String index() { return "index"; } }
8、在pom.xml中添加jsp的依赖
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>
9、运行为 spring boot app
10、在浏览器中输入 http://127.0.0.1:8090/index 并查看