关于mybatis-plus 和 mybatis-plus-boot-starter 异同点分析

在采用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>-->

总是报错

  1. Whitelabel Error Page
  2. This application has no explicit mapping for /error, so you are seeing this as a fallback.
  3. Thu May 23 14:54:08 CST 2019
  4. There was an unexpected error (type=Internal Server Error, status=500).
  5. Invalid bound statement (not found): com.mrk.dx.system.dao.SkyUserDao.selectList
  6. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mrk.dx.system.dao.SkyUserDao.selectList
  7. at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:232)
  8. at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:50)
  9. at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62)
  10. at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
  11. at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62)
  12. at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)
  13. at com.sun.proxy.$Proxy101.selectList(Unknown Source)
  14. at com.baomidou.mybatisplus.service.impl.ServiceImpl.selectList(ServiceImpl.java:292)
  15. at com.baomidou.mybatisplus.service.impl.ServiceImpl$$FastClassBySpringCGLIB$$3e2398a4.invoke(<generated>)
  16. at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
  17. at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
  18. 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中的定义。

 

 

 

 

posted @ 2019-12-25 17:40  星朝  阅读(4555)  评论(0编辑  收藏  举报