4--苍穹外码-SpringBoot项目中分类管理 详解

server/2024/9/30 1:12:00/

前言

   
1--苍穹外卖-SpringBoot项目介绍及环境搭建 详解-CSDN博客

2--苍穹外卖-SpringBoot项目中员工管理 详解(一)-CSDN博客

3--苍穹外卖-SpringBoot项目中员工管理 详解(二)-CSDN博客

4--苍穹外码-SpringBoot项目中分类管理 详解-CSDN博客

5--苍穹外卖-SpringBoot项目中菜品管理 详解(一)-CSDN博客

6--苍穹外卖-SpringBoot项目中菜品管理 详解(二)-CSDN博客

7--苍穹外卖-SpringBoot项目中套餐管理 详解(一)-CSDN博客

8--苍穹外卖-SpringBoot项目中套餐管理 详解(二)-CSDN博客

9--苍穹外卖-SpringBoot项目中Redis的介绍及其使用实例 详解-CSDN博客

10--苍穹外卖-SpringBoot项目中微信登录 详解-CSDN博客


目录

新增分类

分类分页查询

启用禁用分类

根据类型查询

修改分类


本文介绍SpringBoot项目中的分类管理,操作类似员工管理模块

新增分类

java">package com.sky.controller.admin;import com.sky.dto.CategoryDTO;
import com.sky.properties.JwtProperties;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类相关接口")
public class CategoryController {@Autowiredprivate CategoryService categoryService;//新增分类@PostMapping@ApiOperation("新增分类")public Result save(@RequestBody CategoryDTO categoryDTO){log.info("新增分类:{}",categoryDTO);categoryService.save(categoryDTO);return  Result.success();}}
java">package com.sky.service;import com.sky.dto.CategoryDTO;public interface CategoryService {//新增分类void save(CategoryDTO categoryDTO) ;
}
java">package com.sky.service.impl;import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.dto.CategoryDTO;
import com.sky.entity.Category;
import com.sky.mapper.CategoryMapper;
import com.sky.service.CategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.time.LocalDateTime;@Service
public class CategoryServiceImpl implements CategoryService {//新增分类@Autowiredprivate CategoryMapper categoryMapper;@Overridepublic void save(CategoryDTO categoryDTO) {Category category = new Category();BeanUtils.copyProperties(categoryDTO,category);// BeanUtils.copyProperties(categoryDTO,category);category.setStatus(StatusConstant.ENABLE);category.setCreateTime(LocalDateTime.now());category.setUpdateTime(LocalDateTime.now());category.setCreateUser(BaseContext.getCurrentId());category.setUpdateUser(BaseContext.getCurrentId());categoryMapper.insert(category);}
}
java">package com.sky.mapper;import com.sky.entity.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface CategoryMapper {@Insert("insert into category (type, name, sort, status, create_time, " +"update_time, create_user, update_user) " +"values " +"(#{type},#{name},#{sort},#{status},#{createTime}," +"#{updateTime},#{createUser},#{updateUser})")void insert(Category category);
}

分类分页查询

java">//分类分页查询@GetMapping("/page")@ApiOperation("分类分页查询")public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){log.info("分类分页查询,参数为:{}",categoryPageQueryDTO);PageResult pageResult=categoryService.pageQuery(categoryPageQueryDTO);return Result.success(pageResult);}
java">//分类分页查询PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
java"> @Overridepublic PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());Page<Category> page=categoryMapper.pageQuery(categoryPageQueryDTO);long total = page.getTotal();List<Category> records = page.getResult();return new PageResult(total,records);}
java"> //分类分页查询Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
java"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.CategoryMapper">
<!--分类分页查询--><select id="pageQuery" resultType="com.sky.entity.Category">
select*from category
<where><if test="name!=null and name!=''">and name like concat('%',#{name},'%')</if><if test="type!=null">and type=#{type}
</if>
</where>
order by create_time desc</select>
</mapper>

启用禁用分类

java">//启用禁用分类@PostMapping("/status/{status}")@ApiOperation("启用禁用分类")public Result startOrStop(@PathVariable Integer status,Long id){log.info("启用禁用分类:{},{}",status,id);categoryService.startOrStop(status,id);return Result.success();}
java">//启用禁用分类void startOrStop(Integer status, Long id);
java">//启用禁用分类@Overridepublic void startOrStop(Integer status, Long id) {Category category = Category.builder().status(status).id(id).build();categoryMapper.update(category);}

java">//启用禁用分类void update(Category category);
java"><!--启用禁用分类--><update id="update" parameterType="category">update category<set><if test="name!=null">name=#{name},</if><if test="type!=null">type=#{type},</if><if test="sort!=null">sort=#{sort},</if><if test="updateTime!=null">update_Time=#{updateTime},</if><if test="updateUser!=null">update_User=#{updateUser},</if><if test="status!=null">status=#{status},</if></set>where id=#{id}</update>

根据类型查询

java">//根据类型查询@GetMapping("/list")@ApiOperation("根据类型查询")public Result<Category> getByType(Integer type){log.info("根据类型查询:{}",type);Category category=categoryService.getByType(type);return Result.success(category);}
java">  //根据类型查询Category getByType(Integer type);

java">//根据类型查询@Overridepublic Category getByType(Integer type) {Category category=categoryMapper.getByType(type);return category;}
java">//根据类型查询@Select("select *from category where type=#{type}")Category getByType(Integer type);

修改分类

java">//修改分类@PutMapping@ApiOperation("修改分类")public Result update(@RequestBody CategoryDTO categoryDTO){log.info("修改分类:{}",categoryDTO);categoryService.update(categoryDTO);return Result.success();}
java">//修改分类void update(CategoryDTO categoryDTO);
java"> //修改分类@Overridepublic void update(CategoryDTO categoryDTO) {Category category = new Category();BeanUtils.copyProperties(categoryDTO,category);category.setUpdateTime(LocalDateTime.now());category.setUpdateUser(BaseContext.getCurrentId());categoryMapper.update(category);}


http://www.ppmy.cn/server/124742.html

相关文章

【C语言刷力扣】1014.最佳观光组合

题目&#xff1a; 解题思路&#xff1a; 一开始对本题尝试两层for 循环遍历&#xff0c;时间复杂度为 &#xff0c; 超出时间限制&#xff0c;需要降低时间复杂度。 题目中求的组合得分可以分为 values[ i ] i 和 values[ j ] - j 两部分 要求得最高分即求 values[ i ] i 和…

9.28 daimayuan 模拟赛总结

感觉 -S 模拟赛时间好紧啊 复盘 8:00 开题 扫了一遍四道题&#xff0c;感觉 T1 很典&#xff0c;T2 有点神秘&#xff0c;T3 计数&#xff0c;但限制是简单的&#xff0c;看上去非常可做&#xff1b;T4 也有点神秘 推 T1&#xff0c;先定根&#xff0c;然后树形dp是显然的&…

STM32LL库之printf函数重定向

1. 加入以下代码 int fputc(int ch,FILE *f) {LL_USART_TransmitData8(USART1,ch);while(!LL_USART_IsActiveFlag_TXE(USART1));//需要等待发送完成return(ch); }记得添加 stdio.h 头文件 2. 在MDK中勾选&#xff1a;Use MicroLIB

8:00面试,8:06就出来了,问的问题有点变态。。。

在职业生涯的旅途中&#xff0c;我们总会遇到各种意想不到的挑战和转折。我从一家小公司跳槽至另一家公司&#xff0c;原以为能够迎接全新的工作环境和机遇&#xff0c;却未曾料到&#xff0c;等待我的是一场职场风暴。 新公司的加班文化让我倍感压力&#xff0c;虽然薪资诱人…

基于Selenium+Python的web自动化测试框架

&#x1f345; 点击文末小卡片&#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 一、什么是Selenium&#xff1f; Selenium是一个基于浏览器的自动化测试工具&#xff0c;它提供了一种跨平台、跨浏览器的端到端的web自动化解决方案。Selenium主…

【Linux】防火墙

一、防火墙命令 开启&#xff1a;service firewalld start 重启&#xff1a;service firewalld restart 关闭&#xff1a;service firewalld stop firewall-cmd state 查看防火墙状态 systemctl stop firewalld 临时开启防火墙 systemctl start firewalld 临时关闭防火墙 syst…

智能手机取证: 专家如何从被锁定设备中提取数据?

在数字取证领域&#xff0c;从被锁定的手机中检索数据的能力是决定调查成功与否的关键技能。由于智能手机往往是解决复杂案件的关键&#xff0c;智能手机取证已经成为打击犯罪和恐怖主义战争中的一个关键组成部分。通话记录、短信、电子邮件&#xff0c;甚至位置数据都可能被发…

基于php的医院信息管理系统

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、Vue项目源码、SSM项目源码 精品专栏&#xff1a;Java精选实战项目…