1.用mybatis查询时,传入一个字符串传参数,且进行判断时,会报异常
2.mapper.xml 中id值有重复的(出现原因:拷贝上面的实现,修改下参数或SQL,忘记ID值唯一的修改了)
There is no getter for property named 'moduleCode' in 'class java.lang.String
1.错误写法:
<select id="queryAllParentModule" resultType="jobModule" prameterType="jobModule"> select modulecode,modulename,modulevalue,linkurl,rank, parentmodule=isnull(parentmodule,1),moduledescription from job_module <where> <choose> <when test="moduleCode!=null and moduleCode!=''">modulecode = #{moduleCode} </when> </choose> </where> </select>
需要修改成:
<select id="queryModuleByCode" resultType="jobModule" parameterType="string"> select modulecode, modulename,modulevalue,linkurl, rank,parentmodule=isnull(parentmodule,1),moduledescription from job_module <where> <choose> <when test="_parameter!=null and _parameter!=''">modulecode = #{_parameter}</when> </choose> </where> </select>
总结:不管你的参数是什么,都要改成"_parameter"
原文地址: http://txin0814.iteye.com/blog/1533645
参考文献: http://blog.csdn.net/noku_ln10/article/details/7977976
2.改写parameter_type为 map
接口:
public List<Long> viewUidsLikeName(Map<String, Object> params);
Mapper.xml
<select id="viewUidsLikeName" resultType="java.lang.Long" parameterType="java.util.Map"> SELECT id FROM usr_users where 1=1 <if test="username != null"> and username like concat ('%','${username}','%') </if> <if test="email != null"> and email like concat ('%','${email}','%') </if> </select>
注意:
1.parameterType="java.util.Map" Map为大写,若写成map会报错
2.或直接写成map
调用:
public List<Long> selectUidsByUsername(String username) { if(StringUtil.isBlank(username)){ return null ; } Map<String, Object> params = new HashMap<String, Object>(); if(UserUtils.isEmailAdress(username)){ params.put("email", username); }else{ params.put("username", username); } return userMapper.viewUidsLikeName(params); }
3.若封装在工具类中需要引用
<select id="selectscheduleTrackingsListPage" resultMap="BaseResultMap" parameterType="mybatis.utility.PageBean"> SELECT <include refid="Base_Column_List" /> from usr_merchant_schedule_tracking where 1 = 1 <if test="parameter.startTime != null and parameter.startTime !=''"> and date_format(create_time,'%Y-%m-%d') >= date_format(#{parameter.startTime},'%Y-%m-%d') </if> <if test="parameter.endTime != null and parameter.endTime !=''"> <![CDATA[ and date_format(create_time,'%Y-%m-%d') <= date_format(#{parameter.endTime},'%Y-%m-%d') ]]> </if> <if test="parameter.merchantid != null and parameter.merchantid !=''"> and merchantid = #{parameter.merchantid,jdbcType=VARCHAR} </if> </select>
注意:
merchantid = #{parameter.merchantid,jdbcType=VARCHAR},若为
merchantid = #{merchantid,jdbcType=VARCHAR},就会出现上面的错误