在采用mybatis-plus做代碼生成器時,我前面的文章https://blog.csdn.net/u012329294/article/details/90473681 講過,必須把其他的mybatis-plus刪掉,只留下mybatis-plus-boot-starter。
但用mybatis-plus-boot-starter生成的代碼,放在mybatis-plus依賴環境中,
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.0.6</version>
</dependency>
<!--generator時使用-->
<!--<dependency>-->
<!--<groupId>com.baomidou</groupId>-->
<!--<artifactId>mybatis-plus-boot-starter</artifactId>-->
<!--<version>2.2.0</version>-->
<!--</dependency>-->
總是報錯
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu May 23 14:54:08 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Invalid bound statement (not found): com.mrk.dx.system.dao.SkyUserDao.selectList
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mrk.dx.system.dao.SkyUserDao.selectList
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:232)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:50)
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)
at com.sun.proxy.$Proxy101.selectList(Unknown Source)
at com.baomidou.mybatisplus.service.impl.ServiceImpl.selectList(ServiceImpl.java:292)
at com.baomidou.mybatisplus.service.impl.ServiceImpl$$FastClassBySpringCGLIB$$3e2398a4.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
at com.mrk.dx.system.service.impl.SkyUserServiceImpl$$EnhancerBySpringCGLIB$$d0192f7b.selectList(<generated>)
這個報錯很有迷惑性,反復查找名字映射等都不行。
后來經過提醒才發覺,原來mybatis-plus并沒有自動生成那些命令。
即其中的selectList方法要自己來實現。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mrk.dx.system.dao.SkyUserDao">
<!-- 通用查詢映射結果 -->
<resultMap id="BaseResultMap" type="com.mrk.dx.system.entity.SkyUser">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="nickname" property="nickname" />
<result column="sex" property="sex" />
<result column="phone" property="phone" />
<result column="identifier" property="identifier" />
<result column="openid" property="openid" />
<result column="created_at" property="createdAt" />
<result column="updated_at" property="updatedAt" />
<result column="headimgurl" property="headimgurl" />
<result column="root_organization_ids" property="rootOrganizationIds" />
</resultMap>
<select id="selectList" resultMap="BaseResultMap"> select * from sky_user </select>
</mapper>
如上圖,加上紅色那一句后就可以了,這個耽誤了將近1天時間。
而在mybatis-plus-boot-starter中不需要寫,它已經完全自動實現了。
因此,mybatis-plus 和 mybatis-plus-boot-starter 的主要異同點就在于:
mybatis-plus-boot-starter將xml中basemap中定義的id全部已經實現了,
而mybatis-plus這個包還需要自己實現basemap中的定義。