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

news2024/9/29 19:53:19

前言

   
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项目中的分类管理,操作类似员工管理模块

新增分类

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 {
    @Autowired
    private CategoryService categoryService;

    //新增分类
    @PostMapping
    @ApiOperation("新增分类")
    public Result save(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类:{}",categoryDTO);
        categoryService.save(categoryDTO);
        return  Result.success();

    }


}
package com.sky.service;

import com.sky.dto.CategoryDTO;

public interface CategoryService {
    //新增分类
    void save(CategoryDTO categoryDTO) ;
}
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 {
    //新增分类
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public 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);

    }
}

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);
}

分类分页查询

//分类分页查询
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类分页查询,参数为:{}",categoryPageQueryDTO);
        PageResult pageResult=categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
//分类分页查询
    PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
 @Override
    public 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);
    }
 //分类分页查询
    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
<?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>

启用禁用分类

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

    }

//启用禁用分类
    void update(Category category);
<!--启用禁用分类-->
    <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>

根据类型查询

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

    }
  //根据类型查询
    Category getByType(Integer type);

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

修改分类

//修改分类
    @PutMapping
    @ApiOperation("修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类:{}",categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }
//修改分类
    void update(CategoryDTO categoryDTO);
 //修改分类
    @Override
    public 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.coloradmin.cn/o/2177680.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

webGL入门(四)绘制一个三角形

代码&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title><scri…

DBMS-2.3 数据库设计(3)——数据库规范化设计实现(3NF、BCNF模式分解)

本文章的素材与知识来自李国良老师和王珊珊老师。 关系模式分解的定义 一.关系模式分解的定义 1.定义 2.理解 &#xff08;1&#xff09;关系不丢失&#xff1a;所有子关系的属性集加起来 原关系的属性集。即分解中不能把某个属性给丢了。 &#xff08;2&#xff09;模式…

8.6K Star,一键将 Markdown 可视化为思维导图

Hi&#xff0c;骚年&#xff0c;我是大 G&#xff0c;公众号「GitHub 指北」会推荐 GitHub 上有趣有用的项目&#xff0c;一分钟 get 一个优秀的开源项目&#xff0c;挖掘开源的价值&#xff0c;欢迎关注。 在知识管理和项目规划中&#xff0c;思维导图是非常有效的工具&#…

【Flume Kafaka实战】Using Kafka with Flume

一 目标 在Cloudera Manager中创建两个Flume的Agent&#xff0c;Agent1从local file中获取内容&#xff0c;写入到kafka的队列中。Agent2以Agent1的sink作为source&#xff0c;将数据从kafka中读取出来&#xff0c;写入到HDFS中。 二 实战 2.1 Kafka Sink 第一步&#xff0…

Java-数据类型与变量

一、字面常量 在我们使用Java进行数据的打印时&#xff0c;经常会用到这个语句&#xff1a; System.out.println("Hello world!"); 而当这个语句运行时&#xff0c;不论如何都会输出"Hello world!"&#xff0c;所以"Hello world!"就是字面常量…

哪款宠物空气净化器能有效去除浮毛?希喂、352实测分享

你是否曾经站在家电卖场里&#xff0c;面对琳琅满目的宠物空气净化器产品而感到无所适从&#xff1f;或者在浏览网上商城时&#xff0c;被海量的参数和功能描述搞得头晕眼花&#xff1f;别担心&#xff0c;你不是一个人。在这个科技飞速发展的时代&#xff0c;选择一台既能满足…

Grafana指标汉化

1、Grafana解压 目录 conf 2、找到&#xff1a;defaults.ini 3、打开defaults.ini &#xff0c;搜索&#xff1a;en-US 4.重新运行 &#xff1a;grafana-server.exe

开放词汇全景分割

开放词汇全景分割是一种先进的计算机视觉任务&#xff0c;它旨在将图像中的每个像素分割并分类到预先定义或未定义的类别中。这与传统的图像分割不同&#xff0c;后者通常仅限于识别有限的、预先定义的对象类别。开放词汇全景分割的目标是识别和处理图像中的任何可能的对象&…

基于Hadoop的微博舆情监测分析系统

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

大模型,互联网玩家们的「角斗场」

文/孟永辉 布局大模型&#xff0c;似乎正在成为每一个互联网玩家必然都要去做的事情。无论是以BAT为代表的综合性的大型平台来讲&#xff0c;还是以WPS、携程为代表的专业性的平台们而言&#xff0c;几乎都是如此。一时间&#xff0c;大模型&#xff0c;成为了一个全新的风口。…

9.5K Star,开源在线网盘

Hi&#xff0c;骚年&#xff0c;我是大 G&#xff0c;公众号「GitHub 指北」会推荐 GitHub 上有趣有用的项目&#xff0c;一分钟 get 一个优秀的开源项目&#xff0c;挖掘开源的价值&#xff0c;欢迎关注。 随着云存储的广泛应用&#xff0c;越来越多的人和企业需要一个简单、…

android SELinux权限适配

抓log方法&#xff0c; setenforce 0, 如果不先将selinux设置为permission mode&#xff0c;会导致一个问题。 程序运行的时候遇到权限策略限制&#xff08;假设 sepolicy 1&#xff09;&#xff0c;程序运行失败。添加权限&#xff08;sepolicy 1&#xff09;&#xff0c;然后…

Java Web —— 第十天(SpringBoot原理)

SpringBoot框架之所以使用起来更简单更快捷&#xff0c;是因为SpringBoot框架底层提供了两个非常重要的 功能&#xff1a;一个是起步依赖&#xff0c;一个是自动配置。 通过SpringBoot所提供的起步依赖&#xff0c;就可以大大的简化pom文件当中依赖的配置&#xff0c;从而解决…

Python 知识宝库 —— 数据可视化:matplotlib 与 seaborn 的使用技巧

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《C干货基地》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 博主简介 博主致力于嵌入式、Python、人工智能、C/C领域和各种前沿技术的优质博客分享&#xff0c;用最优质的内容带来最舒适的…

SpringBoot日常:链路追踪skyworking的接入

前言 开发中遇到这样的一个常见&#xff0c;服务之间调用需要链路追踪&#xff0c;并且日志报错时能够及时预警&#xff0c;最重要的一点是不要写太多的侵入式代码&#xff0c;那么我们来捋捋常用的链路追踪组件&#xff0c;有Google的Dapper&#xff0c;阿里的鹰眼&#xff0…

Excel提取数据

Excel提取数据 在使用Excel的过程中&#xff0c;我需要将带有评语的评分的文本内容提取出评分&#xff0c;如下所示 其中分数与文本之间用空格分隔&#xff0c;只有分数的评语会自动靠右对齐&#xff0c;我需要做的就是将B列的评语从中提取出分数放到C列中&#xff0c;以下为实…

卡牌小程序搭建:多样化在线拆卡体验

潮玩市场已经成为备受消费者瞩目的行业&#xff0c;新兴的潮流玩具不断出现&#xff0c;其中卡牌更是备受广大消费者关注&#xff0c;不管是哪个年龄层的消费者&#xff0c;对卡牌都非常情有独钟。在科技的不断发展下&#xff0c;卡牌的玩法与互联网相结合&#xff0c;打造出了…

如何高效删除 MySQL 日志表中的历史数据?实战指南

在处理高并发的物联网平台或者其他日志密集型应用时&#xff0c;数据库中的日志表往往会迅速增长&#xff0c;数据量庞大到数百GB甚至更高&#xff0c;严重影响数据库性能。如何有效管理这些庞大的日志数据&#xff0c;特别是在不影响在线业务的情况下&#xff0c;成为了一项技…

IPD变革中,数据治理是关键

IPD变革中&#xff0c;数据治理是关键 2024-09-29 14:41汉捷咨询 华为轮值董事长徐直军先生在回顾IPD变革时&#xff0c;提到&#xff1a;“华为IPD变革前期&#xff0c;对数据的关注不够&#xff0c;没有系统梳理产品的信息架构和数据标准&#xff0c;也没有对业务流中的数据…

C++的隐式构造函数、隐式转换和explicit关键字

1、隐式的意思是不用告诉它该怎么做&#xff0c;有点类似于自动化的意思 #include <iostream> #include <string>class Entity { private:std::string m_Name;int m_Age; public:Entity(const std::string& name) :m_Name(name),m_Age(-1){}Entity(int age):…