Person.xml
<!-- 模糊查询 -->
<select id="findPersons" parameterClass="com.tq365.vo.Person" resultMap="person_result">
select * from t_person
<dynamic prepend="where">
<isNotEmpty prepend="and" property="personname">
personname like '%$personname$%'
</isNotEmpty>
<!--此为精确查询,模糊查询写成like '%$value$%',#XX#,#将其在sql中表现为'XX'
<isNotEmpty prepend="and" property="personname">
(personname like #personname#)
</isNotEmpty>
-->
<!--
<isNotEmpty prepend="AND" property="address">
(address like #address#)
</isNotEmpty>
-->
</dynamic>
</select>
PersonDao.java
/**
* 模糊查询,查询符合指定条件的所有Person对象
* @param person
* @return
*/
@SuppressWarnings("unchecked")
public List<Person> findPersons(Person person){
SqlMapClient sqlMapClient=SqlMapUtil.getSqlMapClient();
List<Person> personList=new ArrayList<Person>();
try {
sqlMapClient.startTransaction();
personList=sqlMapClient.queryForList("findPersons", person);
sqlMapClient.commitTransaction();
return personList;
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
sqlMapClient.endTransaction();
} catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}