記錄一下這個錯誤。
報錯原因:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'pd.goods_name!= null and pd.goods_name!= '''. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "goods_name")
分析:
由於項目框架里有個將map封裝成PageData,我通過new PageData ,將前端jsp傳到controller的參數進行保存。不過沒有再做pd.put("goods_name",pd.getString("goods_name"));處理,而此時maping.xml里就不能在用pd獲取了。(它會直接用它封裝的方法,return 一個map)
錯誤寫法:
<if test="pd.goods_name!= null and pd.goods_name!= ''"> and goods_name like concat('%', #{pd.goods_name},'%') </if>
把pd.去掉即可。
<if test="goods_name!= null and goods_name!= ''"> and goods_name like concat('%', #{goods_name},'%') </if>
