mybatis表单查询
查询条件多个:
- 创建查询类
public class UserinfoCondition {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
private Integer age;
}
2、设置别名 mybatis.xml
<!-- 配置实体类的别名 如果不配置 则**Mapper.xml文件中 <select id="findUserList" resultType="User"> resultType需要加完整的包名 -->
<typeAliases>
<typeAlias type="com.test.bean.Userinfo" alias="Userinfo"/>
<typeAlias type="com.test.condition.UserinfoCondition" alias="UserinfoCondition"/>
<!-- <package name="com.atguigu.day03_mybaits.bean"/> -->
</typeAliases>
3、UserinfoMapper中定义方法
<!-- 根据名字和年龄查询学生 -->
<select id="findUserByNameAndAge" parameterType="UserinfoCondition" resultType="Userinfo">
select uid,name ,age from userinfo where name=#{name} and age=#{age}
</select>