Springboot框架

Spring的框架
Springboot工程都是基于maven做依赖管理
在这里插入图片描述
Src-main-java:用于写后台代码的目录
SpringbootApplication:是工程的入口文件,运行的入口
Src-main-resources:
application.properties:用来配置底层框架需要的属性信息
pom.xml:maven工程用于管理依赖的核心配置文件
配置热部署:

<!-- 配置热部署 -->
	 	<dependency>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-devtools</artifactId>
	        <scope>runtime</scope>
	    </dependency>

热部署的作用是当更新代码时自动重新部署程序,避免频繁的重启
application.properties中增加配置属性:

内嵌tomcat的端口号
server.port=8090
上下文路径
server.servlet.context-path=/springboot
Debug级别的日志
logging.level.org.springframework=DEBUG

配置组件扫描管理所有层类对象

@ComponentScan(basePackages="com.springboot")
public class SpringbootApplication {
	public static void main(String[] args) {
	SpringApplication.run(SpringbootApplication.class, args);
	}
}

事务管理的方式:

@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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值