0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

第六章 分类管理功能开发

Last updated at Posted at 2025-01-09

1.分类表设计(两级分类)与持久层代码生成

①在DBeaver中生成表并插入数据

image.png

②生成器配置文件中(generator-config.xml):

生成对应的四个类

<table tableName="category"/>

2.完成分类基本增删改查功能

⭐从电子书管理复制

①controller层下新建CategoryController类

②req下新建CategoryQueryReq类:重写tostring方法

③req下新建CategorySaveReq类

④resp下新建CategoryQueryResp类

⑤service层下新建CategoryService类

⑥在components/the-header中新增目录

<a-menu-item key="/admin/category">
       <router-link to="/admin/category">分类管理</router-link>
</a-menu-item>

⑦在router/index中新增路径

import AdminCategory from '../views/admin/admin-category.vue'

{
    path: '/admin/category',
    name: 'AdminCategory',
    component: AdminCategory
  },

⑧增加分类管理页面:admin-category

⑨为解决id精度问题增加JacksonConfig类(雪花算法产生的问题)

package com.jiawa.wiki.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;


@Configuration
public class JacksonConfig {
    @Bean
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
        objectMapper.registerModule(simpleModule);
        return objectMapper;
    }
}

3.分类表格显示优化

①不需要分页,一次查出全部数据

②改为树型表格展示

4.分类编辑功能优化

编辑(新增/修改)分类时,支持选中某一分类作为父分类,或无父分类

(父分类改为下拉选择)

<a-form-item label="父分类">
        <a-select
            v-model:value="category.parent"
            ref="select"
        >
          <a-select-option value="0">
            
          </a-select-option>
          <a-select-option v-for="c in level1" :key="c.id" :value="c.id" :disabled="category.id === c.id">
            {{c.name}}
          </a-select-option>
        </a-select>
</a-form-item>

5.电子书管理增加分类选择

①分类选择改为级联选择组件

②电子书列表显示分类名称

③ 修复BUG,编辑保存重新加载数据后,再点编辑,则列表显示的还是编辑前的数据

6.首页显示分类菜单

7.点击分类菜单显示电子书

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?