修改分类
1 CategoryController里添加update
@PutMapping
@ApiOperation("修改分类")
public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
log.info("修改分类:{}", categoryDTO);
categoryService.update(categoryDTO);
return Result.success();
}
2 categoryService接口中添加方法update
void update(CategoryDTO categoryDTO);
3 categoryService实现类CategoryServiceImpl实现update方法
public void update(CategoryDTO categoryDTO) {
Category category = new Category();
BeanUtils.copyProperties(categoryDTO, category);
category.setUpdateTime(LocalDateTime.now());
category.setUpdateUser(BaseContext.getCurrentId());
categoryMapper.update(category);
}
4 categoryMapper中添加update方法
void update(Category category);
5 xml文件中的动态sql
<update id="update" parameterType="com.sky.entity.Category">
update category
<set>
<if test="type != null">
type = #{type},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="sort != null">
sort = #{sort},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="updateUser != null">
update_user = #{updateUser}
</if>
</set>
where id = #{id}
</update>