栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Ruoyi-Vue集成mybatis-plus实践

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Ruoyi-Vue集成mybatis-plus实践

版本说明:pageHelper版本为1.2.3、mybatis-plus版本为3.1.0
  1. 步骤一:修改父工程ruoyi-vue的pom文件,将pagehelper版本号改为1.2.3
  2. 步骤二:修改ruoyi-common工程pom文件,在pagehelper中排除mybatis和mybatis-spring jar坐标
  3. 步骤三:引入mybatis-plus jar坐标
        com.baomidou
        mybatis-plus-boot-starter
        3.1.0
    
com.baomidou mybatis-plus-boot-starter 3.1.0
  1. 步骤四:修改ruoyi-admin工程中application.yml配置文件,将mybatis相关的配置注释点,添加mybatis-plus配置
mybatis-plus:
  type-aliases-package: com.ruoyi.**.domain
  mapper-locations: classpath*:mapper*Mapper.xml
  config-location: classpath:mybatis/mybatis-config.xml
  1. 步骤五:将ruoyi-framework工程中的MyBatisConfig类的@Configuration注释掉或者直接删除该类
  2. 步骤六:修改ruoyi-system工程的SysNoticeMapper接口,使其继承baseMapper
  3. 步骤七:修改ruoyi-system的SysNoticeServiceImpl,使其继承ServiceImpl
  4. 步骤八:在ruoyi-admin工程中编写测试类
package com.yf.cn;

import com.ruoyi.RuoYiApplication;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.mapper.SysNoticeMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@SpringBootTest(classes = RuoYiApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class TestMp {

    @Autowired
    private SysNoticeMapper sysNoticeMapper;
    @Test
    public void testInsert(){
        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeTitle("我是一只小毛驴");
        sysNotice.setNoticeType("1");
        sysNoticeMapper.insert(sysNotice);
    }
}

  1. 步骤九:执行testInsert方法,发现报错:Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘params’. It was either not specified and/or could not be found for the javaType (java.util.Map) : jdbcType (null) combination.
    经仔细查看发现 SysNotice 实体类集成了baseEntity,baseEntity中有一个 private Map params;属性,该属性不是数据库对应的字段,所以在在执行inser方法时应该排除该字段
  2. 步骤十:重新执行insert方法,发现数据可以正常插入,至此ruoyi-vue集成mybatis-plus已经完成
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/693073.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号