ibatis学习笔记-查询所有对象
来源:互联网 发布:做美食经验知乎 编辑:程序博客网 时间:2024/06/07 11:13
辅助类有一个要求,保证有一个无参的构造方法(无论是ibatis还是hi****,不然可能会出问题)。
CRUD
借助SqlMapClient中的方法:
queryForObject
queryForList
insert
delete
update
Student.xml的配置
<sqlMap> <!-- 通过typeAlias使得我们在下面使用Student实体类的时候不需要写包名 --> <typeAlias alias="Student" type="com.nitlib.check.entity.Student" /> <!-- 这样以后改了sql,就不需要去改java代码了 --> <!-- id表示select里的sql语句,resultClass表示返回结果的类型 --> <select id="selectAllStudent" resultClass="Student"> select * from Student</select> <select id = "selectStudentById" parameterClass="int" resultClass="Student">select * form Student where studentid=#studentid# </select></sqlMap>
读取配置
private static SqlMapClient sqlMapClient = null;// 读取配置文件 static { try { Reader reader = Resources .getResourceAsReader("com/nitlib/check/SqlMapConfig.xml"); sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { e.printStackTrace(); } }
基本的CRUD操作
查询
public List<Student> queryAllStudent() {// TODO Auto-generated method stubList<Student> studentList = null;try {studentList = sqlMapClient.queryForList("selectAllStudent");} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return studentList;}
测试
public static void main(String args[]){IStudentDAO dao = new IStudentDAOImpl();for(Student student:dao.queryAllStudent()){System.out.println(student);}}
模糊查询
自动主键selectKey
优点
思考使用ibatis的好处
0 0
- ibatis学习笔记-查询所有对象
- ibatis学习笔记-模糊查询实体对象
- ibatis学习笔记-插入一个实体对象
- ibatis学习笔记-修改实体对象
- ibatis自学笔记-查询指定id的单个对象
- ibatis教程_查询所有的对象(对student进行增删改查)
- IBatis.Net学习笔记五--常用的查询方式
- IBatis.Net学习笔记六--再谈查询
- ibatis学习笔记-删除指定id的当个对象
- ibatis 学习笔记
- IBatis.Net学习笔记
- iBatis 学习笔记
- ibatis学习笔记
- iBatis学习笔记
- iBATIS学习笔记(一)
- iBatis学习笔记
- ibatis 学习笔记 3
- ibatis 学习笔记 4
- 【C++】链表学习
- zoj 3626 Treasure Hunt I (树形dp)
- Matlab数据挖掘工具箱 spider + Weka
- 计算几何的排序--极角排序
- perl的LWP模块简单介绍
- ibatis学习笔记-查询所有对象
- (C++)用typedef定义函数指针类型
- Objective-C 之优雅的命名
- Android图片处理(Matrix,ColorMatrix)
- 如何提高Win7系统的反应速度
- java-参考支付宝加密方式
- C++学习笔记(八)类型转换
- 超级崩溃之头文件错误导致error LNK1120: 1 个无法解析的外部命令
- SNTP协议