iBatis 的条件查询

时间:2022-01-08 23:48:34

之类以传入ID进行举例

Student.xml 在里面设置一个ID的标志位,设置类型

    <select id="selectAllStudentByid" parameterClass="int" resultClass="Student">
select * from
student
where Id=#id#
</select>

StudentImpl.java文件,这里将ID给传入进去,

    public List<Student> selStudentByid(int id) {
List<Student> student = null;
try {
student = sqlMapClient.queryForList("selectAllStudentByid",id);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return student;
}

Test.java测试页面

package cn.test.main;

import java.util.List;

import cn.test.domain.Student;
import cn.test.service.IStudent;
import cn.test.service.StudentImpl; public class Test { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
IStudent istudent2 = new StudentImpl();
List<Student> student2 = istudent2.selStudentByid(1);
System.out.printf("id="+student2.get(0).getId() + "name = " +student2.get(0).getName() + "age = " + student2.get(0).getAge()); } }