遇到的mybatis报错与Mybatis参数(Parameters)传递

1.遇到的mybatis报错

(1)org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement ‘com.dao.UserDao.selectuser’. It’s likely that neither a Result Type nor a Result Map was specified.
(2)org.apache.ibatis.binding.BindingException: Mapper method 'com.dao.UserDao.selectuser attempted to return null from a method with a primitive return type (int).

上面两种报错的排查建议一下三个方面
(1),检查dao层与xml的全类名是否一致
(2),检查方法名与是否dao层是否一致
(3),返回类型是是否一致
我的错误带你在于select 语句没写resultType insert没有写parameterType

2.resultType 与 parameterType 的基本使用的区别

(1)、使用 resultType : 主要针对于从数据库中提取相应的数据出来
(2)、使用parameterType : 主要针对于 将信息存入到数据库中 如: insert 增加数据到数据库中 ,Update等

3.新增用户总是为空(我传的Map集合数据)

Mybatis参数(Parameters)传递的错误
(1) insert语句要parameterType
(2)赋值时直接写map的元素不用写map.属性
代码如下

		<!-- 新增用户 -->
		<insert id="insertuser" parameterType="java.util.Map" >
			insert   INTO t_user(openid,nickname,user_gender,user_isnew) VALUE (#{openid},#{nickname},#{user_gender},#{user_isnew});
		</insert>

ps:因为新增数据库总不成功,所有需要打印数据库的日志查看具体详情。
我使用的是application.properties配置文件,在里面加入如下配置:

logging.level.com.dao=debug

4.加上查询是否为新用户的代码后springboot启动报错:

映射文件的resultType写错了,String类型的只要写string就可以了

	<!--判断用户是否是新用户-->
	<select id="selectuser" resultType="string">
		   select  user_isnew  from  t_user where  openid=#{openid};
	   </select>

5.Mybatis其他类型的参数传递具体详情

包括单个参数,POJO,Map,多个参数,命名参数类型。
Mybatis参数传递

发布了45 篇原创文章 · 获赞 6 · 访问量 1190

猜你喜欢

转载自blog.csdn.net/qq_41219586/article/details/103473798