SpringBoot入门

SpringBoot入门

  1. 如何创建一个springboot框架web项目

  2. 使用springboot框架集成springmvc

    pon.xml

        <dependencies>
           <!--SpringBoot框架web项目的起步依赖-->
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
           </dependency>

    <!--SpringBoot框架测试起步依赖-->
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-test</artifactId>
               <scope>test</scope>
           </dependency>
       </dependencies>

       <build>
           <plugins>
    <!--    SpringBoot编译打包的插件        -->
               <plugin>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-maven-plugin</artifactId>
               </plugin>
           </plugins>
       </build>

    </project>
  3. 使用springboot框架的核心配置文件application.properties

    #设置内嵌Tomcat端口号
    server.port=8081

    #设置上下文根
    server.servlet.context-path=/springboot
  4. 使用springboot框架的核心配置文件application.yml或者application.yaml

  5. 如果springboot框架的核心配置文件application.properties和application.yaml同时存在会是什么情况?

优先使用application.properties

  1. 多环境下核心配置文件的使用,工作中开发的环境有哪些:开发环境、测试环境、准生产环境、生产环境

    application.properties主核心配置文件

    #springboot主核心配置文件
    #激活使用的配置文件
    spring.profiles.active=ready
  2. springboot在核心配置文件application.properties自定义配置一个一个获取@Value

    @Controller
    public class IndexController {

       @Value("${school.name}")
       private String schoolName;

       @Value("${websit}")
       private  String websit;

       @RequestMapping(value = "/say")
       public @ResponseBody String say(){
           return "Hello" + schoolName + ":" +  websit;
      }
    }
  3. springboot在核心配置文件将自定义配置映射到一个对象

    server.port=8080
    server.servlet.context-path=

    school.name=changge
    school.websit=http://www.changge.com

    abc.name=abc
    abc.websit=http://www.abc.com
  4. springboot集成jsp

  5.  

posted @ 2021-08-31 17:23  比你有趣  阅读(301)  评论(0)    收藏  举报