java-mybatis

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>

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值