
| Bean转换类 | 释义 | 
|---|---|
| PO | 持久层对象,面向数据库,只存在基本数据类型和String,一般一个PO对应一张表 | 
| BO | 业务层对象,对PO进行业务处理,并将处理的结果进行封装 | 
| VO | 表现层对象,面向web界面,将BO进行包装为web页面需要渲染的数据结构 | 
使用Mybatis generator插件
在设置界面安装better-mybatis-generator插件
点开Database控制界面,找到已经保存的Database中的table,右击选择mabatis-generate会弹出下图的界面


spring:
  datasource:
    primary:
      jdbc-url: jdbc:mysql://127.0.0.1:3306/testdb?serverTimezone=GMT&useUnicode=true&characterEncoding=utf-8&useSSL=false
      username: root
      password: root
      driver-class-name: com.mysql.cj.jdbc.Driver
@Configuration
@MapperScan(baseBackage="com.jun.dao.db1",sqlSessionTemplateRef="primarySqlSessionTemplate")
public class primaryDataSourceConfig{
    
    
    @Bean(name = "primaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.primary")
    public DataSource primaryDataSource(){
        return DataSourceBuilder.create().build();
    }
    
    @Bean(name = "primarySqlSessionFactory")
    public SqlSessionFactory primarySqlSessionFactory(
    @Qualifier("primaryDataSource") DataSource datasource){
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(datasource);
        bean.setMappperLocation(new PathMatchingResourcePatternResolver()
                .getResources("classpath:mapper/db1/*.xml"));
        return bean.getObject();
    }
    
    @Bean(name = "primarySqlSessionTemplate")
    public SqlSessionTemplate primarySqlSessionTemplate(
    @("primarySqlSessionFactory") SqlSessionFactory sqlSessionFactory){
        return new SqlSessionTemplate(SqlSessionFactory);
    }
    
    
    @Bean(name = "secondDataSourceTransactionManager")
    public DataSourceTransactionManager secondDataSourceTransactionManager(
            @Qualifier("secondDataSource") DataSource dataSource){
        return new DataSourceTransactionManager(dataSource);
    }
}
| 更新丢失 | 脏读 | 虚读 | 幻读 | 实现方式 | |
|---|---|---|---|---|---|
| Read uncommited | √ | √ | √ | 排他写锁 | |
| Read commited | √ | √ | 瞬时共享读锁与排他锁 | ||
| Repeatable read | √ | 共享读锁与排他写锁 | |||
| Serializable | 
- Read uncommited A读取到B未提交的数据
- Read commited A读取到B修改前后的两次数据
- Repeatable read A读取到添加新数据前后数据的总数
<dependency>
    <groupId>cn.smallbun.screw</groupId>
    <artifactId>screw-core</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.28</version>
</dependency>
public class ScrewTest {
    @Test
    public void testScrewTest() {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/testdb2?serverTimezone=GMT&useUnicode=true&characterEncoding=utf-8&useSSL=false");
        hikariConfig.setUsername("root");
        hikariConfig.setPassword("root");
        hikariConfig.addDataSourceProperty("useInformationSchema","true");
        hikariConfig.setMaximumPoolSize(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);
        EngineConfig engineConfig = EngineConfig.builder()
                .fileOutputDir("e://")
                .openOutputDir(true)
                .fileType(EngineFileType.HTML)
                .produceType(EngineTemplateType.freemarker)
                .build();
        ArrayList<String> ignoreTableName = new ArrayList<>();
        ignoreTableName.add("test_table");
        ArrayList<String> ignorePrefix = new ArrayList<>();
        ignorePrefix.add("test_");
        ArrayList<String> ignoreSuffix = new ArrayList<>();
        ignorePrefix.add("_test");
        ProcessConfig processConfig = ProcessConfig.builder()
                .designatedTableName(new ArrayList<>())
                .designatedTablePrefix(new ArrayList<>())
                .designatedTableSuffix(new ArrayList<>())
                .ignoreTableName(ignoreTableName)
                .ignoreTablePrefix(ignorePrefix)
                .ignoreTableSuffix(ignoreSuffix).build();
        Configuration configuration = Configuration.builder()
                .version("1.0.0")
                .description("数据库文档设计")
                .dataSource(dataSource)
                .engineConfig(engineConfig)
                .produceConfig(processConfig)
                .build();
        new DocumentationExecute(configuration).execute();
    }
}
