15 changed files with 162 additions and 109 deletions
@ -1,28 +0,0 @@ |
|||
package com.win.bank.config; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.session.SqlSessionFactory; |
|||
import org.mybatis.spring.SqlSessionFactoryBean; |
|||
import org.mybatis.spring.SqlSessionTemplate; |
|||
import org.mybatis.spring.annotation.MapperScan; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
@Configuration |
|||
@MapperScan(value = "com.win.bank", annotationClass = Mapper.class) // Mapper 懒加载,目前仅用于单元测试
|
|||
public class MyBatisConfig { |
|||
|
|||
@Bean |
|||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { |
|||
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); |
|||
sqlSessionFactoryBean.setDataSource(dataSource); |
|||
return sqlSessionFactoryBean.getObject(); |
|||
} |
|||
|
|||
@Bean |
|||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { |
|||
return new SqlSessionTemplate(sqlSessionFactory); |
|||
} |
|||
} |
@ -0,0 +1,65 @@ |
|||
package com.win.bank.config; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.DbType; |
|||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
|||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; |
|||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; |
|||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
|||
import org.apache.ibatis.session.SqlSessionFactory; |
|||
import org.mybatis.spring.SqlSessionFactoryBean; |
|||
import org.mybatis.spring.SqlSessionTemplate; |
|||
import org.mybatis.spring.annotation.MapperScan; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
/** |
|||
* Mybatis Plus 配置 |
|||
* |
|||
* @author win |
|||
*/ |
|||
@Configuration |
|||
@EnableTransactionManagement(proxyTargetClass = true) |
|||
public class MybatisPlusConfig { |
|||
|
|||
@Bean |
|||
public MybatisPlusInterceptor mybatisPlusInterceptor() { |
|||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
|||
// 乐观锁插件
|
|||
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); |
|||
// 分页插件
|
|||
interceptor.addInnerInterceptor(paginationInnerInterceptor()); |
|||
// 阻断插件
|
|||
interceptor.addInnerInterceptor(blockAttackInnerInterceptor()); |
|||
return interceptor; |
|||
} |
|||
|
|||
/** |
|||
* 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html
|
|||
*/ |
|||
public PaginationInnerInterceptor paginationInnerInterceptor() { |
|||
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
|||
// 设置数据库类型为mysql
|
|||
paginationInnerInterceptor.setDbType(DbType.MYSQL); |
|||
// 设置最大单页限制数量,默认 500 条,-1 不受限制
|
|||
paginationInnerInterceptor.setMaxLimit(-1L); |
|||
return paginationInnerInterceptor; |
|||
} |
|||
|
|||
/** |
|||
* 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
|
|||
*/ |
|||
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { |
|||
return new OptimisticLockerInnerInterceptor(); |
|||
} |
|||
|
|||
/** |
|||
* 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
|
|||
*/ |
|||
public BlockAttackInnerInterceptor blockAttackInnerInterceptor() { |
|||
return new BlockAttackInnerInterceptor(); |
|||
} |
|||
|
|||
} |
@ -1,9 +0,0 @@ |
|||
package com.win.bank.dal.mysql.bank; |
|||
|
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.win.bank.dal.dataobject.bank.BankDO; |
|||
|
|||
@Mapper |
|||
public interface BankMapper extends BaseMapper<BankDO> {} |
@ -1,10 +1,9 @@ |
|||
package com.win.bank.dal.dataobject.bank; |
|||
package com.win.bank.domain; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.win.bank.dal.dataobject.BaseDO; |
|||
|
|||
import lombok.*; |
|||
|
@ -1,4 +1,4 @@ |
|||
package com.win.bank.dal.dataobject; |
|||
package com.win.bank.domain; |
|||
|
|||
import java.io.Serializable; |
|||
|
@ -0,0 +1,10 @@ |
|||
package com.win.bank.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.win.bank.domain.BankDO; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
@Mapper |
|||
public interface BankMapper extends BaseMapper<BankDO> { |
|||
|
|||
} |
@ -1,21 +0,0 @@ |
|||
package com.win.bank.service.bank; |
|||
|
|||
import java.util.List; |
|||
|
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.win.bank.dal.dataobject.bank.BankDO; |
|||
import com.win.bank.dal.mysql.bank.BankMapper; |
|||
|
|||
@Service |
|||
public class BankServiceImpl extends ServiceImpl<BankMapper, BankDO> implements BankService { |
|||
|
|||
@Override |
|||
public List<BankDO> listByStatus(String status) { |
|||
QueryWrapper<BankDO> queryWrapper = new QueryWrapper<>(); |
|||
queryWrapper.eq("status", status); |
|||
return list(queryWrapper); |
|||
} |
|||
} |
@ -0,0 +1,57 @@ |
|||
# MyBatis Plus配置 |
|||
mybatis-plus: |
|||
# 不支持多包, 如有需要可在注解配置 或 提升扫包等级 |
|||
# 例如 com.**.**.mapper |
|||
mapperPackage: com.win.bank.mapper |
|||
# 对应的 XML 文件位置 |
|||
mapperLocations: classpath*:mapper/*Mapper.xml |
|||
# 实体扫描,多个package用逗号或者分号分隔 |
|||
typeAliasesPackage: com.win.bank.domain |
|||
# 加载全局的配置文件 |
|||
# configLocation: classpath:mybatis/mybatis-config.xml |
|||
# 启动时是否检查 MyBatis XML 文件的存在,默认不检查 |
|||
checkConfigLocation: false |
|||
configuration: |
|||
# 自动驼峰命名规则(camel case)映射 |
|||
mapUnderscoreToCamelCase: true |
|||
# MyBatis 自动映射策略 |
|||
# NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射 |
|||
autoMappingBehavior: PARTIAL |
|||
# MyBatis 自动映射时未知列或未知属性处理策 |
|||
# NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息 |
|||
autoMappingUnknownColumnBehavior: NONE |
|||
# 开启缓存 |
|||
cache-enabled: true |
|||
# 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl |
|||
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl |
|||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl |
|||
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl |
|||
global-config: |
|||
# 是否打印 Logo banner |
|||
banner: false |
|||
dbConfig: |
|||
# 主键类型 |
|||
# AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID |
|||
id_type: AUTO |
|||
# 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) |
|||
# logic-delete-field: flag |
|||
# 逻辑已删除值(默认为 1) |
|||
logic-delete-value: 1 |
|||
# 逻辑未删除值(默认为 0) |
|||
logic-not-delete-value: 0 |
|||
# 逻辑已删除值 |
|||
logicDeleteValue: 2 |
|||
logicNotDeleteValue: 0 |
|||
# 字段验证策略之 insert,在 insert 的时候的字段验证策略 |
|||
# IGNORED 忽略 NOT_NULL 非NULL NOT_EMPTY 非空 DEFAULT 默认 NEVER 不加入 SQL |
|||
insert_strategy: NOT_NULL |
|||
# 字段验证策略之 update,在 update 的时候的字段验证策略 |
|||
update_strategy: NOT_NULL |
|||
# 字段验证策略之 select,在 select 的时候的字段验证策略既 wrapper 根据内部 entity 生成的 where 条件 |
|||
where-strategy: NOT_NULL |
|||
|
|||
# PageHelper分页插件 |
|||
pagehelper: |
|||
helperDialect: mysql |
|||
supportMethodsArguments: true |
|||
params: count=countSql |
@ -0,0 +1,5 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.win.tms.system.mapper.CarrierFinanceMapper"> |
|||
|
|||
</mapper> |
@ -1,12 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.win.bank.dal.mysql.bank.BankMapper"> |
|||
|
|||
<!-- |
|||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 |
|||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 |
|||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 |
|||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ |
|||
--> |
|||
|
|||
</mapper> |
Loading…
Reference in new issue