01_7_模糊查询实体对象
1. 配置映射文件
<select id="selectStudentByName" parameterClass="String" resultClass="Student">
select * from Student where name like '%$name$%'
</select>
2. 实现类的方法
public List<Student> queryStudentByName(String name) {
List<Student> studentList = null;
try {
studentList = sqlMapClient.queryForList("selectStudentByName", name);
} catch (SQLException e) {
e.printStackTrace();
}
return studentList;
}
3. 测试
public static void main(String[] args) {
IStudentDAO dao = new IStudentDAOImpl();
for(Student stu : dao.queryAllStudent()) {
System.out.println(stu);
}
//名字包含"子"的名字
System.out.println("###################");
for(Student stu : dao.queryStudentByName("子")) {
System.out.println(stu);
}
}
[sid:1, name:李明, major:语文, birth:Tue Mar 27 00:00:00 CST 2018, score:100.0]
[sid:2, name:可可, major:英语, birth:Mon Mar 12 00:00:00 CST 2018, score:120.0]
[sid:3, name:子浩, major:数学, birth:Thu Jan 25 00:00:00 CST 2018, score:100.0]
###################
[sid:3, name:子浩, major:数学, birth:Thu Jan 25 00:00:00 CST 2018, score:100.0]