1. 程式人生 > 實用技巧 >Mybatis查詢sql傳入一個字串傳引數,報There is no getter for property named 'ids' in 'class java.lang.String'。

Mybatis查詢sql傳入一個字串傳引數,報There is no getter for property named 'ids' in 'class java.lang.String'。

Mybatis查詢sql傳入一個字串傳引數,報There is no getter for property named 'ids' in 'class java.lang.String'。

解決方法:

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.在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>

  或無論引數名是啥,都要改成"_parameter"

 <select id="findByName" parameterType="string" resultType="com.domain.entity.FactoryEntity">
     SELECT * FROM T_FACTORY WHERE F_NAME LIKE "%${_parameter}%"
    </select>

兩種方法區別

可以看出,_parameter不能區分多個引數,而@param能。所以@param能傳多個這樣的引數

3.將String引數放入Map集合中

Map map=new HashMap();
        map.put("condition",condition);

        List list=bookMapper.bookList(map);
<select id="bookList" parameterType="map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from book
    <if test="condition!= null">
      where bname like '%${condition}%' or author like '%${condition}%'
    </if>
  </select>

參照:

https://blog.csdn.net/zcl_love_wx/article/details/78601481

https://www.cnblogs.com/xmzJava/p/7245574.html