Base Repository 添加批量删除方法

yun-zuoyi
wei.peng 7 years ago
parent 1a3183addf
commit bbe6b4f544

@ -56,11 +56,11 @@ public abstract class BaseBean implements Serializable {
@ApiParam(value = "有效性",example = "1") @ApiParam(value = "有效性",example = "1")
public Integer isValid; //EnumUtil.isValid; public Integer isValid; //EnumUtil.isValid;
@Column(name="create_user") @Column(name="create_user",updatable = false)
@ApiParam(value = "创建用户") @ApiParam(value = "创建用户")
public String createUser; public String createUser;
@Column(name="create_date") @Column(name="create_date",updatable = false)
@ApiParam(value = "创建日期") @ApiParam(value = "创建日期")
public String createDatetime; public String createDatetime;

@ -83,6 +83,13 @@ public interface BaseRepository <T, ID extends Serializable> extends JpaReposito
public void deleteByIds(Long[] ids); public void deleteByIds(Long[] ids);
/** /**
*
* @param propName
* @param ids
*/
public void deleteByTypeLong(String propName, Long[] ids);
/**
* *
* @param conditionName * @param conditionName
* @param conditionValue * @param conditionValue

@ -145,14 +145,19 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
@Override @Override
public void deleteByIds(Long[] ids) { public void deleteByIds(Long[] ids) {
if(ids != null && ids.length > 0){ deleteByTypeLong("id", ids);
String hql = "delete from " + persistentClass.getName() + " model where model.id in(:ids) "; }
@Override
public void deleteByTypeLong(String propName, Long[] ids) {
if ((propName != null && propName.length() > 0) && (ids != null && ids.length > 0)) {
String hql = "delete from " + persistentClass.getName() + " model where model."+propName+" in(:ids) ";
Query query = entityManager.createQuery(hql); Query query = entityManager.createQuery(hql);
query.setParameter("ids", Arrays.asList(ids)); query.setParameter("ids", Arrays.asList(ids));
query.executeUpdate(); query.executeUpdate();
}else{ }else{
throw new IllegalArgumentException("Method deleteByPropertiesIn argument is illegal! ids:" + ids); throw new IllegalArgumentException("Method deleteByPropertiesIn argument is illegal! "+propName+":" + ids);
} }
} }

@ -77,6 +77,4 @@ public class SysRole extends BaseBean {
@ApiParam(value ="角色状态枚举1.正常2.状态)" , example ="-1") @ApiParam(value ="角色状态枚举1.正常2.状态)" , example ="-1")
private Integer roleStatusId; private Integer roleStatusId;
} }

Loading…
Cancel
Save