其他分享
首页 > 其他分享> > MyBatis 批量修改(update)数据表某字段

MyBatis 批量修改(update)数据表某字段

作者:互联网

<update id="updateName">
       update student set grade = #{newGrade}, course = #{newCourse}
       where stuID in (
       <foreach collection="idList" item="item" index="index" open="" close="" separator=",">
           #{item}
       </foreach>
       )
   </update>
	int updateInfo(@Param("idList") List idList, @Param("newGrade") String newGrade, @Param("newCourse") String newCourse);
	boolean updateInfo(List idList, String newGrade, String newCourse);
@Override
	public boolean updateInfo(List idList, String newGrade, String newCourse) {
		int result = baseMapper.updateInfo(idList, newGrade, newCourse);
		return result > 0;
	}
	@PostMapping("/updateInfo")
	@ApiOperationSupport
	@Transactional(rollbackFor = Exception.class)
	@ApiOperation(value = "批量更改学生信息", notes = "传入需要修改的学生id,grade,course")
	public R<Object> updateInfo(@RequestBody Map<String,Object> map) {
		if (!ObjectUtils.isEmpty(map.get("idList"))) {
			// 更新的执行结果(true:成功,false:失败)
			boolean result = false;
			// 将接收到的学生ids 转为 list
			List idList= Arrays.asList(String.valueOf(map.get("idList")).split(","));
			result = studentService.updateInfo(idList, String.valueOf(map.get("newGrade")), String.valueOf(map.get("newCourse")));
			if (!result) {
				throw new ServiceException("更新失败!");
			}
		}
		return R.status(true);
	}
export const updateInfo= (param) => {
  return request({
    url: '/api/collage/student/updateInfo',
    method: 'post',
    data: param
  })
}
var param = {
		idList:this.stuIds,
        newGrade:this.grade,
        newCourse:this.course,
      }

标签:某字段,String,newCourse,updateInfo,update,数据表,newGrade,result,idList
来源: https://blog.csdn.net/weixin_38115942/article/details/121913216