add example Logic
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.imyeyu.spring.util;
|
||||
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.bean.Logic;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.builder.annotation.ProviderContext;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
@@ -28,17 +30,17 @@ public class RawSQLProvider extends SQLProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectByExample(Object entity) {
|
||||
return selectAllByExample(entity) + BaseMapper.LIMIT_1;
|
||||
public String selectByExample(@Param("entity") Object entity, @Param("logic") Logic logic) {
|
||||
return selectAllByExample(entity, logic) + BaseMapper.LIMIT_1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectAllByExample(Object entity) {
|
||||
public String selectAllByExample(@Param("entity") Object entity, @Param("logic") Logic logic) {
|
||||
EntityMeta meta = getEntityMeta(entity.getClass());
|
||||
String conditionClause = meta.fieldColumnList.stream()
|
||||
.filter(fc -> fc.isNotEmpty(entity))
|
||||
.map(fc -> "`%s` = #{%s}".formatted(fc.columnName, fc.fieldName))
|
||||
.collect(Collectors.joining(" AND "));
|
||||
.map(fc -> "`%s` = #{entity.%s}".formatted(fc.columnName, fc.fieldName))
|
||||
.collect(Collectors.joining(" %s ".formatted(logic)));
|
||||
return "SELECT %s FROM `%s` WHERE %s".formatted(meta.selectAllClause, meta.table, conditionClause);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user