- 步骤一:修改父工程ruoyi-vue的pom文件,将pagehelper版本号改为1.2.3
- 步骤二:修改ruoyi-common工程pom文件,在pagehelper中排除mybatis和mybatis-spring jar坐标
- 步骤三:引入mybatis-plus jar坐标
com.baomidou mybatis-plus-boot-starter 3.1.0com.baomidou mybatis-plus-boot-starter3.1.0
- 步骤四:修改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
- 步骤五:将ruoyi-framework工程中的MyBatisConfig类的@Configuration注释掉或者直接删除该类
- 步骤六:修改ruoyi-system工程的SysNoticeMapper接口,使其继承baseMapper
- 步骤七:修改ruoyi-system的SysNoticeServiceImpl,使其继承ServiceImpl
- 步骤八:在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); } }
- 步骤九:执行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 Mapparams;属性,该属性不是数据库对应的字段,所以在在执行inser方法时应该排除该字段
- 步骤十:重新执行insert方法,发现数据可以正常插入,至此ruoyi-vue集成mybatis-plus已经完成
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)