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")
public Integer isValid; //EnumUtil.isValid;
@Column(name="create_user")
@Column(name="create_user",updatable = false)
@ApiParam(value = "创建用户")
public String createUser;
@Column(name="create_date")
@Column(name="create_date",updatable = false)
@ApiParam(value = "创建日期")
public String createDatetime;

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

@ -145,14 +145,19 @@ public class BaseRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRep
@Override
public void deleteByIds(Long[] ids) {
if(ids != null && ids.length > 0){
String hql = "delete from " + persistentClass.getName() + " model where model.id in(:ids) ";
deleteByTypeLong("id", 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.setParameter("ids", Arrays.asList(ids));
query.executeUpdate();
}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")
private Integer roleStatusId;
}

Loading…
Cancel
Save