1. 程式人生 > >Mybatis 報錯 There is no getter for property named '***' in 'class java.lang.String'

Mybatis 報錯 There is no getter for property named '***' in 'class java.lang.String'

sql 使用 mybatis and 參數 when choose orcal get

在mapper.xml中 , 如果單參數是String類型 , 且在sql語句中對參數進行了判斷 , 如下 when 中的判斷 , 如果出現 if 判斷也是一樣的。都需要把判斷中的參數用 _parameter 來代替 ,。

另外orcal中判斷字段是否為空需要使用 is null , 同理,判斷不為空使用 is not null 。

錯誤查詢:

<select id = "select"  resultMap="ResultMap" parameterType="String">
select
name,code,parent,level
from
table
<where>
<choose>
<when test="code != null and code !=‘‘">
and code = #{code}
</when>
<otherwise>
and code is null
</otherwise>
</choose>
</where>
</select>

正確查詢:


<select id = "select" resultMap="ResultMap" parameterType="String">
select
name,code,parent,level
from
table
<where>
<choose>
<when test="_parameter !=null and _parameter !=‘‘">
and code = #{code}
</when>
<otherwise>
and code is null
</otherwise>
</choose>
</where>
</select>

Mybatis 報錯 There is no getter for property named '***' in 'class java.lang.String'