mybatis-注意事项

 

<select id="actListPage" resultType="java.util.HashMap"> 
       select 
           act, 
           sum(e_num) eTotal,
           round(sum(e_time)/sum(e_num),2) avgTime
       from
           <if test="methodType == 'type1'">
		table_type1
           </if>
           <if test="methodType == 'type2'">
	       table_type2
           </if>
       <where>
           <if test="firstCon != null">
		        firstCon = #{firstCon}
		    </if>
		    <if test="secondCon!= null">
		        and secondCon = #{secondCon}
		    </if>
       </where>
       group by act
       order by avgTime desc
    </select>

 

public interface ActMapper {
    //分页,Page也放入到map中
    public Map<String, Object> actListPage(Map<String, Object> params);

    //下面的传值方式会报错,sql会无法注入’methodType‘等参数
    /*public Map<String, Object> actListPage(Map<String, Object> params, Page page);*/
   
     //要么全放到map里通过map传,要么在方法的形参上一一列出,以下方法也可为sql语句传参成功
     public Map<String, Object> actListPage(String methodType, Integer firstCon, Integer secondCon, Page page);
}

 

你可能感兴趣的:(mybatis-注意事项)