要进行判断会有多个条件一般传入多对参数的方法如下
一、传入指定的多个参数
在接口类中的参数前面加个@Param(“xxx”),xxx就是指定mapper的xml文件能够识别的参数名
List<Employee> findByIdAndLastName(@Param("id") int id,@Param("lastName") String lastName);
<select id="findByIdAndLastName" resultType="employee">
select * from tbl_employee where id=#{id} and last_name=#{lastName}
</select>
二、传入实体类型
直接在调用接口类的方法中传入实体类型,取出实体类型的属性值即可
实体类型如下
public class Employee {
private Integer id;
private String lastName;
private String email;
private String gender;
}
<select id="findByIdAndLastName" resultType="employee" parameterType="employee">
select * from tbl_employee where id=#{id} and last_name=#{lastName}
</select>
三、传入Map
Map<String,Object>map=new HashMap<>();
map.put("id",1);
map.put("lastName","asda");
<select id="findByIdAndLastName" resultType="employee">
select * from tbl_employee where id=#{id} and last_name=#{lastName}
</select>
注意:本人已经在核心配置文件中作以下处理
<typeAliases>
<typeAlias type="com.cch.domain.Employee" alias="employee"/>
</typeAliases>
版权声明:本文为weixin_45876044原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。