mapper映射文件,输入参数总结:
所有的输入参数都可以省略parameterType
1.对于单一参数,mybatis不做任何特殊处理,直接在sql里面引入即可。
2.对于多参数问题,mybatis 会做出特殊处理
a. 如果参数不超过5个,使用@Param注解的形式指定,在sql里面填写param括号里面指定的值
b.如果参数很多:
1) 使用mybatis的特殊处理,对于普通参数列表,使用param1,param2,...,paramn 来指定
2) 对于单一的list<>类型,如果要指定内部下标,使用list[0] 的形式 Array类型使用 array[0]
3) 要处理的参数和业务参数一致的情况,使用javabean
4) 不一致又经常使用的情况使用新建一个映射类
public Employee selectEmployee(int id);
public Employee selectEmployee2(@Param("id")int id,String name);
public Employee selectEmployee3(List<Integer> ids);
public Employee selectEmployee4(List<Integer> ids,String name);
public Employee selectEmployee5(Map<String,Object> map);
对应的sql语句:
<select id="selectEmployee" resultType="com.anlysqx.entity.Employee">
select * from employee where id = #{param1};
</select>
<select id="selectEmployee2" resultType="com.anlysqx.entity.Employee">
select * from employee where id = #{id} and ename = #{arg1};
</select>
<select id="selectEmployee3" resultType="com.anlysqx.entity.Employee">
select * from employee where id = #{list[0]};
</select>
<select id="selectEmployee4" resultType="com.anlysqx.entity.Employee">
select * from employee where id = #{param1[0]} and ename = #{param2}
</select>
<select id="selectEmployee5" resultType="com.anlysqx.entity.Employee">
select * from employee where id = #{id} and ename =#{name};
</select>