标签:条件查询 ram set return vat birt rda username 实体类
package chen.domain;
import java.io.Serializable;
import java.util.Date;
public class User implements Serializable {
private Integer id;
private String username;
private Date birthday;
private String sex;
private String address;
//以下省略get set方法
}
package chen.domain;
//User实体类在chen.domanin包下
public class QueryVo {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
此处传递的参数parameterType是QueryVo实体类,但是查询语句需要的是User对象里面的username,我们可以用Query里面的user对象直接用到username,此处用到的是OGNL语法。
<select id="findUserByVo" parameterType="chen.domain.QueryVo" resultType="chen.domain.User">
select * from user where username like #{user.username}
</select>
/**
*根据QUERYVO中的条件查询用户
* @return
*/
List<User> findUserByVo(QueryVo vo);
/**
* 测试使用QueryVo作为查询条件
*/
@Test
public void testfindUserByVo(){
QueryVo Vo=new QueryVo();
User user=new User();
Vo.setUser(user);
user.setUsername("李%");
//执行查找方法
List<User> users= userDao.findUserByVo(Vo);
for (User u:users) {
System.out.println(u);
}
}
运行结果
User{id=6, username=‘李智‘, birthday=Mon May 25 21:41:51 CST 2020, sex=‘男‘, address=‘宝鸡‘}
User{id=9, username=‘李四‘, birthday=Tue May 26 21:26:01 CST 2020, sex=‘男‘, address=‘钓鱼‘}
User{id=10, username=‘李四‘, birthday=Mon Jun 22 22:12:58 CST 2020, sex=‘男‘, address=‘钓鱼‘}
标签:条件查询 ram set return vat birt rda username 实体类
原文地址:https://www.cnblogs.com/chenguosong/p/13185370.html