| public class FindOne extends AbstractMethod { |
| |
| @Override |
| public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| |
| String sql = "select * from " + tableInfo.getTableName() |
| + " where " + tableInfo.getKeyColumn() + "=#{" + tableInfo.getKeyProperty() + "}"; |
| |
| String method = "findOne"; |
| SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass); |
| return addSelectMappedStatementForTable(mapperClass, method, sqlSource, tableInfo); |
| } |
| } |
| public class MySqlInjector extends DefaultSqlInjector { |
| |
| @Override |
| public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { |
| List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); |
| |
| methodList.add(new DeleteAll()); |
| methodList.add(new FindOne()); |
| |
| |
| |
| |
| |
| methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE)); |
| methodList.add(new AlwaysUpdateSomeColumnById()); |
| methodList.add(new LogicDeleteByIdWithFill()); |
| return methodList; |
| } |
| } |
| public interface MyBaseMapper<T> extends BaseMapper<T> { |
| |
| |
| |
| |
| |
| |
| default QueryChainWrapper<T> queryChain() { |
| return new QueryChainWrapper<>(this); |
| } |
| |
| default LambdaQueryChainWrapper<T> lambdaQueryChain() { |
| return new LambdaQueryChainWrapper<>(this); |
| } |
| |
| default UpdateChainWrapper<T> updateChain() { |
| return new UpdateChainWrapper<>(this); |
| } |
| |
| default LambdaUpdateChainWrapper<T> lambdaUpdateChain() { |
| return new LambdaUpdateChainWrapper<>(this); |
| } |
| |
| |
| |
| |
| int insertBatchSomeColumn(List<T> entityList); |
| |
| int alwaysUpdateSomeColumnById(@Param(Constants.ENTITY) T entity); |
| |
| int deleteByIdWithFill(T entity); |
| |
| |
| |
| |
| T findOne(Serializable id); |
| |
| int deleteAll(); |
| } |
| @Slf4j |
| @SpringBootTest |
| public class InjectorTest { |
| |
| @Resource |
| private StudentMapper studentMapper; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| @Test |
| public void test() { |
| log.error("--------------------------------------insert-------------------------------------------------------"); |
| List<Long> ids = Lists.newArrayList(); |
| for (int i = 0; i < 2; i++) { |
| Student student = new Student("小明" + i + "号", i); |
| studentMapper.insert(student); |
| ids.add(student.getId()); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| @Test |
| public void test1() { |
| log.error("--------------------------------------insert-------------------------------------------------------"); |
| List<Long> ids = Lists.newArrayList(); |
| for (int i = 0; i < 2; i++) { |
| Student student = new Student("小明" + i + "号", i); |
| studentMapper.insert(student); |
| ids.add(student.getId()); |
| } |
| log.error("--------------------------------------insertBatchSomeColumn-------------------------------------------------------"); |
| List<Student> ss = Lists.newArrayList(); |
| for (int i = 2; i < 20; i++) { |
| Student student = new Student("小明" + i + "号", i); |
| ss.add(student); |
| } |
| studentMapper.insertBatchSomeColumn(ss); |
| ids.addAll(ss.stream().map(Student::getId).collect(Collectors.toList())); |
| |
| Student select = studentMapper.select("select * from student where id = " + ids.get(0)); |
| System.out.println(select); |
| } |
| |
| |
| |
| |
| |
| @Test |
| public void test2() { |
| log.error("--------------------------------------deleteAll-------------------------------------------------------"); |
| studentMapper.deleteAll(); |
| } |
| |
| } |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术