之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用。在我们前台查询的时候会有许多的条件传过来:先看个例子:

public List<Contact> searchByExample(Contact contact) {
        System.out.println("searchByExampleContact");
        ContactExample example = new ContactExample();
        ContactExample.Criteria cri = example.createCriteria();
        if (this.objectAttrNullCheck(contact, "username"))
            cri.andUsernameEqualTo(contact.getUsername());
        if (this.objectAttrNullCheck(contact, "password"))
            cri.andPasswordEqualTo(contact.getPassword());
        ContactMapper vcontactMapper = sqlSession
                .getMapper(ContactMapper.class);
        List<Contact> returnList = vcontactMapper.selectByExample(example);
        return returnList;
}
09-30 13:48