Mybatis like 模糊查询,有数据,但是就是查询不出来
来源:互联网 发布:js获取body元素 编辑:程序博客网 时间:2024/04/30 19:55
今天修改项目遇到的问题,mybatis模糊查询,有数据,就是查不出来。也不报错。
问题虽然最后搞定了,来总结下。
Mybatis配置如下: <select id="getAll" resultMap="OaEmplyeeInfoResultMap" parameterType="com.deppon.oa.module.oaEmplyeeInfo.domain.OaEmplyeeInfo"> <![CDATA[ SELECT ]]> <include refid="select_param" /> <![CDATA[ FROM OM_EMPLOYEE ]]> <where> <if test="empcode!=null"> AND EMPCODE = #{empcode} </if> <if test="empname!=null"> AND EMPNAME LIKE #{empname} </if> </where> </select>Dao层如下:public List<OaEmplyeeInfo> getAllByName(OaEmplyeeInfo oaEmplyeeInfo,String empname){ List<OaEmplyeeInfo> list=null; Map map=new HashMap(); map.put("empname", empname); list=(List<OaEmplyeeInfo>) getSqlSession().selectList("com.deppon.oa.module.oaEmplyeeInfo.domain.OaEmplyeeInfo.getAll", map); return list; }测试代码如下:public void testQuery(){ List<OaEmplyeeInfo> fos=null; fos = oaEmplyeeInfoDao.getAllByName(null,"王"); for(OaEmplyeeInfo li:fos){ System.out.println(li.getEmpname()); } Assert.assertNotNull(fos.get(0).getCardno()); }发现怎么都查不出来数据,最后查询资料才得知:原来Mybatis用like进行模糊查询的时候,配置与所用的数据库有关系,总结了下,具体如下:1、mysql :LIKE CONCAT('%',#{empname},'%' ) 或者 LIKE CONCAT('%',‘${empname}’,'%' )2、oracle:LIKE '%'||#{empname}||'%'我用的是oracle 把配置文件改为:<select id="getAll" resultMap="OaEmplyeeInfoResultMap" parameterType="com.deppon.oa.module.oaEmplyeeInfo.domain.OaEmplyeeInfo"> <![CDATA[ SELECT ]]> <include refid="select_param" /> <![CDATA[ FROM OM_EMPLOYEE ]]> <where> <if test="empcode!=null"> AND EMPCODE = #{empcode} </if> <if test="empname!=null"> AND EMPNAME LIKE '%'||#{empname}||'%' </if> </where> </select>
0 0
- Mybatis like 模糊查询,有数据,但是就是查询不出来
- Mybatis LIKE 模糊查询
- MyBatis 模糊查询 like %
- Mybatis like 模糊查询问题
- Mybatis like 模糊查询问题
- Mybatis的like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- MyBatis的like模糊查询
- mybatis like 模糊查询问题
- Mybatis中的模糊查询(like)
- mybatis做模糊查询 like
- mybatis做like模糊查询
- Mybatis中like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- mybatis做like模糊查询
- HTTP长连接 && keep-alive
- scrollview和listview的区别
- crontab 解锁
- 使用AutoLayout添加UIScrollView
- sql with as 用法
- Mybatis like 模糊查询,有数据,但是就是查询不出来
- quagga 安装详解以及相关问题解决
- Apache Shiro权限管理框架的初次认识
- 又学了几个emacs快捷键
- cookie中domain和path的解释
- 【转载】使用OpenCV的OpenCL(ocl)模块
- LeetCode -- Valid Sudoku
- 各种距离
- c++与java的区别