注解@Param有以下两种:

1、Spring
org.springframework.data.repository.query.Param
2、mybatis
org.apache.ibatis.annotations.Param

两者的区别在于:

spring的注解参数按照先后顺序传入,如[arg1, arg0, param1, param2]

mybatis的注解则是使用参数名传入,如{#userId}

注意

如果使用spring的注解,而xml的SQL使用参数名取值,会报下面的错:

        org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy128.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:158)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:76)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:62)
at com.sun.proxy.$Proxy187.queryEquipmentAndPositionByProjectId(Unknown Source)

使用@Param注解时注意org.springframework.data.repository.query.Param与org.apache.ibatis.annotations.Param的区别的更多相关文章

  1. import org.apache.ibatis.annotations.Param 报错

    说明缺少依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus ...

  2. Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.config.BootstrapMode

    1.起因,启动SpringBoot2.0的时候报了这个错误.说找不到类,咱也是刚学SpringBoot2.0,咱也不懂,咱也不知道问谁,研究一翻,找不到原因就百度了. 参考链接:https://blo ...

  3. org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;

    升级springboot到2.0时,碰到了一大堆问题,上面异常原因是jar版本冲突了,有的模块忘记更新版本了,统一一下版本就可以了

  4. Mybatis中的@Param注解(自己没试过)

    @Param是MyBatis所提供的(org.apache.ibatis.annotations.Param),作为Dao层的注解,作用是用于传递参数,从而可以与SQL中的的字段名相对应//https ...

  5. org.springframework.data.mapping.PropertyReferenceException: No property created found for type

    错误原因:org.springframework.data.domain.SortSort sort=new Sort(Sort.Direction.DESC,"created_time&q ...

  6. @Param注解

    关于mybatis的@Param注解和参数 引用 https://www.cnblogs.com/whisper527/p/6568028.html 薇飘意 1,使用@Param注解 当以下面的方式进 ...

  7. 关于mybatis的@Param注解和参数

    1,使用@Param注解 当以下面的方式进行写SQL语句时: @Select("select column from table where userid = #{userid} " ...

  8. @Param注解的用法解析

    实例一 @Param注解单一属性 dao层示例 Public User selectUser(@param(“userName”) String name,@param(“userpassword”) ...

  9. Mybatis中的@Param注解

    前言 今天在使用Mybatis时遇到一个问题,主要出错原因在于Mybatis的@Param注解,如果我不在参数前面加上@Param注解,数据库操作就会报错,如下: @Param作用 @Param注解的 ...

  10. 使用@Param注解

    1,使用@Param注解 当以下面的方式进行写SQL语句时: @Select("select column from table where userid = #{userid} " ...

随机推荐

  1. 搭建ubuntu开发环境

    tar -xzvf  VMwareTools-10.0.6-3595377.tar.gz cd  vmware-tools-distrib 再执行:sudo ./vmware-install.pl  ...

  2. layui多图片上传

    <div> <button type="button" class="layui-btn" id="mulUpload"& ...

  3. 浏览器打开微信小程序

    function h5() { $wx = new Wx('appId', 'appSecret'); // \dump($wx->getAccessToken()); $url = 'http ...

  4. C# 数据结构之嵌套加法、嵌套乘法

    复杂性度量问题 1.大O复杂度:嵌套加法 找出以下代码片段的 Big O 复杂度. using System; namespace Chapter_1 { class Challenge_1 { st ...

  5. pip python的包成功,但是import的时候报错

    今天,一位同学线上反馈import python包失败了,同时附带两张图: 图1.报错代码 图2.报错提示 结合上面两个图片,我们发现这个同学import全部失败,初步怀疑该同学的本地环境上没有num ...

  6. python实现web应用程序(1)虚拟环境与Django

    前言 在这个系列博客中,我将使用python实现一个名为"OI笔记"的项目. 1 建立项目目录 第一步,我们先为自己的项目建立一个目录. 首先,打开终端. win+r键,然后输入c ...

  7. 思科vlan简单配置

    实验拓扑 实验目标:2台交换机,4台pc,分别处于10,20vlan中可以跨交换机相互通信 tips:vlan是2层技术 可以配置在交换机上 实验ip PC2 10.1.1.2/24 PC1 10.1 ...

  8. vue项目运行出现warnings potentially fixable with the `--fix` option的报错问题

    vue-cil3 运行报错 warnings potentially fixable with the `--fix` option. 解决办法:"lint": "vue ...

  9. Retrofit简要分析

    Retrofit是对网络请求实现了一套请求架构封装,屏蔽底层网络实现,使网络请求像调用本地接口一样 基本使用例子 public interface GitHubService {//定义request ...

  10. localStorage/sessionStorage/cookie

    html5本地存储主要有两种localStorage和sessionStorage        都是使用相同api,存入后都是字符串类型 localStorage和sessionStorage使用方 ...