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]

 

相关文章:

  • 2021-11-18
  • 2021-12-10
  • 2021-11-18
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2021-12-18
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案