mybatis中传入String类型参数的问题
来源:互联网 发布:体体育训练软件 编辑:程序博客网 时间:2024/05/20 11:28
1. 出现的问题
需求是想写一个按公司名字查询公司列表的功能,最开始的代码如下
Dao层接口如下:
@MyBatisDaopublic 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注解
@MyBatisDaopublic 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能传多个这样的参数
阅读全文
1 0
- mybatis中传入String类型参数的问题
- mybatis中传入String类型参数异常
- 对于mybatis传入string类型的参数
- mybatis 传入String 类型的参数
- mybatis 中parametertype的传入参数问题
- MyBatis: SQL语句中传入单个String类型的参数的获取
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis传入参数的问题
- MyBatis的传入参数parameterType类型
- MyBatis的传入参数parameterType类型
- MyBatis的传入和返回参数类型
- MyBatis的传入参数parameterType类型
- MyBatis的传入参数parameterType类型
- MyBatis的传入参数parameterType类型
- mybatis传入List参数或者单个String 参数等问题
- Oracle的表空间
- 创建、修改、删除Oracle表空间
- Qt 实现多级菜单
- 认识Oracle表
- 调试存储过程
- mybatis中传入String类型参数的问题
- 使用cvSmooth()函数以五种方式平滑图像
- markdown编辑数学公式
- openstack学习记录(一) horizon二次开发部署(juno)
- 如何删除Oracle表中的数据
- css3 彩虹文字解答
- Oracle管理表
- bzoj 2724: [Violet 6]蒲公英(分块预处理)
- 文本居中方式总结