转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:张燕广

该篇主要编写DAO层代码。

src下创建包com.zyg.ssi.dao,在该包下创建接口StudentDao,其代码如下:

package com.zyg.ssi.dao; import java.util.List; import com.zyg.ssi.bean.Student; public interface StudentDao { /** * 保存学生信息 * @param student */ public void addStudent(Student student); /** * 根据学号删除学生信息 * @param studentId */ public void delStudentById(int id); /** * 更新学生信息 * @param student */ public void updateStudentById(Student student); /** * 根据学号获取学生信息 * @param studentId */ public Student queryStudentById(int id); /** * 根据姓名获取学生信息 * @param studentId */ public List<Student> queryStudentByName(String name); /** * 获取全部学生信息 * @param studentId */ @SuppressWarnings("unchecked") public List<Student> queryAllStudents(); }

在src下创建包com.zyg.ssi.dao.ibaits,在该包下创建实现StudentDao接口的类StudentDaoImpl,其代码如下:

package com.zyg.ssi.dao.ibaits; import java.io.IOException; import java.io.Reader; import java.sql.SQLException; import java.util.List; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.ibatis.sqlmap.client.SqlMapClient; import com.zyg.ssi.bean.Student; import com.zyg.ssi.dao.StudentDao; public class StudentDaoImpl implements StudentDao { private SqlMapClient sqlMapClient; public void addStudent(Student student) { // TODO Auto-generated method stub try { sqlMapClient.insert("insertStudent", student); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void addStudentBySequence(Student student) { // TODO Auto-generated method stub } public void delStudentById(int id) { try { sqlMapClient.delete("delStudentById", id); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public List<Student> queryAllStudents() { // TODO Auto-generated method stub List<Student> stuList = null; try { stuList = sqlMapClient.queryForList("selectAllStudent"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return stuList; } public Student queryStudentById(int id) { Student student=null; try { student = (Student)sqlMapClient.queryForObject("selectStudentById", id); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return student; } public List<Student> queryStudentByName(String name) { // TODO Auto-generated method stub List<Student> stuList = null; try { stuList = sqlMapClient.queryForList("selectStudentByName",name); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return stuList; } public void updateStudentById(Student student) { // TODO Auto-generated method stub try { sqlMapClient.update("updateStudent", student); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public SqlMapClient getSqlMapClient() { return sqlMapClient; } public void setSqlMapClient(SqlMapClient sqlMapClient) { this.sqlMapClient = sqlMapClient; } }

至此,改篇完成了DAO层代码的编写。下一篇开始编写Service层代码以及针对Service层功能的Junit测试代码。

Spring2.5+Struts2+Ibatis整合之四相关推荐

  1. Spring2.5+Struts2+Ibatis整合之五

    转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:张燕广 该篇主要Service层代码以及针对Service层功能的Junit测试代码 在src下创建包com. ...

  2. Spring2.5+Struts2+Hibernate3整合之四

    转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:张燕广 该篇主要编写DAO层代码. 在src下创建包com.zyg.ssh.dao,在该包下创建接口Stude ...

  3. Spring2.5+Struts2+Hibernate3整合之五

    转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:张燕广 该篇主要编写Service层代码以及针对Service层功能的Junit测试代码 在src下创建包co ...

  4. spring+struts2+ibatis整合完全步骤

    Ssi整合首先需要导入相关的jar包 <classpath> <classpathentry kind="src" path="src"/&g ...

  5. Spring2.5+Struts2+Hibernate3整合之三

    转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:张燕广 该篇主要编写bean和bean的hibernate配置文件. 在src下创建包com.zyg.ssh. ...

  6. struts2 ibatis Spring系统架构图

    struts2 Ibatis Spring ----------------------------------- 转载于:https://www.cnblogs.com/archie2010/arc ...

  7. spring2.5+struts2+hibernate+mysql

    今天写了二个学习的小实例,功能很简单,就是登录,注册功能. spring2.5+struts2+hibernate3.1+mysql5 http://download.csdn.net/source/ ...

  8. struts2+ibatis+spring框架整合(二)

    MyBatis3.1.1+Spring3.1.2+Struts2.3.4.1框架整合 先来看目录结构 来看配置文件 applicationContext.xml <?xml version=&q ...

  9. Ibatis 整合spring + Struts2 加入OSCACHE

    说明:    使用  spring2.5 +ibatis2.3.4+oscache2.4+struts2+oracle 建表 create table STUDENT ( SID NUMBER(8) ...

最新文章

  1. VS Code go 插件安装失败 r.declReader.Reset undefined
  2. #mysql50#_#mysql50#.ssh设个啥数据库?
  3. python music21将音符转为mid格式音乐
  4. 2022年大厂面试八股文上线!
  5. Evernote 印象笔记赞一个(非广告)
  6. SAP Spartacus UsersSelectors.getAddressesLoading
  7. js递归遍历json树_2020-08-26:裸写算法:树的非递归先序遍历
  8. 医疗机构被勒索软件攻击的可能性是金融机构的114倍
  9. Ubuntu 16.04安装 Nmap 6.46.1
  10. Python基础(十): 函数的基本概念
  11. python 怎么把 写好的代码 放到服务器执行_给 Python 初学者解答了无数遍的 Python 环境相关问题...
  12. HBuilderX App开发环境搭建
  13. k3 cloud oracle,调试K3Cloud的管理中心未能加载Oracle问题
  14. Dynamics CRM 365零基础入门学习(五)权限管理
  15. Android开发实战《手机安全卫士》——6.“高级工具”模块拓展 自定义Toast
  16. 聊聊我办上海居住证的经历
  17. c# 一个月中的工作日_在Excel中查找一个月中的第N个工作日
  18. python怎么从excel获取数据_python如何读取excel表数据
  19. 三分钟快速了解typeScript接口
  20. python数组列表添加一行一列np.rowstack()np.column_stack()

热门文章

  1. Neural Motifs: Scene Graph Parsing with Global Context (CVPR 2018) 运行复现遇到的一些坑以及解决方法
  2. android 按钮悬浮菜单,悬浮菜单app下载
  3. IOS捷径、微信技巧、玩机巧计交流群
  4. 数学建模求大师帮助,急
  5. 绝缘栅型场效应管(N沟道)
  6. python扫雷游戏设计_python扫雷游戏
  7. Factory Method (工厂方法)---对象创建型模型
  8. pg主从复制(二)——备库激活过程分析
  9. 什么是粗粒度与细粒度,它们的区别又是什么?
  10. 【知识点】(五)多元函数微积分学