java对象的删除 java中的删除语句
转载
lemon
2023-05-24 09:54:41
文章标签
java
CRUD
增删改查
bc
数组
文章分类
Java
后端开发
1、根据id批量删除数据方式一:sql实现推荐使用方式一,减少与数据库的交互次数,效率高1.1、接口void deleteBatchUser(Integer[] id);1.2、SQL语句:
delete from t_user where id in
#{userid}
for循环实现此方法在删除大数量下,不推荐(要删除100条数据的话,得循环100次,和数据库交互次数过多,影响数据库性能,效率低),小数据量可以。public Object deleteBatchUserIds(Integer[] ids) {
int count = 0;
for (Integer userid : ids) {
int i = userDao.deleteByPrimaryKey(userid);
count += i;
}
// 返回count,告诉用户成功删除了几条数据,或者直接告诉用户是否删除成功,看业务而定吧!
return count;
}2、动态SQL-模糊查询
select * from t_user
loginacct like concat('%',#{queryText},'%')
username like concat('%',#{username},'%')
order by createtime desc
limit #{startIndex},#{pagesize}
3.更新数据方式一:根据id更新单条数据
update t_user
set loginacct = #{loginacct,jdbcType=VARCHAR},
username = #{username,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
方式二:批量更新数据 |