myBatis一些问题
一、mapper:
MyselfSatisfactionPage getGoodInfo(String coachId, String month);
xml:
<select id="getGoodInfo" parameterType="string" resultMap="coachMap">
SELECT
round((t1.good_evalute_num / t1.total_evalute_num) * 100,1) as level, '' as dsf
FROM sm_coach_month_evaluate t1 WHERE t1.coach_id = #{coachId} AND t1.month =#{month}
</select>
会报:
Parameter 'coachId' not found. Available parameters are [1, 0, param1, param2]
多个参数传入不能识别,需要用#{0},#{1}。也可以用parameterMap
如果是<if text='_parameter.get("0") == 1'></if>
二、resultType 用映射工具将字段和实体字段对应,返回时有_的字段依旧没有值。
通过resultMap来建立对应关系 resultType无法将查询结果映射到pojo对象的pojo属性中
三、insert返回主键值
<insert id="addSmLeaveRecord" parameterType="smLeaveRecord" useGeneratedKeys="true" keyProperty="id">
insert into sm_leave_record(created_by,created_date,apply_employee_id,apply_time,leave_type,reason,start_time,end_time,time_size,type,result)
values(#{createdBy},#{createdDate},#{applyEmployeeId},#{applyTime},#{leaveType},#{reason},#{startTime},#{endTime},#{timeSize},#{type},#{result})
</insert>
useGeneratedKeys="true" keyProperty="id"
执行完sql 实体中就有id值(主键)
而这个sql返回是插入的条数
四、Caused by: java.lang.NumberFormatException: For input string: "M"
mybatis中if标签 <if test="type=='M'">
这里 'M' 将被认为是 char 类型
type是string类型所以报错
改成 <if test='type=="M"'>
五、mybatis总是报
#{0}
Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
网上找只是说mybatis高版本不支持这个方式。我这边是本地3.4.2没有问题,部署到环境上也是3.4.2就是报这个错误