mybatis中传入String类型参数的问题
1. 出现的问题
需求是想写一个按公司名字查询公司列表的功能,最开始的代码如下
Dao层接口如下
@MyBatisDao
public interface OfficeDao extends TreeDao<Office> {
List<Office> findCompanyNameList(String name);
}
mybatis的xml代码:
<select id="findCompanyNameList" parameterType="java.lang.String" resultType="com.pds.modules.sys.entity.Office">
SELECT id,name FROM sys_office where o.del_flag = '1'
<if test="name!= null and name!= ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
这样写会报错,大体意思是name没有Getter方法。
2. 解决办法
2.1 解决办法1
在接口参数里加上mybatis中的@param注解
@MyBatisDao
public interface OfficeDao extends TreeDao<Office> {
List<Office> findCompanyNameList(@Param("name")String name);
}
<select id="findCompanyNameList" parameterType="java.lang.String" resultType="com.pds.modules.sys.entity.Office">
SELECT id,name FROM sys_office where o.del_flag = '1'
<if test="name!= null and name!= ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
2.2 解决办法2
在xml的if里用”_parameter” 代表参数
<select id="findCompanyNameList" parameterType="java.lang.String" resultType="com.pds.modules.sys.entity.Office">
SELECT id,name FROM sys_office where o.del_flag = '1'
<if test="_parameter!= null and _parameter!= ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
2.3 两种方法区别
可以看出,_parameter不能区分多个参数,而@param能。所以@param能传多个这样的参数
mybatis中传入String类型参数的问题的更多相关文章
- mybatis中传入String类型参数异常
在使用mybatis时,写了一条sql语句,只有一个String类型的参数, 示例代码 <select id="getApplyNum" parameterType=&quo ...
- MyBatis中传入参数parameterType类型详解
前言 Mybatis的Mapper文件中的select.insert.update.delete元素中有一个parameterType属性,用于对应的mapper接口方法接受的参数类型.本文主要给大家 ...
- foreach属性-动态-mybatis中使用map类型参数,其中key为列名,value为列值
http://zhangxiong0301.iteye.com/blog/2242723 最近有个需求,就是使用mybatis时,向mysql中插入数据,其参数为map类型,map里面的key为列名, ...
- (转载)mybatis中传入参数是list或map
原文地址:http://blog.csdn.net/aya19880214/article/details/41961235 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集 ...
- 关于mybatis中传入一个List,字符串数组,或者Map集合作为查询条件的参数
一.入参为List的写法: <select id="queryParamList" resultType="map" parameterType=&quo ...
- mybatis中传入一个List集合作为查询条件的参数
如果有一个查询参数有多个,用一个List集合传进去,这个mapper文件可以这么写 <select id="queryList04" resultType="map ...
- Mybatis中传入List条件
传入一个map的参数,map里有一个tenantIds的List,在xml里先判断这个List的size是否大于o,然后通过foreach 构造一个in后面括号里的元素,具体的xml如下: <i ...
- Mybatis中传入时间值
<if test="search_content2 != null and search_content2 != ''"> AND add_time <![CDA ...
- mybatis中的查询语句in用法的相关问题
在开发的时候,mybatisl中使用in的时候会遇到一些问题,如果我们传的参数是String类型,以“,”来进行隔开的,例如:参数是0,1,2字符串,mybatis中的语句如下 <select ...
随机推荐
- 移动端遮罩及阻止页面滑动,实用!!! 我们经常做一个fixed定位的遮罩和一个提示弹框,这时就要用到。记录--
document.body.style.height = '100%'; document.body.style.overflow = 'hidden'; document.getElementByI ...
- df -h hang 问题
此处仅截取原文中的解决方案,以便快速查找解决方法. 解决方法如下:1. systemctl restart proc-sys-fs-binfmt_misc.automount; 2. 升级到最新 sy ...
- django 第四天
简单的一对多的页面 实现的页面结果如下 利用正则匹配 1.x系列和2.x系列django的用法不同,....他x的. 关于正则匹配 我一直没能实现,再试试吧 路由分发,尤其是在多个页面的时候 app0 ...
- 金蝶k/3 K3密码对照破解源码
金蝶k/3 K3密码对照破解源码 通过密码对照表进行密码破解 以下是源码: VERSION 5.00 Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055 ...
- sql语法总结
1.创建表 . 创建时间 default current_imestamp(6) 更新时间 default current_timestamp(6) on update current_timest ...
- linux 添加ssh和开启ssh服务apt管理的ubuntu
是在ubuntu下出现的需求 现笔记记录 apt-get update 更新源命令 apt-get install openssh-server 安装ssh服务 容易出现无法定位软件包.出现此问 ...
- vue实现数据双向绑定的原理
一.知识准备Object.defineProperty( )方法可以直接在一个对象上定义一个新属性,或者修改一个已经存在的属性,并返回这个对象.Object.defineProperty(obj,pr ...
- [nodemon] clean exit - waiting for changes before restart
出现上述日志信息,程序就不能往下运行了. 原因:node程序在初始化的时候就报错了,仔细debug吧...
- 杭电1506 java
求最大子矩阵面积(dp) import java.util.*; public class Main1{ public static void main(String[] args) { Scanne ...
- CentOS下 SVN版本控制的安装(包括yum与非yum)的步骤记录。
一.yum安装 rpm -qa subversion //检查是否安装了低版本的SVN yum remove subversion //如果存储旧版本,卸载旧版本SVN 开始安装 yum -y ins ...