属于Spring框架:简化Spring配置文件的编写
SpringBoot工程基于maven做依赖管理
- Src-main-java:用于写后台代码的目录
- SpringbootApplication:是工程的入口文件,运行的入口
- Src-main-resources:
- application.properties:用来配置底层框架需要的属性信息
- pom.xml:maven工程用于管理依赖的核心配置文件
1. 配置热部署:
<!-- 配置热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
热部署的作用是当更新代码时自动重新部署程序,避免频繁的重启
2. application.properties中增加配置属性:
内嵌tomcat的端口号
server.port=8090
上下文路径
server.servlet.context-path=/springboot
Debug级别的日志
logging.level.org.springframework=DEBUG
3. 配置组件扫描管理所有层类对象
@ComponentScan(basePackages="com.springboot")
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
4. 事务管理的方式:
@SpringBootApplication
@ComponentScan(basePackages="com.springboot")
@EnableTransactionManagement
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
Service层类,如果某个方法需要事务处理,则方法上方加注解:@Transactional
Springboot整合mybatis:
<!-- mybatis新增 begin-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--mybatis end -->
#mybatis add
mybatis.type-aliases-package=com.springboot.model.bean
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password = 123456
mybatis.mapper-locations=classpath:mybatis/*.xml