T_Mustang
「已注销」
2019-04-18 10:19

任意字段的模糊查询怎么设置参数?

  • java
  • mysql
  • intellij-idea
  • java-ee

1.请问field1和field2这两个字段应该怎么设置?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mustang.mapper.SpecilMapper">

    <resultMap id="myMap" type="com.mustang.po.Specil">
        <id property="sid" column="spilinfoid"/>
        <result property="did" column="depinfoid"/>
        <result property="sCode" column="spilinfocode"/>
        <result property="sName" column="spilinfoname"/>
        <result property="sAim" column="spilinfoaim"/>
        <result property="sProdire" column="spilinfoprodire"/>
    </resultMap>


    <select id="queryLikeAndPageAndSort" parameterType="java.util.Map" resultMap="myMap" >
        SELECT * from specilinfo
        where spilinfoname like concat('%',#{value},'%')
        ORDER BY spilinfoid DESC
        limit #{start},#{pageSize}
    </select>
</mapper>

报错:

图片说明

将field1和field修改为具体的字段名后

<select id="queryLikeAndPageAndSort" parameterType="java.util.Map" resultMap="myMap" >
        SELECT * from specilinfo
        where spilinfoname like concat('%',#{value},'%')
        ORDER BY spilinfoid DESC
        limit #{start},#{pageSize}
    </select>

结果如下:

图片说明

测试类:

图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答