一、用到的实体类如下:
Student.java
パッケージcom.company.entity; java.io.serializableをインポートします。 Import Java.util.date;パブリッククラスの学生はSerializable {private static final long serialversionuid = 1l; private int id;プライベート文字列名;私立日付の出生;プライベートグループグループ; Public Group getGroup(){return Group; } public void setGroup(グループグループ){this.group = group; } public int getId(){return id; } public void setid(int id){this.id = id; } public string getname(){return name; } public void setName(string name){this.name = name; } public date getBirth(){return birth; } public void setBirth(日付出生){this.birth = birth; } @Override public String toString(){return "sustent [birth =" + birts + "、group =" + group + "、id =" + id + "、name =" + name + "]"; }}Group.java
パッケージcom.company.entity; java.util.listをインポートします。パブリッククラスグループ{private int id;プライベート文字列名;プライベート文字列位置;プライベートリスト<学生>学生; public List <Student> getStudents(){return Student; } public void setStudents(List <Student> Student){this.Students = sustent; } public int getId(){return id; } public void setid(int id){this.id = id; } public string getname(){return name; } public void setName(string name){this.name = name; } public string getPosition(){return position; } public void setposition(string position){this.position = position; } @Override public String toString(){return "group [id =" + id + "、name =" + name + "、position =" + position + "]"; }}二、实体对应的表结构
学生表:
Table Student(id int Primary Key、Name Varchar(20)、生年月日、Group_id int References G_Group(g_id));
g_group表:
テーブルg_group(g_id intプライマリキー、g_name varchar(20)、g_position varchar(30));
順序:
シーケンスStudent_ID_Sequenceを作成します;シーケンスgroup_id_sequenceを作成します。
学生和グループ的映射文件如下、你可以在映射文件中找到、关于、mybatis的增删改查操作、mybatis调用存储过程、mybatis分页以及mybatis 对一对一、多对多的处理
xml文件中都标有注释、看的时候配合下面的具体实现看、虽然有点乱
Student.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" mybatis缓存 - > <キャッシュeviction = "lru" flushinterval = "600000" size = "1024" readonly = "false" /> <! - sql id = "getStudentandGroup"> <id column = "id" property = "id"/> <result column = "name" property = "name"/> <result column = "birts" property = "birth"/> <associationプロパティ= "column =" column = "column =" column = "group_id"列= "g_position" Property = "position"/> </association> </resultmap> <select id = "many2one" resultmap = "getstudentandgroup" parametertype = "int"> select s.id、s.name、s.birth、s.group_id、g.g_id、g.g_name、g.gg_id g.grid gg_id gg_id gg_id gg_id gg_id g. s.id =#{id} </select> <! - 意图是获得一个学生、并且获得该学生所属的组、跟上面的意思差不多、用association的select属性 - > <! - 于上面的相比个人感觉上面的效率要高些、因为上面只有一条sql语句 - > <resultmap type = "sudent" id = "getstudent andgroupuseselectmap"> <id column = "id" "/> <colum ="プロパティ= "birth"/> <associationプロパティ= "column =" group_id "javatype =" group "select =" selectgroup "/> </resultmap> <select id =" getstudentandgroupuseSelect "resultmap =" getStudentandgroupuseSelectmap "parametertype =" int " resultType = "group" parametertype = "int" flushcache = "false" usecache = "true"> <! - 此处实用缓存 - > selece g_id as nameとしてg_name、g_groupとしての位置g_id =#{id} </select> <! parametertype = "sudent" resultType = "sustent"> select * from Student <where> <if> <"id!= null"> id> 2 </if> <if> <"name!= null">および '%g%' </if> </where> </select> <! - mybatis调用存储过程 - > <result column = "name" property = "name"/> <result column = "birth" property = "birth"/> </<resultmap> <select id = "getalluser" statementType = "callable"> {call get_all_student(#{call get_all_student(#{call get_all_student(#{call = out、out、jdbctype = cursor、javatype = resultsmap = sudumentmap}) mybatis向学生表中插入一条数据 - > <Id = "add" parametertype = "dustom" keycolumn = "keycolumn =" keycolumn = "selectkey keyproperty =" resulttype = "int"> select stu_id_sequence.nextval from dual </selectkey> insert intering(id、burth、burth、#{id} ^ </insert> <! - 根据id defid = "sustentcolumns"/> id <! - 此处是引用了上面预定义好的sql语句 - > </select> </mapper>による注文MyBatis 存储过程、Mybatis 分页、 mybatis一对多增删改查操作、希望对大家有所帮助、如果大家有任何疑问请给我留言、小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!