电商项目(十四)--CMS对内容分类增删改查操作

common_content 做CMS维护的

创建common_content模块,修改pom文件(与common_item的pom文件相似)

pom文件修改

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>bz_parent</artifactId>
        <groupId>com.bjsxt</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>common_item</artifactId>

    <dependencies>
        <!--mapper-->
        <dependency>
            <groupId>com.bjsxt</groupId>
            <artifactId>common_mapper</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <!-- utils -->
        <dependency>
            <groupId>com.bjsxt</groupId>
            <artifactId>common_utils</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <!--Spring Boot Web Starter-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--Spring Cloud Eureka Client Starter-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>



    </dependencies>


</project>

修改配置文件,添加相关配合信息

spring:
  application:
    name: common_content
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/bz_shop?characterEncoding=UTF-8
    username: root
    password: root
    type: com.alibaba.druid.pool.DruidDataSource

server:
  port: 9020

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-server:8761/eureka/

tx-lcn:
	client: 
		manager-address: 192.168.54.171:8070

创建启动类

在这里插入图片描述

创建backed_content模块

pom文件,添加相关依赖

```java
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>bz_parent</artifactId>
        <groupId>com.bjsxt</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>backend_item</artifactId>

    <dependencies>

        <!-- pojo-->
        <dependency>
            <groupId>com.bjsxt</groupId>
            <artifactId>common_pojo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <!--Spring Boot Web Starter-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--Spring Cloud Eureka Client Starter-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!--Spring Cloud OpenFeign Starter-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <!-- utils -->
        <dependency>
            <groupId>com.bjsxt</groupId>
            <artifactId>common_utils</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>


</project>

创建配置文件appilication.yml

spring:
  application:
    name: backend_content
  

server:
  port: 9021

eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka1:8761/eureka/
tx-lcn:
	client: 
		manager-address: 192.168.54.171:8070

创建启动类

在这里插入图片描述

实现内容分类的查询

下游服务:
在common_content中出创建ContentCategoryController,新增方法:根据父节点id查询子节点。方法的返回值是List集合,参数是:@RequestParam Long parentId
在业务层实现此方法,调用方法即可。

上游服务

在backed_content中出创建ContentCategoryController,新增方法:根据当前点id查询子节点。方法的返回值是Result,参数是:@RequestParam(defaultValue=“0”)Long id
在业务层实现查询内容分类的方法,调用feign中的方法,返回list集合,判断集合是否为空或者长度是否大于零,是则OK,反之error。
创建feign的包,创建一个接口类CommonContentFeignClient
在这里插入图片描述

实现添加内容分类(注意事务管理的不要忘记添加)

下游服务
在common_content中的ContentCategoryController,新增方法:添加内容分类。方法的返回值是Integer,参数是:@RequestBody TBContentCategory tbContentCategory
在业务层实现此方法,首先补齐数据(设置创建时间和更新时间,设置父节点为false,设置sortOrder为1,设置状态为1)。然后插入数据,然后查询当前节点的父节点是不是叶子结点(! isParent,设置父节点的isParent=1,对表进行更新操作)

上游服务

在backed_content中的ContentCategoryController,新增方法:添加内容分类。方法的返回值是Result,参数是: TBContentCategory tbContentCategory
在业务层中实现添加内容分类的方法,现在feign中声明,在业务层调用feign中的方法,在对查询结果判断是否为空,返回结果。

实现内容分类的删除操作(注意:事务管理)

下游服务
在common_content中的ContentCategoryController,新增方法:删除内容分类。方法的返回值是Integer,参数是:@RequestParam Long categoryId .
在业务层中是实现删除内容分类,首先查询当前节点,删除当前节点的子节点,查询当前节点的父节点,查看当前节点是否有兄弟节点,决定是否修改父节点的状态
在这里插入图片描述
在这里插入图片描述

定义一个私有的方法,实现删除当前节点和子节点(叶子结点的isparent是false),判断当前节点是不是父节点,不是父节点直接删除,是父节点需要查询当前节点的所有子节点,若子节点下还有子节点还需要进行递归删除
在这里插入图片描述

上游服务
在backed_content中的ContentCategoryController,新增方法:删除内容分类。方法的返回值是Result,参数是: Long categoryId

在业务层中实现删除商品分类的方法,调用feign的接口中的删除方法,判断方法的返回值是不是200,返回结果。

实现修改内容分类(注意事务管理)

下游服务
在common_content中的ContentCategoryController,新增方法:修改内容分类。方法的返回值是Integer,参数是:@RequestBody TBContentCategory tbContentCategory
在业务层实现更新商品分类的方法。

上游服务
在backed_content中的ContentCategoryController,新增方法:修改内容分类。方法的返回值是Result,参数是: TBContentCategory tbContentCategory
在业务层中实现修内容分类的方法,调用feign中定义的修改内容分类的方法,判断查询结果是否为空。

实现根据分类查询内容

下游服务
创建ContentController,新增方法:根据分类查询内容,方法的返回值:PageResult,方法的参数:@RequesrParam Integer page,@RequesrParam Integer rows,@RequesrParam Long category

在业务层中实现根据分类查询内容的方法,
在这里插入图片描述

上游服务

创建ContentController,新增方法:根据分类查询内容,方法的返回值:Result,方法的参数:@RequesrParam (defaultValue=“1”)Integer page,@RequesrParam(defaultValue=“3”) Integer rows, Long category

业务层中实现查询根据分类查询内容,在feign中添加对应的抽象方法,在调用对应的查询方法,完成查询即可
在这里插入图片描述

实现根据分类添加内容(注意:事务)

下游服务
在ContentController,新增方法:根据分类添加内容,方法的返回值:Integer,方法的参数:@RequesrBody TbContent tbContent
在业务层中进行相对应的插入数据即可。

上游服务

在ContentController,新增方法:根据分类新增内容,方法的返回值:Result,方法的参数:TbContent tbContent
在业务层中实现根据分类添加内容的方法,先在feign中新增根据分类添加内容的抽象方法,在通过feign调用对应的方法,在进行判断数据是否为空即可实现。

实现根据分类删除内容(注意:事务)

下游服务
在ContentController,新增方法:根据分类删除内容,方法的返回值:Integer,方法的参数:@RequesrParam Long id
在业务层中进行相对应的删除数据即可。

上游服务

在ContentController,新增方法:根据分类删除内容,方法的返回值:Result,方法的参数: Long ids
在业务层中实现根据分类删除内容的方法,先在feign中新增根据分类删除内容的抽象方法,在通过feign调用对应的方法,在进行判断数据是否为空即可实现。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值