SpringBoot之数据访问和事务-专题三

四、数据访问

4.1、springboot整合使用JdbcTemplate

4.1.1 pom文件引入
  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>
  6. <dependencies>
  7. <!-- jdbcTemplate 依赖 -->
  8. <dependency>
  9. <groupId>org.springframework.boot</groupId>
  10. <artifactId>spring-boot-starter-jdbc</artifactId>
  11. </dependency>
  12. <!-- mysql 依赖 -->
  13. <dependency>
  14. <groupId>mysql</groupId>
  15. <artifactId>mysql-connector-java</artifactId>
  16. </dependency>
  17. <!-- 测试 -->
  18. <dependency>
  19. <groupId>org.springframework.boot</groupId>
  20. <artifactId>spring-boot-starter-test</artifactId>
  21. <scope>test</scope>
  22. </dependency>
  23. <!-- springboot-web组件 -->
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-web</artifactId>
  27. </dependency>
  28. </dependencies>

4.1.2 application.properties新增配置

  1. spring.datasource.url=jdbc:mysql://localhost:3306/test
  2. spring.datasource.username=root
  3. spring.datasource.password=root
  4. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
4.1.3 UserService类
  1. @Service
  2. public class UserServiceImpl implements UserService {
  3. @Autowired
  4. private JdbcTemplate jdbcTemplate;
  5. public void createUser(String name, Integer age) {
  6. jdbcTemplate.update("insert into users values(null,?,?);", name, age);
  7. }
  8. }

4.1.4 App类

  1. @SpringBootApplication
  2. public class App {
  3. public static void main(String[] args) {
  4. SpringApplication.run(App.class, args);
  5. }
  6. }

注意: spring-boot-starter-parent要在1.5以上

4.2、springboot整合使用mybatis

4.2.1、pom文件引入
  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter</artifactId>
  10. </dependency>
  11. <!-- 测试 -->
  12. <dependency>
  13. <groupId>org.springframework.boot</groupId>
  14. <artifactId>spring-boot-starter-test</artifactId>
  15. <scope>test</scope>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.mybatis.spring.boot</groupId>
  19. <artifactId>mybatis-spring-boot-starter</artifactId>
  20. <version>1.1.1</version>
  21. </dependency>
  22. <!-- mysql 依赖 -->
  23. <dependency>
  24. <groupId>mysql</groupId>
  25. <artifactId>mysql-connector-java</artifactId>
  26. </dependency>
  27. <!-- springboot-web组件 -->
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-web</artifactId>
  31. </dependency>
  32. </dependencies>

4.2.2、配置文件引入

  1. spring.datasource.url=jdbc:mysql://localhost:3306/test
  2. spring.datasource.username=root
  3. spring.datasource.password=root
  4. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
4.2.3、Mapper代码
  1. public interface UserMapper {
  2. @Select("SELECT * FROM USERS WHERE NAME = #{name}")
  3. User findByName(@Param("name") String name);
  4. @Insert("INSERT INTO USERS(NAME, AGE) VALUES(#{name}, #{age})")
  5. int insert(@Param("name") String name, @Param("age") Integer age);
  6. }
4.2.4、启动方式
  1. @MapperScan("com.mapper")
  2. @SpringBootApplication
  3. public class MybatisApp {
  4. public static void main(String[] args) {
  5. SpringApplication.run(MybatisApp.class, args);
  6. }
  7. }
4.2.5、Mybatis整合分页插件

pageHelper

PageHelper 是一款好用的开源免费的 Mybatis 第三方物理分页插件

物理分页

支持常见的 12 种数据库。Oracle,MySql,MariaDB,SQLite,DB2,PostgreSQL,SqlServer 等

支持多种分页方式

支持常见的 RowBounds(PageRowBounds),PageHelper.startPage 方法调用,Mapper 接口参数调用

Maven依赖

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.projectlombok</groupId>
  9. <artifactId>lombok</artifactId>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter</artifactId>
  14. </dependency>
  15. <!-- 测试 -->
  16. <dependency>
  17. <groupId>org.springframework.boot</groupId>
  18. <artifactId>spring-boot-starter-test</artifactId>
  19. <scope>test</scope>
  20. </dependency>
  21. <dependency>
  22. <groupId>org.mybatis.spring.boot</groupId>
  23. <artifactId>mybatis-spring-boot-starter</artifactId>
  24. <version>1.1.1</version>
  25. </dependency>
  26. <!-- mysql 依赖 -->
  27. <dependency>
  28. <groupId>mysql</groupId>
  29. <artifactId>mysql-connector-java</artifactId>
  30. </dependency>
  31. <!-- springboot-web组件 -->
  32. <dependency>
  33. <groupId>org.springframework.boot</groupId>
  34. <artifactId>spring-boot-starter-web</artifactId>
  35. </dependency>
  36. <!-- springboot 整合 pagehelper -->
  37. <dependency>
  38. <groupId>com.github.pagehelper</groupId>
  39. <artifactId>pagehelper-spring-boot-starter</artifactId>
  40. <version>1.2.5</version>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.apache.commons</groupId>
  44. <artifactId>commons-lang3</artifactId>
  45. <version>3.7</version>
  46. </dependency>
  47. </dependencies>

配置文件

  1. spring.datasource.url=jdbc:mysql://localhost:3306/test
  2. spring.datasource.username=root
  3. spring.datasource.password=root
  4. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  5. logging.level.com.example.demo.dao=DEBUG
  6. pagehelper.helperDialect=mysql
  7. pagehelper.reasonable=true
  8. pagehelper.supportMethodsArguments=true
  9. pagehelper.params=count=countSql
  10. pagehelper.page-size-zero=true

Entity层

  1. @Data
  2. public class User {
  3. private Integer id;
  4. private String name;
  5. private Integer age;
  6. }

Mapper层

  1. public interface UserMapper {
  2. @Select("SELECT * FROM USERS ")
  3. List<User> findUserList();
  4. }

Service层

  1. @Service
  2. public class UserService {
  3. @Autowired
  4. private UserMapper userMapper;
  5. public PageInfo<User> findUserList(int page, int size) {
  6. // 开启分页插件,放在查询语句上面
  7. PageHelper.startPage(page, size);
  8. List<User> listUser = userMapper.findUserList();
  9. // 封装分页之后的数据
  10. PageInfo<User> pageInfoUser = new PageInfo<User>(listUser);
  11. return pageInfoUser;
  12. }
  13. }

Controller层

  1. @RestController
  2. public class IndexController {
  3. @Autowired
  4. private UserService userService;
  5. @RequestMapping("/findUser")
  6. public PageInfo<User> findUserList(int page, int size) {
  7. return userService.findUserList(page, size);
  8. }
  9. }

启动项目

  1. @MapperScan("com.mapper")
  2. @SpringBootApplication
  3. public class PageHelper {
  4. public static void main(String[] args) {
  5. SpringApplication.run(PageHelper.class, args);
  6. }
  7. }

4.3、springboot整合使用springjpa

4.3.1 pom文件引入依赖
  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.0.0.RELEASE</version>
  5. </parent>
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.springframework.boot</groupId>
  9. <artifactId>spring-boot-starter-data-jpa</artifactId>
  10. </dependency>
  11. <dependency>
  12. <groupId>mysql</groupId>
  13. <artifactId>mysql-connector-java</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-web</artifactId>
  18. </dependency>
  19. </dependencies>
4.3.2 创建User实体类
  1. @Entity(name = "users")
  2. public class UserEntity {
  3. @Id
  4. @GeneratedValue(strategy = GenerationType.IDENTITY)
  5. private Integer id;
  6. @Column(name = "name")
  7. private String name;
  8. @Column(name = "age")
  9. private Integer age;
  10. }

4.3.3 创建UserDao

  1. public interface UserDao extends JpaRepository<User, Integer> {
  2. }

4.3.3 创建IndexController

  1. @RestController
  2. public class IndexController {
  3. @Autowired
  4. private UserDao userDao;
  5. @RequestMapping("/jpaFindUser")
  6. public Object jpaIndex(User user) {
  7. Optional<User> userOptional = userDao.findById(user.getId());
  8. User reusltUser = userOptional.get();
  9. return reusltUser == null ? "没有查询到数据" : reusltUser;
  10. }
  11. }

4.3.4 启动项目

  1. @SpringBootApplication
  2. public class JpaApp {
  3. public static void main(String[] args) {
  4. SpringApplication.run(JpaApp.class, args);
  5. }
  6. }

4.4、springboot整合多数据源

思考下,你们在项目中有使用到多数据源吗?

原理使用根据包名,加载不同的数据源

4.4.1配置文件中新增两个数据源
  1. ###datasource1
  2. spring.datasource.test1.driver-class-name = com.mysql.jdbc.Driver
  3. spring.datasource.test1.jdbc-url = jdbc:mysql://localhost:3306/test01?useUnicode=true&characterEncoding=utf-8
  4. spring.datasource.test1.username = root
  5. spring.datasource.test1.password = root
  6. ###datasource2
  7. spring.datasource.test2.driver-class-name = com.mysql.jdbc.Driver
  8. spring.datasource.test2.jdbc-url = jdbc:mysql://localhost:3306/test02?useUnicode=true&characterEncoding=utf-8
  9. spring.datasource.test2.username = root
  10. spring.datasource.test2.password = root
4.4.2配置文件中新增两个数据源
  1. //DataSource01
  2. @Configuration // 注册到springboot容器中
  3. @MapperScan(basePackages = "com.example.test01", sqlSessionFactoryRef = "test1SqlSessionFactory")
  4. public class DataSource1Config {
  5. @Bean(name = "test1DataSource")
  6. @ConfigurationProperties(prefix = "spring.datasource.test1")
  7. @Primary
  8. public DataSource testDataSource() {
  9. return DataSourceBuilder.create().build();
  10. }
  11. @Bean(name = "test1SqlSessionFactory")
  12. @Primary
  13. public SqlSessionFactory testSqlSessionFactory(@Qualifier("test1DataSource") DataSource dataSource)
  14. throws Exception {
  15. SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  16. bean.setDataSource(dataSource);
  17. // bean.setMapperLocations(
  18. // new
  19. // PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml"));
  20. return bean.getObject();
  21. }
  22. @Bean(name = "test1TransactionManager")
  23. @Primary
  24. public DataSourceTransactionManager testTransactionManager(@Qualifier("test1DataSource") DataSource dataSource) {
  25. return new DataSourceTransactionManager(dataSource);
  26. }
  27. @Bean(name = "test1SqlSessionTemplate")
  28. @Primary
  29. public SqlSessionTemplate testSqlSessionTemplate(
  30. @Qualifier("test1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
  31. return new SqlSessionTemplate(sqlSessionFactory);
  32. }
  33. }

DataSource02

  1. //DataSource2
  2. @Configuration // 注册到springboot容器中
  3. @MapperScan(basePackages = "com.example.test02", sqlSessionFactoryRef = "test2SqlSessionFactory")
  4. public class DataSource2Config {
  5. @Bean(name = "test2DataSource")
  6. @ConfigurationProperties(prefix = "spring.datasource.test2")
  7. public DataSource testDataSource() {
  8. return DataSourceBuilder.create().build();
  9. }
  10. @Bean(name = "test2SqlSessionFactory")
  11. public SqlSessionFactory testSqlSessionFactory(@Qualifier("test2DataSource") DataSource dataSource)
  12. throws Exception {
  13. SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  14. bean.setDataSource(dataSource);
  15. // bean.setMapperLocations(
  16. // new
  17. // PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test2/*.xml"));
  18. return bean.getObject();
  19. }
  20. @Bean(name = "test2TransactionManager")
  21. public DataSourceTransactionManager testTransactionManager(@Qualifier("test2DataSource") DataSource dataSource) {
  22. return new DataSourceTransactionManager(dataSource);
  23. }
  24. @Bean(name = "test2SqlSessionTemplate")
  25. public SqlSessionTemplate testSqlSessionTemplate(
  26. @Qualifier("test2SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
  27. return new SqlSessionTemplate(sqlSessionFactory);
  28. }
  29. }
4.4.2创建分包Mapper
  1. public interface User1Mapper {
  2. @Insert("insert into users values(null,#{name},#{age});")
  3. public int addUser(@Param("name") String name, @Param("age") Integer age);
  4. }
4.4.3 多数据源事务注意事项

在多数据源的情况下,使用@Transactional注解时,应该指定事务管理者

@Transactional(transactionManager = “test2TransactionManager”)

4.4.5启动项目

  1. @SpringBootApplication
  2. @MapperScan(basePackages = { "com.example.mapper" })
  3. public class App {
  4. public static void main(String[] args) {
  5. SpringApplication.run(App.class, args);
  6. }
  7. }

No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: test1DataSource,test2DataSource

加上@Primary即可。

There was an unexpected error (type=Internal Server Error, status=500).

No qualifying bean of type ‘org.springframework.transaction.PlatformTransactionManager’ available: expected single matching bean but found 2: test1TransactionManager,test2TransactionManager

指定事务管理器

Springboot1.5的时候 没有默认指向数据源 会报错

Springboot2.0的时候 不报错

五、事物管理

5.1.1SpringBoot整合事物管理

Springboot默认集成事物,只主要在方法上加上@Transactional即可

5.1.2SpringBoot分布式事物管理

使用springboot+jta+atomikos 分布式事物管理

Atomikos 是一个为Java平台提供增值服务的并且开源类事务管理器。

5.1.2.1 新增jta-atomikos依赖

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-jta-atomikos</artifactId>
  4. </dependency>

5.1.2.2新增配置文件信息

  1. # Mysql 1
  2. mysql.datasource.test1.url = jdbc:mysql://localhost:3306/test01?useUnicode=true&characterEncoding=utf-8
  3. mysql.datasource.test1.username = root
  4. mysql.datasource.test1.password = root
  5. mysql.datasource.test1.minPoolSize = 3
  6. mysql.datasource.test1.maxPoolSize = 25
  7. mysql.datasource.test1.maxLifetime = 20000
  8. mysql.datasource.test1.borrowConnectionTimeout = 30
  9. mysql.datasource.test1.loginTimeout = 30
  10. mysql.datasource.test1.maintenanceInterval = 60
  11. mysql.datasource.test1.maxIdleTime = 60
  12. # Mysql 2
  13. mysql.datasource.test2.url =jdbc:mysql://localhost:3306/test02?useUnicode=true&characterEncoding=utf-8
  14. mysql.datasource.test2.username =root
  15. mysql.datasource.test2.password =root
  16. mysql.datasource.test2.minPoolSize = 3
  17. mysql.datasource.test2.maxPoolSize = 25
  18. mysql.datasource.test2.maxLifetime = 20000
  19. mysql.datasource.test2.borrowConnectionTimeout = 30
  20. mysql.datasource.test2.loginTimeout = 30
  21. mysql.datasource.test2.maintenanceInterval = 60
  22. mysql.datasource.test2.maxIdleTime = 60

5.1.2.3 读取配置文件信息

  1. @Data
  2. @ConfigurationProperties(prefix = "mysql.datasource.test1")
  3. public class DBConfig1 {
  4. private String url;
  5. private String username;
  6. private String password;
  7. private int minPoolSize;
  8. private int maxPoolSize;
  9. private int maxLifetime;
  10. private int borrowConnectionTimeout;
  11. private int loginTimeout;
  12. private int maintenanceInterval;
  13. private int maxIdleTime;
  14. private String testQuery;
  15. }
  1. @Data
  2. @ConfigurationProperties(prefix = "mysql.datasource.test2")
  3. public class DBConfig2 {
  4. private String url;
  5. private String username;
  6. private String password;
  7. private int minPoolSize;
  8. private int maxPoolSize;
  9. private int maxLifetime;
  10. private int borrowConnectionTimeout;
  11. private int loginTimeout;
  12. private int maintenanceInterval;
  13. private int maxIdleTime;
  14. private String testQuery;
  15. }

5.1.2.4 创建多数据源

  1. @Configuration
  2. // basePackages 最好分开配置 如果放在同一个文件夹可能会报错
  3. @MapperScan(basePackages = "com.example.test01", sqlSessionTemplateRef = "testSqlSessionTemplate")
  4. public class MyBatisConfig1 {
  5. // 配置数据源
  6. @Primary
  7. @Bean(name = "testDataSource")
  8. public DataSource testDataSource(DBConfig1 testConfig) throws SQLException {
  9. MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
  10. mysqlXaDataSource.setUrl(testConfig.getUrl());
  11. mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
  12. mysqlXaDataSource.setPassword(testConfig.getPassword());
  13. mysqlXaDataSource.setUser(testConfig.getUsername());
  14. mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
  15. AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
  16. xaDataSource.setXaDataSource(mysqlXaDataSource);
  17. xaDataSource.setUniqueResourceName("testDataSource");
  18. xaDataSource.setMinPoolSize(testConfig.getMinPoolSize());
  19. xaDataSource.setMaxPoolSize(testConfig.getMaxPoolSize());
  20. xaDataSource.setMaxLifetime(testConfig.getMaxLifetime());
  21. xaDataSource.setBorrowConnectionTimeout(testConfig.getBorrowConnectionTimeout());
  22. xaDataSource.setLoginTimeout(testConfig.getLoginTimeout());
  23. xaDataSource.setMaintenanceInterval(testConfig.getMaintenanceInterval());
  24. xaDataSource.setMaxIdleTime(testConfig.getMaxIdleTime());
  25. xaDataSource.setTestQuery(testConfig.getTestQuery());
  26. return xaDataSource;
  27. }
  28. @Primary
  29. @Bean(name = "testSqlSessionFactory")
  30. public SqlSessionFactory testSqlSessionFactory(@Qualifier("testDataSource") DataSource dataSource)
  31. throws Exception {
  32. SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  33. bean.setDataSource(dataSource);
  34. return bean.getObject();
  35. }
  36. @Primary
  37. @Bean(name = "testSqlSessionTemplate")
  38. public SqlSessionTemplate testSqlSessionTemplate(
  39. @Qualifier("testSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
  40. return new SqlSessionTemplate(sqlSessionFactory);
  41. }
  42. }
  1. @Configuration
  2. @MapperScan(basePackages = "com.example.test02", sqlSessionTemplateRef = "test2SqlSessionTemplate")
  3. public class MyBatisConfig2 {
  4. // 配置数据源
  5. @Bean(name = "test2DataSource")
  6. public DataSource testDataSource(DBConfig2 testConfig) throws SQLException {
  7. MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
  8. mysqlXaDataSource.setUrl(testConfig.getUrl());
  9. mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
  10. mysqlXaDataSource.setPassword(testConfig.getPassword());
  11. mysqlXaDataSource.setUser(testConfig.getUsername());
  12. mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
  13. AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
  14. xaDataSource.setXaDataSource(mysqlXaDataSource);
  15. xaDataSource.setUniqueResourceName("test2DataSource");
  16. xaDataSource.setMinPoolSize(testConfig.getMinPoolSize());
  17. xaDataSource.setMaxPoolSize(testConfig.getMaxPoolSize());
  18. xaDataSource.setMaxLifetime(testConfig.getMaxLifetime());
  19. xaDataSource.setBorrowConnectionTimeout(testConfig.getBorrowConnectionTimeout());
  20. xaDataSource.setLoginTimeout(testConfig.getLoginTimeout());
  21. xaDataSource.setMaintenanceInterval(testConfig.getMaintenanceInterval());
  22. xaDataSource.setMaxIdleTime(testConfig.getMaxIdleTime());
  23. xaDataSource.setTestQuery(testConfig.getTestQuery());
  24. return xaDataSource;
  25. }
  26. @Bean(name = "test2SqlSessionFactory")
  27. public SqlSessionFactory testSqlSessionFactory(@Qualifier("test2DataSource") DataSource dataSource)
  28. throws Exception {
  29. SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  30. bean.setDataSource(dataSource);
  31. return bean.getObject();
  32. }
  33. @Bean(name = "test2SqlSessionTemplate")
  34. public SqlSessionTemplate testSqlSessionTemplate(
  35. @Qualifier("test2SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
  36. return new SqlSessionTemplate(sqlSessionFactory);
  37. }
  38. }

5.1.2.4 启动加载配置

  1. @EnableConfigurationProperties(value = { DBConfig1.class, DBConfig2.class })

分布式事务,可以预览我的这个链接分布式事务

SpringBoot之数据访问和事务-专题三的更多相关文章

  1. Solon Web 开发,五、数据访问、事务与缓存应用

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  2. Spring数据访问和事务

    1.模型 2.解耦 3.实现 3.1 核心接口 3.2 代码分析 3.2.1 事务管理 3.2.2 数据访问 4.使用 4.1 编程模式 4.2 配置模式 4.2.1 声明式配置方式 4.2.2 注解 ...

  3. 六、SpringBoot与数据访问

    六.SpringBoot与数据访问 1.JDBC spring: datasource: username: root password: 123456 url: jdbc:mysql://192.1 ...

  4. SpringBoot(九) -- SpringBoot与数据访问

    一.简介 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置.引入各种xxxTemplate,xx ...

  5. 10分钟进阶SpringBoot - 05. 数据访问之JDBC(附加源码分析+代码下载)

    10分钟进阶SpringBoot - 05. 数据访问之JDBC 代码下载:https://github.com/Jackson0714/study-spring-boot.git 一.JDBC是什么 ...

  6. Spring ( 五 )Spring之数据访问与事务管理

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.Spring之数据访问 1.Spring数据访问工程环境搭建 ​ jdbc.properties配置 ...

  7. java框架之SpringBoot(9)-数据访问及整合MyBatis

    简介 对于数据访问层,无论是 SQL 还是 NOSQL,SpringBoot 默认采用整合 SpringData 的方式进行统一处理,添加了大量的自动配置,引入了各种 Template.Reposit ...

  8. Spring 4 官方文档学习(九)数据访问之事务管理

    说明:未整理版,未完待续,请绕行 本部分的重点是数据访问以及数据访问层与业务层之间的交互. 1.Spring框架的事务管理 介绍 http://docs.spring.io/spring/docs/c ...

  9. SpringBoot 之数据访问

    1. Spring Boot 与 JDBC 默认使用 org.apache.tomcat.jdbc.pool.DataSource 数据源; // application.yml spring: da ...

随机推荐

  1. js加密(六)QB.com

    1. url: https://notice.qb.com/detail?noticeId=256 2. target: 3. 分析: 3.1 打开网址,刷新页面,看看都发送了哪些请求. 看到了发送了 ...

  2. 放眼全球,关注游戏质量变化:腾讯WeTest发布《2019中国移动游戏质量白皮书》

    2019是中国游戏市场,尤其是手游市场称得上是跌宕起伏的一年,同时也是各大厂商推陈出新突破过去的一年.面对竞争激烈的市场,手游厂商们不仅着眼于游戏质量的提升,更是将一众优秀的国产游戏带入到了海外市场, ...

  3. 利用单臂路由实现VLAN间的路由

    实验4:利用单臂路由实现VLAN间的路由. 实验原理:  实验内容: 本实验模拟公司网络场景,路由器R1是公司的出口网关,员工PC通过接入层交换机(如S2和S3)接入公司网络,接入层交换机又通过汇聚交 ...

  4. 让 typora和word一样好用

    让 typora和word一样好用  :https://github.com/itcastWsy/typora_copy_images typora是一款支持实时预览的markdown编辑器,作者在使 ...

  5. react组件之间传值方式

    1.父向子(通过props传值) 2.父向更深层的子(通过context传值) 3.子向父(通过回调函数传值:在父组件中创建一个函数来接收子组件传过来的参数值,通过父组件将这个函数做为子组件的属性传递 ...

  6. php中截取中文不乱吗

    php截取中文的使用是随处可见的,譬如,博客首页显示简介,可能会用到,或一些相册简介会用到,以前不知道,还傻傻的自己去写函数用来做“智能截取”,效果还不十分好,幸运的是,今天因为一位同学做项目,让我一 ...

  7. python opencv:使用鼠标当做画笔

    鼠标事件 import cv2 events=[i for i in dir(cv2) if 'EVENT'in i] print events 双击画圆圈 import cv2 import num ...

  8. 【代码总结】PHP面向对象之类与对象

    一.类和对象的关系 类的实体化结果是对象,而对象的抽象就是类.在开发过程中,我们通常都是先抽象(幻想)出一个类,再用该类去创建对象(实现幻想的内容).在程序中,直接使用的是我们(实现幻想)的对象,而不 ...

  9. 影响IPSec的网络问题

    影响IPSec VPN的网络问题:①.动态地址问题:两个 站点之间IPSec VPN的条件是站点之间有固定的IP地址,假如说分支站点采用ADSL上网链路,那么其IP地址是动态的,那么就在VPN时出现问 ...

  10. UCS内存问题排查

    UCS使用双列直插式内存模块(Dual In-line Memory Module (DIMM) )作为RAM模块. 根据文档介绍,主要有如下部分:1.Memory placement <内存放 ...