类 BaseController<T1 extends BaseEntity,T2 extends IBaseService,ID>
- java.lang.Object
-
- me.youm.frame.jpa.base.controller.BaseController<T1,T2,ID>
-
public class BaseController<T1 extends BaseEntity,T2 extends IBaseService,ID> extends Object
基础控制器基类,包含常见的基本的CRUD的请求的处理,其他特殊的方法通过子类继承实现。 T1,是操作的实体类,T2是对应的service接口类继承IBaseService,ID是主键的类型- 作者:
- youta
-
-
字段概要
字段 修饰符和类型 字段 说明 private Class<T1>clazzT2entityServiceT1实体对应的Service,在子类控制器则不需要再次注入了
-
构造器概要
构造器 构造器 说明 BaseController()Description:无参构造函数,获得T1的clazz对象
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 me.youm.frame.common.model.Result<me.youm.frame.common.model.IPage>advancedPageQuery(org.springframework.data.domain.Pageable page, T1 entity)Description: 高级查询加分页功能me.youm.frame.common.model.Result<?>advancedQuery(T1 entity)Description: 高级查询不分页private T1buildQueryConditions(String q, String fields)Description:根据查询值及多字段,来构建高级查询条件BooleanchkEntityIdExist(ID entityId)Description:检查操作的idd对应实体是否存在,因为多人操作,可能被其他人删除了!me.youm.frame.common.model.Result<?>deleteById(ID id)Description:使用id删除指定的实体me.youm.frame.common.model.ResultdeleteByIds(Set<ID> entityIds)Description:使用id的Set集合来删除指定的实体,不使用数组防止存在重复的数据me.youm.frame.common.model.Result<?>getById(ID id)Description:根据id获取一个实体的信息me.youm.frame.common.model.ResultgetPropertySet(String property, String value)获取某个属性集合,去除重复,通常是前端选择需要,支持模糊匹配 非法属性自动过滤掉me.youm.frame.common.model.Result<me.youm.frame.common.model.IPage>page(org.springframework.data.domain.Pageable page)Description:实体的分页查询,包括排序等,使用SpringData自己的对象接收分页参数me.youm.frame.common.model.Result<?>queryMultiField(String q, String fields)Description: 同一个值,在多个字段中模糊查询,不分页me.youm.frame.common.model.Result<?>queryMultiField(String q, String fields, org.springframework.data.domain.Pageable page)Description:同一个值,在多个字段中模糊查询,分页me.youm.frame.common.model.Result<T1>save(T1 entity)Description:保存一个实体,保存之前会做检查me.youm.frame.common.model.Result<?>updateById(T1 entity)使用id来更新,如果属性空值,则不更新现有的值private T1updateEntity(T1 dbEntity, T1 entity, Boolean useNull, String... ignoreProperties)Description:是否使用前端的数据实体的空值属性更新数据库中的 true,则用空置更新;fasle则不用空值更新,还允许部分更新
-
-
-
字段详细资料
-
entityService
@Autowired public T2 extends IBaseService entityService
T1实体对应的Service,在子类控制器则不需要再次注入了
-
clazz
private Class<T1 extends BaseEntity> clazz
-
-
方法详细资料
-
page
public me.youm.frame.common.model.Result<me.youm.frame.common.model.IPage> page(org.springframework.data.domain.Pageable page)
Description:实体的分页查询,包括排序等,使用SpringData自己的对象接收分页参数- 参数:
page- 分页参数对象- 返回:
- R
-
advancedPageQuery
public me.youm.frame.common.model.Result<me.youm.frame.common.model.IPage> advancedPageQuery(org.springframework.data.domain.Pageable page, T1 entity)Description: 高级查询加分页功能- 参数:
page- 分页参数对象entity- 包含高级查询条件的实体- 返回:
- R
-
advancedQuery
public me.youm.frame.common.model.Result<?> advancedQuery(T1 entity)
Description: 高级查询不分页- 参数:
entity- 包含高级查询条件的实体- 返回:
- R
-
queryMultiField
public me.youm.frame.common.model.Result<?> queryMultiField(String q, String fields)
Description: 同一个值,在多个字段中模糊查询,不分页- 参数:
q- 模糊查询的值fields- 例如:"name,address,desc",对这三个字段进行模糊匹配- 返回:
- R
-
queryMultiField
public me.youm.frame.common.model.Result<?> queryMultiField(String q, String fields, org.springframework.data.domain.Pageable page)
Description:同一个值,在多个字段中模糊查询,分页- 参数:
q- 模糊查询的值fields- 例如:"name,address,desc",对这三个字段进行模糊匹配page- 分页参数对象- 返回:
- R
-
getById
public me.youm.frame.common.model.Result<?> getById(ID id)
Description:根据id获取一个实体的信息- 参数:
id- 主键- 返回:
- R
-
save
public me.youm.frame.common.model.Result<T1> save(T1 entity)
Description:保存一个实体,保存之前会做检查- 参数:
entity- 要保存的实体对象- 返回:
- R
-
updateById
public me.youm.frame.common.model.Result<?> updateById(T1 entity)
使用id来更新,如果属性空值,则不更新现有的值- 参数:
entity-- 返回:
- R
-
deleteById
public me.youm.frame.common.model.Result<?> deleteById(ID id)
Description:使用id删除指定的实体- 参数:
id- 使用主键id- 返回:
- R
-
deleteByIds
public me.youm.frame.common.model.Result deleteByIds(Set<ID> entityIds)
Description:使用id的Set集合来删除指定的实体,不使用数组防止存在重复的数据- 参数:
entityIds- 使用主键Set集合- 返回:
- R
-
chkEntityIdExist
public Boolean chkEntityIdExist(ID entityId)
Description:检查操作的idd对应实体是否存在,因为多人操作,可能被其他人删除了!- 参数:
entityId- 实体主键id- 返回:
- Boolean true存在,false 不存在
-
getPropertySet
public me.youm.frame.common.model.Result getPropertySet(String property, String value)
获取某个属性集合,去除重复,通常是前端选择需要,支持模糊匹配 非法属性自动过滤掉- 参数:
property- 驼峰式的属性value- 模糊查询的value值- 返回:
- R
-
updateEntity
private T1 updateEntity(T1 dbEntity, T1 entity, Boolean useNull, String... ignoreProperties)
Description:是否使用前端的数据实体的空值属性更新数据库中的 true,则用空置更新;fasle则不用空值更新,还允许部分更新- 参数:
dbEntity- 后端查询数据库的实体entity- 前端传来的实体useNull- 是否使用前端的空置更新数据库的有值属性ignoreProperties- 忽略的属性,就是前端需要用空值更新后端的属性,比如常见的:更新时间,更新时间由框架或者数据库自己维护- 返回:
- T1
-
-