文章目录
1.将jt项目改造为mybatis-plus后台
因为mybatis-plus的升级并不会影响mybatis的正常使用,所以后续我们的商品模块使用mybatis-plus来进行实现,并且此前用户模块还可以正常使用并不对其产生影响。
1.1 导入jar包
<!--导入MP的jar包文件-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
1.2 编辑POJO ItemCat
@Data
@Accessors(chain = true)
@TableName("item_cat") //关联数据表
public class ItemCat extends BasePojo{
@TableId(type = IdType.AUTO)//主键自增
private Integer id; //定义主键
private Integer parentId; //定义父级菜单 开启驼峰规则映射
private String name; //分类名称
private Boolean status; //分类状态 0 停用 1 正常
private Integer level; //商品分类等级 1 2 3
@TableField(exist = false) //属性不是表字段
private List<ItemCat> children;
}
这里我们还要额外使用 @TableField注解来标注children属性,因为其不是数据库表中的字段,无法与表中字段进行自动匹配,使用exist = false标注其不是表字段,到时候MP进行操作时就不会自动去匹配映射此字段,从而避免找不到字段而报错。
1.3 编辑ItemCatMapper接口
public interface ItemCatMapper extends BaseMapper<ItemCat> {
}
ItemCatMapper 接口和此前一样要继承 BaseMapper 接口并添加抽象类ItemCat。
1.4 修改YML文件
#配置端口号
server:
port: 8091
#管理数据源
spring:
datasource:
#高版本驱动使用
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
#设定用户名和密码
username: root
password: root
#SpringBoot整合Mybatis-plus
mybatis-plus:
#指定别名包
type-aliases-package: com.jt.pojo
#扫描指定路径下的映射文件
mapper-locations: classpath:/mybatis/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true
# 一二级缓存默认开始 所以可以简化
#打印mysql日志
logging:
level:
com.jt.mapper: debug
配置文件中将mybatis变更为mybatis-plus即可。
1.7 Controller及Service
package com.jt.controller;
import com.jt.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {
@Autowired
private ItemCatService itemCatService;
}
package com.jt.service;
import com.jt.mapper.ItemCatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ItemCatServiceImpll implements ItemCatService{
@Autowired
private ItemCatMapper itemCatMapper;
}
1.6 层级代码结构

2.商品分类页面跳转
说明: 编辑路由 index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import ElementUI from '../components/ElementUI.vue'
import Home from '../components/Home.vue'
import User from '../components/user/user.vue'
import ItemCat from '../components/items/ItemCat.vue'
//使用路由机制
Vue.use(VueRouter)
const routes = [
{path: '/', redirect: '/login'},
{path: '/login', component: Login},
{path: '/elementUI', component: ElementUI},
{path: '/home', component: Home, children: [
{path: '/user', component: User},
{path: '/itemCat', component: ItemCat}
]}
]
页面效果展现

1208




被折叠的 条评论
为什么被折叠?



