随笔分类 -  ibatis初解

摘要:在Student.xml中添加: <select id="selectStudentByName" parameterClass="String" resultClass="Student"> select * from student where name like '%$name$%' </select>此处标红特别注意,跟以往写法不同,可以理解为##自动帮你添加引号,而$$不添加引号进行单元测试: 1 @Test 2 public void queryStudentByName() thr 阅读全文
posted @ 2011-12-04 17:09 一直在等 阅读(372) 评论(0) 推荐(0) 编辑
摘要:在Student.xml中添加: <update id="updateStudent" parameterClass="Student"> update student set name=#name#, score=#score# where id=#id# </update>进行单元测试: 1 @Test 2 public void updateStudent() throws Exception{//更新学生 3 Reader reader=Resources.getResource... 阅读全文
posted @ 2011-12-04 16:41 一直在等 阅读(351) 评论(0) 推荐(0) 编辑
摘要:在Student.xml中添加如下代码: <delete id="deleteStudentById" parameterClass="int"> delete from student where id=#id# </delete>在junit中进行测试:1 @Test2 public void deleteStudent() throws Exception{//根据Id删除学生3 Reader reader=Resources.getResourceAsReader("SqlMapConfig.xml... 阅读全文
posted @ 2011-12-04 16:26 一直在等 阅读(422) 评论(0) 推荐(0) 编辑
摘要:在Student.xml中加入: <insert id="insertStudent" parameterClass="Student"> insert into student ( id , name , score ) values (#id#,#name#,#score#) </insert>并在junit中测试: 1 @Test 2 public void addStudent() throws Exception{//新增学生 3 Reader reader=Resources.getR... 阅读全文
posted @ 2011-12-04 16:04 一直在等 阅读(1037) 评论(0) 推荐(0) 编辑
摘要:在Student.xml中插入如下代码: <!-- parameterClass代表要传入的参数类型 --> <select id="SelectStudentById" parameterClass="int" resultClass="Student"> select * from student where id=#id# </select>然后在junit中进行测试:1 @Test2 public void queryStudentById() throws Exception{//根据Id 阅读全文
posted @ 2011-12-04 15:27 一直在等 阅读(642) 评论(0) 推荐(0) 编辑
摘要:假设数据库的student表中有如下的字段和数据:对应的Student.java如下: 1 public class Student { 2 private Integer id; 3 private String name; 4 private float score; 5 public Integer getId() { 6 return id; 7 } 8 public void setId(Integer id) { 9 this.id = id;10 }11 public String g... 阅读全文
posted @ 2011-12-04 15:11 一直在等 阅读(837) 评论(0) 推荐(0) 编辑
摘要:iBatis是apache得一个开源项目,一个O/R Mapping解决方案,iBatis的最大特点是小巧,上手很快。如果不需要太多复杂的功能,iBatis是能满足你的要求并且灵活简单的方案,官网:http://ibatis.apache.org搭建环境:导入相关的jar包1.导入数据库jar包2.导入ibatis的jar包配置文件:1.JDBC连接的属性文件 SqlMap.properties:driver=org.gjt.mm.mysql.Driverurl=jdbc:mysql://localhost:3306/hibernateusername=rootpassword=java2.总 阅读全文
posted @ 2011-12-04 12:08 一直在等 阅读(893) 评论(1) 推荐(0) 编辑

点击右上角即可分享
微信分享提示