方法一:


<!--  根据hid,hanme,grade,模糊查询医院信息-->

方法一:
List<Hospital> getHospitalLike(@Param("selectword") String selectword);
<select id="getHospitalLike" resultType="com.hand.hand.domain.Hospital">
SELECT *
FROM hospital
where hid=cast(#{selectword} as signed INTEGER ) OR hname like concat('%',#{selectword},'%')
OR grade like concat('%',#{selectword},'%')
</select>

 where hid=cast(#{selectword} as signed INTEGER )  hid为Integer类型,而参数selectword为string类型,所以用cast将string转化为Integer
where hname like concat('%',#{selectword},'%') 字符串拼接,将%和selectword拼接成%selectword% 方法二:动态sql中的bind
List<Hospital> getHospitalLike(@Param("selectword") String selectword);
<select id="getHospitalLike" resultType="com.hand.hand.domain.Hospital">
<bind name="bindselectword" value="'%'+selectword+'%'"></bind>
SELECT *
FROM hospital
<if test="selectword!=null">
where hid=cast(#{selectword} as signed INTEGER ) OR hname like #{bindselectword}
OR grade like #{bindselectword}
</if> </select> 方法三:
在service层直接拼接字符串,xml直接使用转入的参数

 此方法测试出错(参考博客后,测试出错):
<!--where hid like '%'||#{selectword}||'%' or hname like '%'||#{selectword}||'%' or grade like '%'||#{selectword}||'%'-->

其他拼接法,可参考:https://www.cnblogs.com/dushan/p/4766954.html

mybatis中使用mysql的模糊查询字符串拼接(like)的更多相关文章

  1. 关于mybatis中sql映射文件模糊查询的使用

    1.从前台传递一个String类型的参数到后台进行查询,如果牵涉到模糊查询会报错,应该把参数封装到对象中再进行传递然后进行模糊查询 2.一个查询框,多个查询条件 <if test="c ...

  2. mybatis oracle和mysql like模糊查询写法

    oracle:RESOURCE_NAME LIKE '%' || #{resourceName} || '%'mysql:RESOURCE_NAME like concat(concat(" ...

  3. mybatis处理LIKE模糊查询字符串拼接

    -- 最佳实践 <select id="getSealByMap" parameterType="map" resultType="map&qu ...

  4. Mybatis使用MySQL进行模糊查询时输入中文检索不到结果

    Mybatis使用MySQL进行模糊查询时输入中文检索时,需要在jdbcURL后增加参数   ?useUnicode=true&characterEncoding=UTF-8

  5. Mybatis中动态SQL多条件查询

    Mybatis中动态SQL多条件查询 mybatis中用于实现动态SQL的元素有: if:用if实现条件的选择,用于定义where的字句的条件. choose(when otherwise)相当于Ja ...

  6. 对一个表中所有列数据模糊查询adoquery

    如何用adoquery对一个表中所有列进行模糊查询: procedure TForm3.Button4Click(Sender: TObject); var ASql,AKey: string; I: ...

  7. c#中如何使用到模糊查询

    c#中如何使用到模糊查询,先举个最简单实用的例子,可在vs控制台应用程序中输出: 定义实体类:  public class Student        {            public int ...

  8. mysql 实行模糊查询 一个输入值匹配多个字段和多个输入值匹配一个字段

    mysql 实行模糊查询  一个输入值匹配多个字段 MySQL单表多字段模糊查询可以通过下面这个SQL查询实现 为啥一定要150字以上  真的麻烦  还不让贴代码了 SELECT * FROM `ma ...

  9. Mybatis中多表联查,查询出来的字段出现重名,造成数据异常的解决方法!

    在做一对多出现的问题,引发的思考:当数据库表中,主表的主键id和明细表的中的字段名相同时怎么办?Mybatis进行自动映射赋值的时候会不会出现异常?                      注意:M ...

随机推荐

  1. Limits on Table Column Count and Row Size Databases and Tables Table Size 最大行数

    MySQL :: MySQL 8.0 Reference Manual :: C.10.4 Limits on Table Column Count and Row Size https://dev. ...

  2. Cookies and Caching Client Identification

    w HTTP The Definitive Guide 11.6.9 Cookies and Caching You have to be careful when caching documents ...

  3. Apache 2.4 配置多个虚拟主机的问题

    以前一直用Apache2.2的版本,最近升级到了2.4的版本,尝尝新版本嘛. 不过遇到了几个问题,一个就是配置了多个virtualhost,虽然没有报错,不过除了第一可以正常访问外,其他的都存在403 ...

  4. Python中的编码与解码(转)

    Python中的字符编码与解码困扰了我很久了,一直没有认真整理过,这次下静下心来整理了一下我对方面知识的理解. 文章中对有些知识没有做深入的探讨,一是我自己也没有去深入的了解,例如各种编码方案的实现方 ...

  5. VC2005 warning C4819 消除方法

    一. Warning C4819:The file contains a character that can ot be represented in the current code page(9 ...

  6. Tomcat启动慢但是不报错的解决办法

    参考文章:https://blog.csdn.net/xiaoxinyu316/article/details/39064003 可以查看下tomat的启动日志,看看有哪些比较耗时的操作: grep ...

  7. php微信支付回调验证

    //字典排序拼接字符串 function getWxPaySignature($arr){ ksort($arr); $str = ''; foreach ($arr as $k=>$a){ $ ...

  8. struts2.3+spring3.2+hibernate4.2例子

    有些教程比较老,可是版本更新不等人,基于马士兵老师小例子,自己重新引用了新的包,调试确实有点烦人,但是通过英文文档和google解决问题.官网的更新超快,struts2.3+spring3.2+hib ...

  9. 取得选中Grid的数据

    var MergeAction = new Ext.Action({ text: '合并(选中两行)', handler: function () { if (grid.getSelectionMod ...

  10. smart基础原理

    1html模板页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...