BaseService增加selectFirstByExampleWithBLOBs公共接口和实现

This commit is contained in:
shuzheng 2017-03-26 01:27:21 +08:00
parent ae6193d35a
commit dd92445bdb
3 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,8 @@ public interface BaseService<Record, Example> {
Record selectFirstByExample(Example example);
Record selectFirstByExampleWithBLOBs(Example example);
Record selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") Record record, @Param("example") Example example);

View File

@ -132,6 +132,22 @@ public abstract class BaseServiceImpl<Mapper, Record, Example> implements BaseSe
return null;
}
@Override
public Record selectFirstByExampleWithBLOBs(Example example) {
try {
DynamicDataSource.setDataSource(DataSourceEnum.SLAVE.getName());
Method selectByExampleWithBLOBs = mapper.getClass().getDeclaredMethod("selectByExampleWithBLOBs", example.getClass());
List<Record> result = (List<Record>) selectByExampleWithBLOBs.invoke(mapper, example);
if (null != result && result.size() > 0) {
return result.get(0);
}
} catch (Exception e) {
e.printStackTrace();
}
DynamicDataSource.clearDataSource();
return null;
}
@Override
public Record selectByPrimaryKey(Integer id) {
try {

View File

@ -50,6 +50,11 @@ public abstract class BaseServiceMock<Mapper, Record, Example> implements BaseSe
return null;
}
@Override
public Record selectFirstByExampleWithBLOBs(Example example) {
return null;
}
@Override
public Record selectByPrimaryKey(Integer id) {
return null;