1.创建 student表
create table student (stuno number, stuname varchar2(20),stuage number,graname varchar2(20));
insert into student values (1,'zs',23,'g1'); commit ;
2.创建对象
package org.lanqiao.entity;
import java.math.BigDecimal;
public class Student {
private BigDecimal stuNo;
private String stuName;
private BigDecimal stuAge;
private String graName;
public Student(BigDecimal stuNo, String stuName, BigDecimal stuAge, String graName) {
super();
this.stuNo = stuNo;
this.stuName = stuName;
this.stuAge = stuAge;
this.graName = graName;
}
@Override
public String toString() {
return "Student [stuNo=" + stuNo + ", stuName=" + stuName + ", stuAge=" + stuAge + ", graName=" + graName + "]";
}
public BigDecimal getStuNo() {
return stuNo;
}
public void setStuNo(BigDecimal stuNo) {
this.stuNo = stuNo;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public BigDecimal getStuAge() {
return stuAge;
}
public void setStuAge(BigDecimal stuAge) {
this.stuAge = stuAge;
}
public String getGraName() {
return graName;
}
public void setGraName(String graName) {
this.graName = graName;
}
}
3.创建映射文件studentMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.lanqiao.entity.studentMapper">
<!-- parameterMap:输入参数 resultType:返回参数(对象) -->
<select id="selectStudentById" resultType="org.lanqiao.entity.Student" parameterType="int">
select * from student where stuno = #{stuno}
</select>
</mapper>
4.conf.xml 加载映射文件
<mapper resource="org/lanqiao/entity/studentMapper.xml" />
5.增加 http://mybatis.org/dtd/mybatis-3-config.dtd
eclipse--->preference --->xmllog--->add-->fileSystem
PUBLIC "-//mybatis.org//DTD Config 3.0//EN
6.配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.lanqiao.entity.studentMapper">
<!-- parameterMap:输入参数 resultType:返回参数(对象) -->
<!-- <select id="selectStudentById" resultType="org.lanqiao.entity.Student" parameterType="int">
select * from student where stuno = #{stuno}
</select> -->
<insert id="addstudent" parameterType="org.lanqiao.entity.Student">
insert into student (stuNo ,stuName ,stuAge,graName) values(#{stuNo},#{stuName},#{stuAge},#{graName})
</insert>
<update id="updatestudent"></update>
<delete id="deleteStudentById" parameterType="int">
delete from student where stuNo = ${value}
</delete>
<!-- 返回值是对象 一个多个resultType都是对象 -->
<select id="selectStudentAll" resultType="org.lanqiao.entity.Student" >
select * from student
</select>