spring中@param和mybatis中@param使用差别
spring中@param
/**
* 查询指定用户和企业关联有没有配置角色
* @param businessId memberId
* @return
*/
int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId") Long memberId);
mybatis中的param
/**
* 查询指定用户和企业关联有没有配置角色
* @param businessId memberId
* @return
*/
int selectRoleCount(@Param("businessId") Integer businessId,@Param("memberId") Long memberId);
从表面上看,两种并没有差别,可是在xml文件里使用的时候是有差别的。Spring中的@param在xml须要例如以下这样引用变量
<select id="selectRoleCount" resultType="java.lang.Integer" >
select
count(tbm.id)
from t_business_member_relation tbm
where tbm.business_id = #{0,jdbcType=INTEGER}
and tbm.member_id = #{1,jdbcType=INTEGER}
and tbm.role_business_id is not null
</select>
是依据參数的顺序来取值的,而且从0開始。而在mybatis @param在xml中则是例如以下这样引用变量的
<select id="selectRoleCount" resultType="java.lang.Integer" >
select
count(tbm.id)
from t_business_member_relation tbm
where tbm.business_id = #{businessId,jdbcType=INTEGER}
and tbm.member_id = #{memberId,jdbcType=INTEGER}
and tbm.role_business_id is not null
</select>
是通过參数名来引用的
注:假设Mapper.java文件里引用的是Spring的
org.springframework.data.repository.query.Param;
可是Mapper.xml中使用的是mybatis 的使用方法,那么就会例如以下的错误
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'businessId' not found. Available parameters are [1, 0, param1, param2]
截图例如以下
所以在使用的时候一定要注意@param引用和使用的一致性
spring中@param和mybatis中@param使用差别的更多相关文章
- spring中@param和mybatis中@param使用区别
spring中@param /** * 查询指定用户和企业关联有没有配置角色 * @param businessId memberId * @return */ int selectRoleCount ...
- spring中@Param和mybatis中@Param使用区别(暂时还没接触)
1.spring中@Param(org.springframework.data.repository.query.Param) int selectRoleCount(@Param("bu ...
- eclipse中hibernate和mybatis中xml配置文件的没有标签提醒解决方法
当我们使用eclipse编写Mybatis或hibernate的xml文件时,面对众多标签的配置文件,却没有自动提醒,对于工作和学习都十分不方便. 之所以没有自动提醒,是因为dtd文件没有加载成功. ...
- 解决IDEA中springboot整合mybatis中出现的Invalid bound statement(not found)的问题【转】
感谢原博主,原文链接 : https://blog.csdn.net/benben513624/article/details/81076182 最近学习springboot的开发,中间磕磕碰碰也是遇 ...
- [入坑系列] Mybatis 中$与#的区别
1.理解 1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端把id值1,传入到后台的时候,就相当于 sel ...
- 关于Mybatis的@Param注解 及 mybatis Mapper中各种传递参数的方法
原文:https://blog.csdn.net/mrqiang9001/article/details/79520436 关于Mybatis的@Param注解 Mybatis 作为一个轻量级的数 ...
- MyBatis 中 @Param 注解的四种使用场景,最后一种经常被人忽略!
有一些小伙伴觉得 MyBatis 只有方法中存在多个参数的时候,才需要添加 @Param 注解,其实这个理解是不准确的.即使 MyBatis 方法只有一个参数,也可能会用到 @Param 注解. 但是 ...
- mybatis中@Param的用法和作用
用注解来简化xml配置的时候,@Param注解的作用是给参数命名,参数命名后就能根据名字得到参数值,正确的将参数传入sql语句中 我们先来看Mapper接口中的@Select方法 package Ma ...
- Mybatis中的@Param注解
前言 今天在使用Mybatis时遇到一个问题,主要出错原因在于Mybatis的@Param注解,如果我不在参数前面加上@Param注解,数据库操作就会报错,如下: @Param作用 @Param注解的 ...
随机推荐
- 作死遇到的坑--view向下偏移
好大一个坑.--谈谈view偏移问题: 先上张图, 图中白色部分.上面的是从网上找的资源.将导航栏隐藏之后用collectionView加上去而实现的滑动标签功能.开始以为是代码中的问题.然后仔细推敲 ...
- Delete characters
Description In this exercise, you will get two strings A and B in each test group and the length of ...
- 禁用 WebView 放大镜及拷贝粘贴弹出框
文/KyXu(简书作者)原文链接:http://www.jianshu.com/p/40048d9c979a著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 背景:当你的App中有 We ...
- GET和POST有什么区别?
前几天有人问我这个问题.我说GET是用于获取数据的,POST,一般用于将数据发给服务器之用. 这个答案好像并不是他想要的.于是他继续追问有没有别的区别?我说这就是个名字而已,如果服务器支持,他完全可以 ...
- Asp.Net Web API 2第三课——.NET客户端调用Web API
详情请查看http://aehyok.com/Blog/Detail/70.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- Silverlight动态载入调用XAML资源
以多语言为例子: ResourceDictionary resourceDictionary = new ResourceDictionary(); //新建资源集合 var culture = ...
- nginx location模块--匹配规则
Location语法语法:location [=|~|~*|^~] /uri/ { … } = --> 开头表示精确匹配 ^~ --> 开头表示uri以某个常规字符串开头,理解为匹配url ...
- ueditor编辑器和at.js集成
源码: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&qu ...
- Why we need model on Django ?
step01: create a database name as (django_db) on mysql ... step02: configure your django to use the ...
- atitit. orm mapping cfg 映射配置(3)-------hbnt one2maney cfg
atitit. orm mapping cfg 映射配置(3)-------hbnt one2maney cfg 1. 建立list 1 2. 配置xml 1 3. Hibernate中Set和L ...