1.创建项目file–new-project–mavern,选择jdk版本,点击next
group id其实就是包名,后面也可以更改的,还有artifiact id就是工程名称,然后单击完成,就创建一个简单的maven工程。
2.配置pom.xml文件
引用必要的包
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
3.新建配置application.properties文件
###配置jsp文件的位置,默认位置为:
spring.mvc.view.prefix=/WEB-INF/pages/
###配置jsp文件的后缀
spring.mvc.view.suffix=.jsp
4.加载pom.xml文件,引入使用的包,必须的
5.创建jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
hello world!!!
name=${name } welcome!
</body>
</html>
6.创建testApplication
@SpringBootApplication
public class testApplication {
public static void main(String[] args) {
SpringApplication.run(testApplication.class);
}
}
7.创建TestController.
@Controller
public class TestController {
@RequestMapping(value="/login")
@ResponseBody
public ModelAndView login() {
System.out.println("good morning!");
ModelAndView mode = new ModelAndView();
mode.addObject("name", "test");
mode.setViewName("login");
return mode;
}
}
8.项目样式
testApplication不能直接放到java目录下,否则启动的时候会报错
9.右键启动testApplication即可
一个简单的web项目已经配置完成了