SpringBoot使用小笔记——MybatisPlus使用

使用说明:
相对来说使用比较方便,特性官方文档说的很详细了。基本的使用与mybatis没有任何差别。
集成到springboot的传送门 → http://mp.baomidou.com/#/spring-boot

常见问题:
1、使用MP只需要引入MP的依赖,不需要另外引入mybatis依赖。
2、空指针问题
新建项目使用ActiveRecord 方式CURD时出现下面报错

java.lang.NullPointerException
	at com.baomidou.mybatisplus.entity.GlobalConfiguration.currentSessionFactory(GlobalConfiguration.java:227)
	at com.baomidou.mybatisplus.mapper.SqlHelper.sqlSession(SqlHelper.java:101)
	at com.baomidou.mybatisplus.mapper.SqlHelper.sqlSession(SqlHelper.java:54)
	at com.baomidou.mybatisplus.activerecord.Model.sqlSession(Model.java:346)
	at com.baomidou.mybatisplus.activerecord.Model.insert(Model.java:53)
	...

解决方法:
新项目实体(model)直接maven引用的其他项目,并且对mybatisplus进行了配置。官方文档中描述:“AR模式提供了一种更加便捷的方式实现 CRUD 操作,其本质还是调用的 Mybatis 对应的方法,类似于语法糖。”所以需要补充mapper继承basemapper。
https://gitee.com/baomidou/mybatisplus-spring-mvc/issues/2

3、使用mybatis在xml中写sql,如下:

<select id="queryBgScFplx">
	select * from test
	where name = #{name}
	<if test="state != '1'">
              and age= #{age}
        </if> 
</select>

state为1时,发现执行后的age条件还是加上了
修改为下面情况正常:

<select id="queryBgScFplx">
	select * from test
	where name = #{name}
	<if test='state != "1"'>
              and age= #{age}
        </if> 
</select>

4、连接mysql8.0时driver报错,Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdb
修改连接数据库配置

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/xxx?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: ******

5、Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.G…
引入依赖:

<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-pool2</artifactId>
	<version>2.0</version>
</dependency>

6、org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='ew.paramNameValuePairs.MPGENVAL4', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
	at com.sun.proxy.$Proxy139.selectOne(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
	at com.sun.proxy.$Proxy154.selectCount(Unknown Source)

解决:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SpringBoot项目实战笔记可以按照以下步骤进行: 1. 首先,你可以通过观看B站上的教程视频来学习SpringBoot项目实战。在视频中,你可以学习到如何使用SpringBootMyBatis和MySQL创建一个电脑商城项目。 2. 确保你的SpringBoot项目能够成功启动。找到被@SpringBootApplication注解修饰的入口启动类,并运行该类。如果你能够观察到图形化的界面,那么说明你的项目成功启动了。 3. 如果你还没有创建SpringBoot项目,你可以使用Spring Initializr来初始化一个新的项目。Spring Initializr是一个Web应用程序,可以为你生成Spring Boot项目的基本结构。你可以选择使用Maven或Gradle作为构建工具,并添加适合你的项目的依赖。然后,你只需要编写应用程序的代码即可。 希望以上信息对你有帮助!如果还有其他问题,请随时提问。123 #### 引用[.reference_title] - *1* *2* [SpringBoot项目实战笔记:电脑商城项目实战(SpringBoot+MyBatis+MySQL)](https://blog.csdn.net/weixin_44260350/article/details/127746667)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [《SpringBoot实战》读书笔记](https://blog.csdn.net/sanhewuyang/article/details/104494202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值