package com.xyc.ibatis.dao;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.xyc.ibatis.client.MyAppSqlConfig;
import com.xyc.ibatis.domain.Emp;
public class IbaitsDaoImpl implements IbatisDao{
private static final SqlMapClient sqlMap=MyAppSqlConfig.getSqlMapInstance();
public Emp getEmpById(int id) {
Emp emp=null;
try {
emp=(Emp)sqlMap.queryForObject("getEmpById", id);
System.out.println(emp);
} catch (SQLException e) {
e.printStackTrace();
}
return emp;
}
public List getEmpListBySex() {
String sex=new String("f");
List empList=null;
try {
empList=sqlMap.queryForList("getEmpListBySex", sex);
} catch (SQLException e) {
e.printStackTrace();
}
return empList;
}
public List getDeptList() {
List deptList=null;
try {
deptList=sqlMap.queryForList("getDeptList");
} catch (SQLException e) {
System.out.println("getDeptList方法出现错误!");
e.printStackTrace();
}
return deptList;
}
public List getPartEmpList() {
Map empMap=new HashMap();
empMap.put("sex", "f");
empMap.put("job", "officer");
List parEmpList=null;
try {
parEmpList=sqlMap.queryForList("getPartEmpList",empMap);
} catch (SQLException e) {
System.out.println("getPartEmpList方法出现错误!");
e.printStackTrace();
}
return parEmpList;
}
public void insertEmp() {
Emp emp=new Emp();
emp.setDeptId(1);
emp.setEmpName("ouyangfeng");
emp.setEmpSex("m");
emp.setJob("singer");
emp.setSalary(700.00);
try {
sqlMap.insert("insertEmp", emp);
System.out.println("插入员工记录成功!");
} catch (SQLException e) {
System.out.println("未能成功插入员工记录!");
e.printStackTrace();
}
}
public void updateEmp() {
Emp emp = new Emp();
emp.setEmpId(3);
emp.setSalary(900.0);
emp.setEmpName("huangrong");
emp.setJob("dancer");
try {
sqlMap.update("updateEmp", emp);
System.out.println("更新员工成功!");
} catch (SQLException e) {
e.printStackTrace();
}
}
public void deleteEmp() {
int id=2;
try {
sqlMap.delete("deleteEmp", id);
System.out.println("删除成功!");
} catch (SQLException e) {
e.printStackTrace();
}
}
public Emp getDeptNameByEmpName() {
String empName="jim";
Emp emp=null;
try {
emp=(Emp)sqlMap.queryForObject("getEmpDeptName", empName);
System.out.println(emp.getEmpName()+" "+emp.getDept().getDeptName());
} catch (SQLException e) {
e.printStackTrace();
}
return emp;
}
public Emp getDynamicEmp() {
Emp emp = null;
Map map=new HashMap();
map.put("salary", 201.0);
map.put("empName", "hameimei");
try {
emp = (Emp) sqlMap.queryForObject("dynamicGetEmp",map);
System.out.println(emp);
} catch (SQLException e) {
e.printStackTrace();
}
return emp;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ibatis学习完整实例,例子
共32个文件
xml:9个
class:6个
java:6个
4星 · 超过85%的资源 需积分: 9 154 下载量 129 浏览量
2008-10-29
09:39:53
上传
评论
收藏 673KB RAR 举报
温馨提示
本例子集成了ibatis的常用操作,如果掌握了本实例教程,相信应付一般的工作是没有问题的了。本实例教程还集成了数据库脚本。导入工程就可以运行。里面有详细的注释。
资源推荐
资源详情
资源评论
收起资源包目录
ibatistest2.rar (32个子文件)
ibatistest2
.project 1013B
.mymetadata 306B
WebRoot
WEB-INF
web.xml 375B
lib
ibatis jar.jar 375KB
ibatis-2.3.0.677.jar 380KB
classes
com
xyc
ibatis
sqlMapConf.properties 95B
dao
IbaitsDaoImpl.class 4KB
IbatisDao.class 419B
main
IbatisMain.class 1KB
sqlMapConf.xml 758B
domain
dept.xml 766B
emp.xml 3KB
Emp.class 2KB
Dept.class 1KB
Person.xml 1KB
client
MyAppSqlConfig.class 1KB
index.jsp 834B
META-INF
MANIFEST.MF 39B
.myeclipse
src
com
xyc
ibatis
sqlMapConf.properties 95B
dao
IbaitsDaoImpl.java 3KB
IbatisDao.java 841B
main
IbatisMain.java 886B
sqlMapConf.xml 758B
domain
dept.xml 766B
emp.xml 3KB
Emp.java 1KB
Dept.java 775B
Person.xml 1KB
client
MyAppSqlConfig.java 717B
.classpath 609B
ibatis_emp.sql 1KB
ibatis_dept.sql 1KB
共 32 条
- 1
xieyunchao
- 粉丝: 35
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页