springboot

介绍

springboot是spring项目中的一个子工程,前者的实现是基于spring的。
springboot的特点:“开箱即用”和“约定大于配置”

使用

pom配置
1)添加父工程依赖

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.4.RELEASE</version>
</parent>

2)添加启动器
比如web启动器

<dependencies>
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
</dependencies>

3)插件:用于将项目打成jar包

<build>
      <plugins>
            <plugin>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
      </plugins>
</build>

启动类

@SpringBootApplication
public class Application {
      public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
      }
}

常用注解

  • @Configuration:声明一个类作为配置类,代替xml文件
  • @Bean:声明在方法上,将方法的返回值加入Bean容器,代替标签
  • @value:属性注入
  • @PropertySource:指定外部属性文件

springboot整合

1、整合springmvc
1)修改端口

server.port=8888

2)访问静态资源
默认的静态资源路径为:

  • classpath:/META-INF/resources/
  • classpath:/resources/
  • classpath:/static/
  • classpath:/public
    3)拦截器

2、整合jdbc和事务
使用springboot提供的启动器即可
3、整合连接池
4、整合mybatis
5、整合通用mapper

posted @ 2023-04-19 09:02  挖洞404  阅读(6)  评论(0编辑  收藏  举报