默认注入DictionaryService

This commit is contained in:
mazhicheng 2020-05-13 20:52:11 +08:00
parent 4d921db14a
commit ecc5c90884
2 changed files with 12 additions and 21 deletions

View File

@ -21,6 +21,7 @@ import com.diboot.core.config.Cons;
import com.diboot.core.entity.BaseEntity;
import com.diboot.core.exception.BusinessException;
import com.diboot.core.service.BaseService;
import com.diboot.core.service.DictionaryService;
import com.diboot.core.util.BeanUtils;
import com.diboot.core.util.ContextHelper;
import com.diboot.core.util.S;
@ -30,8 +31,8 @@ import com.diboot.core.vo.Pagination;
import com.diboot.core.vo.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
@ -44,25 +45,27 @@ import java.util.Map;
* @version 2.0
* @date 2019/01/01
*/
public class BaseCrudRestController<E extends BaseEntity, VO extends Serializable> extends BaseController {
public class BaseCrudRestController<E extends BaseEntity> extends BaseController {
private static final Logger log = LoggerFactory.getLogger(BaseCrudRestController.class);
/**
* EntityVO对应的class
*/
private Class<E> entityClass;
private Class<VO> voClasss;
/**
* Service实现类
*/
private BaseService baseService;
@Autowired
protected DictionaryService dictionaryService;
/**
* 查询ViewObject用于子类重写的方法
* @param id
* @return
* @throws Exception
*/
protected JsonResult getViewObject(Serializable id) throws Exception{
protected <VO> JsonResult getViewObject(Serializable id, Class<VO> voClass) throws Exception{
// 检查String类型id
if(id instanceof String && !S.isNumeric((String)id)){
String pk = ContextHelper.getPrimaryKey(getEntityClass());
@ -70,7 +73,7 @@ public class BaseCrudRestController<E extends BaseEntity, VO extends Serializabl
throw new BusinessException(Status.FAIL_INVALID_PARAM, "参数id类型不匹配");
}
}
VO vo = (VO)getService().getViewObject(id, getVOClass());
VO vo = (VO)getService().getViewObject(id, voClass);
return new JsonResult(vo);
}
@ -82,10 +85,10 @@ public class BaseCrudRestController<E extends BaseEntity, VO extends Serializabl
* @return JsonResult
* @throws Exception
*/
protected JsonResult getViewObjectList(E entity, Pagination pagination) throws Exception {
protected <VO> JsonResult getViewObjectList(E entity, Pagination pagination, Class<VO> voClass) throws Exception {
QueryWrapper<E> queryWrapper = super.buildQueryWrapper(entity);
// 查询当前页的数据
List<VO> voList = getService().getViewObjectList(queryWrapper, pagination, getVOClass());
List<VO> voList = getService().getViewObjectList(queryWrapper, pagination, voClass);
// 返回结果
return JsonResult.OK(voList).bindPagination(pagination);
}
@ -354,17 +357,4 @@ public class BaseCrudRestController<E extends BaseEntity, VO extends Serializabl
return this.entityClass;
}
/**
* 获取VO的class
* @return
*/
protected Class<VO> getVOClass(){
if(this.voClasss == null){
this.voClasss = BeanUtils.getGenericityClass(this, 1);
if(this.voClasss == null) {
log.warn("无法从 {} 类定义中获取泛型类voClasss", this.getClass().getName());
}
}
return this.voClasss;
}
}

View File

@ -23,11 +23,12 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* 附带extdata扩展字段的Entity父类
* 附带extdata扩展字段的Entity父类 已废弃
* @author mazc@dibo.ltd
* @version v2.0
* @date 2018/12/27
*/
@Deprecated
public abstract class BaseExtEntity extends BaseEntity {
private static final long serialVersionUID = 10204L;