多平台统一管理软件接口,如何实现多平台统一管理软件接口
195
2023-06-28
MyBatis存储过程、MyBatis分页、MyBatis一对多增删改查操作
一、用到的实体类如下:
Student.java
package com.company.entity;
import java.io.Serializable;
import java.util.Date;
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
private int id;
private String name;
private Date birth;
private Group group;
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
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(Date birth) {
this.birth = birth;
}
@Override
public String toString() {
return "Student [birth=" + birth + ", group=" + group + ", id=" + id
+ ", name=" + name + "]";
}
}
Group.Java
package com.company.entity;
import java.util.List;
public class Group {
private int id;
private String name;
private String position;
private List
public List
return students;
}
public void setStudents(List
this.students = students;
}
public int getId() {
return id;
}
public VQyRAhNTEvoid 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
+ "]";
}
}
二、实体对应的表结构
student表:
create table student(
id int primary key,
name varchar(20),
birth date,
group_id int references g_group(g_id));
g_group表:
create table g_group(
g_id int primary key,
g_name varchar(20),
g_position varchar(30));
sequence:
create sequence student_id_sequence;
create sequence group_id_sequence;
三、Student和Group的映射文件如下,你可以在映射文件中找到,关于MyBatis的增删改查操作,MyBatis调用存储过程,MyBatis分页以及MyBatis对一对一、多对多的处理
xml文件中都标有注释,看的时候配合下面的具体实现看,虽然有点乱
student.xml
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select s.id,s.name,s.birth,s.group_id,g.g_id,g.g_name,g.g_position
from student s
left join g_group g on s.group_id = g.g_id
where s.id = #{id}
select *
from student
where id = #{id}
select g_id as id, g_name as name, g_position as position
from g_group
where g_id = #{id}
select *
from student
id>2
and name like '%g%'
{call get_all_student(#{students ,mode=OUT, jdbcType=CURSOR, javaType=ResultSet, resultMap=studentMap} )}
select stu_id_sequence.nextval from dual
insert into student(id,name,birth) values(#{id},#{name},#{birth})
以上所述是给大家介绍的MyBatis存储过程、MyBatis分页、MyBatis一对多增删改查操作,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~