版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39693164/article/details/81987593
IDEA版本:
首先:pom.xml ->SpringBoot依赖
<!--SpringBoot父级依赖-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--SpringBoot开发WEB的起步依赖-->
<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>
</dependencies>
application.properties文件小零件:
server.port=8080//设置端口
server.servlet.context-path=/02-springboot//设置路径
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
开发:application-dev.properties
测试:application-test.properties
上线:application-online.properties
在application.properties文件中写spring.profiles.active=dev/test/online的时候可以自动加载对应的.properties文件
springmvc注解:
@Controller -->即为处理http请求
@RestController-->是spring4后新增的注解;@RestController=@Controller+@ResponseBody
其次还有@GetMapping、@PostMapping、@PutMapping、@DeleteMapping同上都是组合注解。
其次:SpringBoot使用JSP
首先要在pom.xml中加入支持JSP页面的依赖
<!--引入SpringBoot内嵌的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包start-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
</dependency>
<!--jstl依赖的jar包start-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
其次在Eclipse里不需要加下面的这段依赖,但在idea里是需要加这段代码依赖的,运行后idea会把jsp页面编译到rarget下的META-INF/resources下,不然找不到jsp页面。
<--在<build>里加,和<plugins>标签同级别-->
<resources>
<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/resources</targetPath>
<includes>
<include>**/*.**</include>
</includes>
</resource>
</resources>
到此就结束了。
欢迎转载,但请标明出处!!!