You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
package core.service;
|
|
|
|
import core.dao.BaseDao1;
|
|
import core.dao.BaseDao2;
|
|
import core.util.DBAction;
|
|
import db.model.AbstractModel;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Created by reborn on 2017/7/28.
|
|
*/
|
|
@Service
|
|
public class BaseService {
|
|
|
|
protected Logger log=LogManager.getLogger();
|
|
@Resource
|
|
protected BaseDao1 baseDao1;
|
|
|
|
@Resource
|
|
protected BaseDao2 baseDao2;
|
|
|
|
public<T extends AbstractModel> T curd(DBAction action, T command) {
|
|
switch (action) {
|
|
case C:
|
|
baseDao1.save(command);
|
|
case U:
|
|
baseDao1.update(command);
|
|
case R:
|
|
return baseDao1.get(command.getClass(), command.primaryKey()).cast();
|
|
case D:
|
|
baseDao1.delete(command);
|
|
default:
|
|
throw new RuntimeException("非法操作:" + action);
|
|
}
|
|
|
|
}
|
|
|
|
public <T extends AbstractModel> List find(T command, int firstResult, int maxResults){
|
|
return baseDao1.findByCriteria(command.getCriteria(),firstResult,maxResults);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|