iBatis insert
来源:互联网 发布:知羽电子相册模板30套 编辑:程序博客网 时间:2024/05/08 16:02
一、创建Employee POJO类
public class Employee {private Integer id;private String name;private Integer gender;private Integer salary;public Employee() {}public Employee(String name,Integer gender,Integer salary){this.name = name;this.gender = gender;this.salary = salary;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getGender() {return gender;}public void setGender(Integer gender) {this.gender = gender;}public Integer getSalary() {return salary;}public void setSalary(Integer salary) {this.salary = salary;}}
二、修改 Employee.xml文件
在Employee.xml文件中,我们用<insert>标签,这样ibatis执行时就会帮我们执行SQL的insert操作了,其中employee表的主键id是auto increment的,我们可以使用<selectKey>标签生成id。
<sqlMap namespace="Employee"><insert id="insert" parameterClass="model.Employee">insert into Employee (name,gender,salary)values (#name#,#gender#,#salary#)<selectKey resultClass="int" keyProperty="id">select last_insert_id() as id</selectKey></insert></sqlMap>
三、java测试程序
public static void main(String[] args) throws IOException, SQLException{Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);//insert--------------------------------------------------System.out.println("ready to insert...");Employee em = new Employee("weken1",1,7000);sqlMapClient.insert("Employee.insert",em);System.out.println("finish insert...");}
0 0
- ibatis insert
- iBatis insert
- iBatis insert操作陷阱
- ibatis insert 带有默认值
- ibatis的insert问题
- ibatis insert返回主键
- ibatis批量insert
- ibatis insert赋默认值
- ibatis insert 数组
- Ibatis - insert是否插入成功
- Ibatis insert插入返回值
- ibatis 嵌套insert select语句
- ibatis insert返回值问题
- 关于ibatis insert返回值
- iBatis执行insert后返回主键
- ibatis的insert中使用序列
- Ibatis insert语句中 思想 keyProperty
- ibatis的insert操作返回id
- Unity3D游戏开发从零单排(七) - NetworkView的Demo
- PowerShell 中的 replace
- 英语感想——我们是幸运的
- 多线程
- POJ2002:Squares
- iBatis insert
- HDU 1078 FatMouse and Cheese(DP)
- echarts学习笔记(2) ---- 设置单页面多张图表
- 注意sizeof()返回的数无符号数,有符号数遇到无符号数时变成无符号数
- 辛星亲自编写的11本Python资料,免积分下载,希望对大家有所帮助
- C++11新特性:Lambda函数(匿名函数)
- C语言一个队列的实现(链式)
- 使用Apache的ab工具进行压力测试
- C++风格的强制类型转换之小结