Mysql 多表连查 xml写法 非注解形式
1.xml写法
<!-- 联查用户users表 -->
<resultMap type="nanh.entity.Tasks" id="selectTasksAllLeftUsers">
<id column="id" property="id"/>
<result column="tasknumber" jdbcType="VARCHAR" property="tasknumber" />
<result column="taskstarttime" jdbcType="VARCHAR" property="taskstarttime" />
<result column="taskendtime" jdbcType="VARCHAR" property="taskendtime" />
<result column="taskclass" jdbcType="VARCHAR" property="taskclass" />
<result column="taskinfo" jdbcType="VARCHAR" property="taskinfo" />
<result column="taskstatus" jdbcType="VARCHAR" property="taskstatus" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="executiontime" jdbcType="VARCHAR" property="executiontime" />
<association property="users" javaType="nanh.entity.Users">
<result column="numbers" jdbcType="VARCHAR" property="numbers" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="positionid" jdbcType="INTEGER" property="positionid" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="jurisdiction" jdbcType="VARCHAR" property="jurisdiction" />
<result column="deptid" jdbcType="INTEGER" property="deptid" />
<result column="currenttask" jdbcType="VARCHAR" property="currenttask" />
<result column="state" jdbcType="VARCHAR" property="state" />
<association property="dept" javaType="nanh.entity.Dept">
<result column="deptnumber" property="deptnumber" jdbcType="VARCHAR" />
<result column="deptname" property="deptname" jdbcType="VARCHAR" />
</association>
<association property="position" javaType="nanh.entity.Position">
<result column="positionname" property="positionname" jdbcType="VARCHAR" />
<result column="positionnumber" property="positionnumber" jdbcType="VARCHAR" />
</association>
</association>
</resultMap>
<select id="selectByPrimaryKeyAll" resultMap="selectTasksAllLeftUsers" parameterType="java.lang.Integer" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
t.id, t.tasknumber, t.taskstarttime, t.taskendtime, t.taskclass, t.taskinfo, t.taskstatus, t.uid, t.executiontime,
u.numbers, u.name, u.positionid, u.phone, u.status, u.jurisdiction, u.deptid, u.currenttask, u.state,
d.deptnumber, d.deptname, p.positionname, p.positionnumber
from tasks t left join users u on t.uid = u.id
left join dept d on u.deptid = d.id
left join position p on u.positionid = p.positionid
</select>
2.实体类写法
package nanh.entity;
import java.io.Serializable;
public class Tasks implements Serializable{
private Users Users;
public Users getUsers() {
return Users;
}
public void setUsers(Users users) {
Users = users;
}
@Override
public String toString() {
return "Tasks [Users=" + Users + ", id=" + id + ", tasknumber=" + tasknumber + ", taskstarttime="
+ taskstarttime + ", taskendtime=" + taskendtime + ", taskclass=" + taskclass + ", taskinfo=" + taskinfo
+ ", taskstatus=" + taskstatus + ", uid=" + uid + ", executiontime=" + executiontime + "]";
}
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.id
*
* @mbggenerated
*/
private Integer id;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.tasknumber
*
* @mbggenerated
*/
private String tasknumber;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.taskstarttime
*
* @mbggenerated
*/
private String taskstarttime;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.taskendtime
*
* @mbggenerated
*/
private String taskendtime;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.taskclass
*
* @mbggenerated
*/
private String taskclass;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.taskinfo
*
* @mbggenerated
*/
private String taskinfo;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.taskstatus
*
* @mbggenerated
*/
private String taskstatus;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.uid
*
* @mbggenerated
*/
private Integer uid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column tasks.executiontime
*
* @mbggenerated
*/
private String executiontime;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.id
*
* @return the value of tasks.id
*
* @mbggenerated
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.id
*
* @param id the value for tasks.id
*
* @mbggenerated
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.tasknumber
*
* @return the value of tasks.tasknumber
*
* @mbggenerated
*/
public String getTasknumber() {
return tasknumber;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.tasknumber
*
* @param tasknumber the value for tasks.tasknumber
*
* @mbggenerated
*/
public void setTasknumber(String tasknumber) {
this.tasknumber = tasknumber == null ? null : tasknumber.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.taskstarttime
*
* @return the value of tasks.taskstarttime
*
* @mbggenerated
*/
public String getTaskstarttime() {
return taskstarttime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.taskstarttime
*
* @param taskstarttime the value for tasks.taskstarttime
*
* @mbggenerated
*/
public void setTaskstarttime(String taskstarttime) {
this.taskstarttime = taskstarttime == null ? null : taskstarttime.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.taskendtime
*
* @return the value of tasks.taskendtime
*
* @mbggenerated
*/
public String getTaskendtime() {
return taskendtime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.taskendtime
*
* @param taskendtime the value for tasks.taskendtime
*
* @mbggenerated
*/
public void setTaskendtime(String taskendtime) {
this.taskendtime = taskendtime == null ? null : taskendtime.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.taskclass
*
* @return the value of tasks.taskclass
*
* @mbggenerated
*/
public String getTaskclass() {
return taskclass;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.taskclass
*
* @param taskclass the value for tasks.taskclass
*
* @mbggenerated
*/
public void setTaskclass(String taskclass) {
this.taskclass = taskclass == null ? null : taskclass.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.taskinfo
*
* @return the value of tasks.taskinfo
*
* @mbggenerated
*/
public String getTaskinfo() {
return taskinfo;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.taskinfo
*
* @param taskinfo the value for tasks.taskinfo
*
* @mbggenerated
*/
public void setTaskinfo(String taskinfo) {
this.taskinfo = taskinfo == null ? null : taskinfo.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.taskstatus
*
* @return the value of tasks.taskstatus
*
* @mbggenerated
*/
public String getTaskstatus() {
return taskstatus;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.taskstatus
*
* @param taskstatus the value for tasks.taskstatus
*
* @mbggenerated
*/
public void setTaskstatus(String taskstatus) {
this.taskstatus = taskstatus == null ? null : taskstatus.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.uid
*
* @return the value of tasks.uid
*
* @mbggenerated
*/
public Integer getUid() {
return uid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.uid
*
* @param uid the value for tasks.uid
*
* @mbggenerated
*/
public void setUid(Integer uid) {
this.uid = uid;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column tasks.executiontime
*
* @return the value of tasks.executiontime
*
* @mbggenerated
*/
public String getExecutiontime() {
return executiontime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column tasks.executiontime
*
* @param executiontime the value for tasks.executiontime
*
* @mbggenerated
*/
public void setExecutiontime(String executiontime) {
this.executiontime = executiontime == null ? null : executiontime.trim();
}
}