Skip to content

Commit

Permalink
分类修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Q-1515 committed Jul 21, 2022
1 parent 05e3a2a commit b1494aa
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CategoryController {
public R<String> save(@RequestBody CategoryDTO categoryDTO) {
log.info("新增分类:{}", categoryDTO);
categoryService.save(categoryDTO);
return R.success("添加成功");
return R.success("分类添加成功");
}


Expand Down Expand Up @@ -62,7 +62,20 @@ public R<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
public R<String> deleteById(Long id) {
log.info("删除分类:{}", id);
categoryService.deleteById(id);
return R.success("删除成功");
return R.success("分类删除成功");
}

/**
* 修改分类
* @param categoryDTO 修改id 修改name 修改sort
* @return success
*/
@PutMapping
@ApiOperation("修改分类")
public R<String> update(@RequestBody CategoryDTO categoryDTO) {
log.info("修改分类:{}", categoryDTO);
categoryService.update(categoryDTO);
return R.success("分类修改成功");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public interface CategoryMapper {

//删除分类
void deleteById(Long id);

@AutoFill(type = AutoFillConstant.UPDATE)
//修改分类
void update(Category category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

import com.reggie.dto.CategoryDTO;
import com.reggie.dto.CategoryPageQueryDTO;
import com.reggie.mapper.CategoryMapper;
import com.reggie.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

public interface CategoryService {
//新增分类
Expand All @@ -16,4 +14,7 @@ public interface CategoryService {

//根据id删除分类
void deleteById(Long id);

//修改分类
void update(CategoryDTO categoryDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,19 @@ public void deleteById(Long id) {
//删除分类
categoryMapper.deleteById(id);
}


/**
* 修改分类
*
* @param categoryDTO 修改id 修改name 修改sort
*/
public void update(CategoryDTO categoryDTO) {
//拷贝数据
Category category = new Category();
BeanUtils.copyProperties(categoryDTO,category);

categoryMapper.update(category);

}
}
27 changes: 27 additions & 0 deletions reggie_server/src/main/resources/mapper/CategoryMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,31 @@
from category
where id = #{id}
</delete>


<!--修改分类-->
<update id="update">
update category
<set>
<if test="type != null">
type = #{type},
</if>
<if test="name != null and name !=''">
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>
</mapper>

0 comments on commit b1494aa

Please sign in to comment.