update > optimize code annotation

master
lihengming 8 years ago
parent 3c530ca168
commit 4eee7b8ced
  1. 4
      src/main/java/com/company/project/core/AbstractService.java
  2. 2
      src/main/java/com/company/project/core/Service.java

@ -49,10 +49,10 @@ public abstract class AbstractService<T> implements Service<T> {
} }
@Override @Override
public T findBy(String property, Object value) throws TooManyResultsException { public T findBy(String fieldName, Object value) throws TooManyResultsException {
try { try {
T model = modelClass.newInstance(); T model = modelClass.newInstance();
Field field = modelClass.getDeclaredField(property); Field field = modelClass.getDeclaredField(fieldName);
field.setAccessible(true); field.setAccessible(true);
field.set(model, value); field.set(model, value);
return mapper.selectOne(model); return mapper.selectOne(model);

@ -15,7 +15,7 @@ public interface Service<T> {
void deleteByIds(String ids);//批量刪除 eg:ids -> “1,2,3,4” void deleteByIds(String ids);//批量刪除 eg:ids -> “1,2,3,4”
void update(T model);//更新 void update(T model);//更新
T findById(Integer id);//通过ID查找 T findById(Integer id);//通过ID查找
T findBy(String property, Object value) throws TooManyResultsException; //通过某个成员属性查找,value需符合unique约束 T findBy(String fieldName, Object value) throws TooManyResultsException; //通过Model中某个成员变量名称(非数据表中column的名称)查找,value需符合unique约束
List<T> findByIds(String ids);//通过多个ID查找//eg:ids -> “1,2,3,4” List<T> findByIds(String ids);//通过多个ID查找//eg:ids -> “1,2,3,4”
List<T> findByCondition(Condition condition);//根据条件查找 List<T> findByCondition(Condition condition);//根据条件查找
List<T> findAll();//获取所有 List<T> findAll();//获取所有

Loading…
Cancel
Save