1.分类表设计(两级分类)与持久层代码生成
①在DBeaver中生成表并插入数据
②生成器配置文件中(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>