快速入门Spring Boot

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>

到此就结束了。

欢迎转载,但请标明出处!!!

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值