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类型参数的问题的更多相关文章

  1. mybatis中传入String类型参数异常

    在使用mybatis时,写了一条sql语句,只有一个String类型的参数, 示例代码 <select id="getApplyNum" parameterType=&quo ...

  2. MyBatis中传入参数parameterType类型详解

    前言 Mybatis的Mapper文件中的select.insert.update.delete元素中有一个parameterType属性,用于对应的mapper接口方法接受的参数类型.本文主要给大家 ...

  3. foreach属性-动态-mybatis中使用map类型参数,其中key为列名,value为列值

    http://zhangxiong0301.iteye.com/blog/2242723 最近有个需求,就是使用mybatis时,向mysql中插入数据,其参数为map类型,map里面的key为列名, ...

  4. (转载)mybatis中传入参数是list或map

    原文地址:http://blog.csdn.net/aya19880214/article/details/41961235 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集 ...

  5. 关于mybatis中传入一个List,字符串数组,或者Map集合作为查询条件的参数

    一.入参为List的写法: <select id="queryParamList" resultType="map" parameterType=&quo ...

  6. mybatis中传入一个List集合作为查询条件的参数

    如果有一个查询参数有多个,用一个List集合传进去,这个mapper文件可以这么写 <select id="queryList04" resultType="map ...

  7. Mybatis中传入List条件

    传入一个map的参数,map里有一个tenantIds的List,在xml里先判断这个List的size是否大于o,然后通过foreach 构造一个in后面括号里的元素,具体的xml如下: <i ...

  8. Mybatis中传入时间值

    <if test="search_content2 != null and search_content2 != ''"> AND add_time <![CDA ...

  9. mybatis中的查询语句in用法的相关问题

    在开发的时候,mybatisl中使用in的时候会遇到一些问题,如果我们传的参数是String类型,以“,”来进行隔开的,例如:参数是0,1,2字符串,mybatis中的语句如下 <select ...

随机推荐

  1. 《剑指offer》复杂链表的复制

    本题来自<剑指offer> 反转链表 题目: 思路: C++ Code: Python Code: 总结:

  2. 网络流24题——圆桌问题 luogu 3254

    题目传送门:这里 这是网络流24题里最简单的一道,我们从这里开始 虽然是网络流24题之一,但可以不用网络流... 本题采用贪心即可 有一个很显然的思想:在分配每一组时,我们都应当优先分配给当前可容纳人 ...

  3. Spring Boot Mybatis整合

    Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 特 ...

  4. BeanPostProcessors (for example: not eligible for auto-proxying),报错解决

    最近遇到个问题,springmvc项目debug启动失败 debug启动会卡住不动,run模式启动正常 debug启动输出到下面这行之后,就不会继续输出了 -- :: [INFO]- Bean 'da ...

  5. pandas导入导出数据-【老鱼学pandas】

    pandas可以读写如下格式的数据类型: 具体详见:http://pandas.pydata.org/pandas-docs/version/0.20/io.html 读取csv文件 我们准备了一个c ...

  6. 网络安全第一集之【SQL注入:sqlmap入门】

    1,安装sqlmap和python环境 2,对于环境变量超长问题 3,使用sqlmap: sqlmap.py -u "http://k2.hlxy.net/csdw/news1.asp?dp ...

  7. 【mybatis】-- springboot整合mybatis

    1.添加依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>m ...

  8. Android 调用 .NET WebService

    1.下载并导入jar工具类包 打开下载界面http://simpligility.github.io/ksoap2-android/getting-started.html ,拉倒最下 2.Copy ...

  9. python class属性

    代码一: class A(object): pass a = A() a.name = "class_A" print(a.name) #class_A 代码二:class A(o ...

  10. jQuery 对象 等操作

    /////////////////////下面为文件夹重命名功能区///////////////////////// $(".wpul .rename").click(functi ...