1. Create a new MAVEN Web project;
2, add the corresponding dependency package in the Pom.xml file;
3, a new Hellocontroller request control class;
4, write index.jsp page;
5. Write Startup class App.java
6. Launch the application for code testing
Pom.xml Configuration
<!--Inherit defaults from Spring Boot--<parent> <groupid>org.springframework.boot</gr Oupid> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.release</v ersion> <!--<version>2.0.1.RELEASE</version>--> </parent> <properties> < Project.build.sourceencoding>utf-8</project.build.sourceencoding> <java.version>1.8</ Java.version> </properties> <dependencies> <!--Web support: 1, Web MVC; 2, restful; 3, Jackjson support; 4. AOP ...-<dependency> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-web</artifactid> </dependency> <!--servlet dependency. --><!--dependency><groupid>javax.servlet</groupid><artifactid>javax.servlet-api< /artifactid><scope>provided</scope></dependency--> <!-- JSTL (JSP standard tag LIBRARY,JSP standards Tag library) is an ever-improving open source JSP tag library that is maintained by Apache's Jakarta team. --><dependency><groupid>javax.servlet</groupid><artifactid>jstl</artifactid> </dependency> <!--Tomcat support .--> <!--Spring Boot app launcher There are also some replacement technology initiators, specifically as follows:--><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><scope> Provided</scope></dependency> <!--Fastjson-<dependency> <groupid>com.alibaba& lt;/groupid> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependen cy> <!--spring boot devtools Hot deployment-<dependency> <groupid>org.springframework.boot& lt;/groupid> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <s cope>true</scope> </dependency> </dependencies> <build> <finalname>boot2& Lt;/finalname> <plugins> <!--spring boot Devtools Plugin---<plugin> <groupid>org .springframework.boot</groupid> <artifactId>spring-boot-maven-plugin</artifactId> < Configuration> <!--fork: If there is no such configuration, then Devtools will not work, that is, the app will not restart--<fork>true</fork> </ configuration> </plugin> </plugins> </build>
App.java
Package Boot2.muyang.app;import Org.apache.log4j.logger;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.boot.autoconfigure.web.httpmessageconverters;import Org.springframework.context.annotation.bean;import Org.springframework.http.converter.HttpMessageConverter; Import Com.alibaba.fastjson.serializer.serializerfeature;import Com.alibaba.fastjson.support.config.fastjsonconfig;import Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; @SpringBootApplicationpublic class App {private static Logger Logger = Logger.getlogger (app.class); @Beanpublic httpmessageconverters fastjsonhttpmessageconverters () {Fastjsonhttpmessageconverter Fastconverter = new Fastjsonhttpmessageconverter (); Fastjsonconfig fastjsonconfig = new Fastjsonconfig (); Fastjsonconfig.setserializerfeatures ( Serializerfeature.prettyformat); Fastconverter.setfastjsonconfig (Fastjsonconfig); Httpmessageconverter<?> Converter = Fastconverter;return New Httpmessageconverters (converter);} public static void Main (string[] args) {logger.info ("----: Run Start"); Springapplication.run (App.class, args); Logger.info ("----: runing");}}
Application.properties cannot have spaces
spring.mvc.view.prefix=/web-inf/jsp/spring.mvc.view.suffix=.jsp
Hellocontroller.java
Package Boot2.muyang.app.controller;import Java.util.map;import Org.springframework.stereotype.controller;import org.springframework.web.bind.annotation.RequestMapping; @Controller @requestmapping ("/hello") public class Hellocontroller {@RequestMapping ("/index") public String Index (map<string,object> Map) {map.put ("name", "Andy") ; return "index";}}
Spring boot: Create a simple Web (MAVEN Web project)