ssm采用注解方式外连接查询数据

package cn.it.domain;

import java.io.Serializable;

public class Employee{
private Integer empId;
private String empName;
private String gender;
private String phone;
private Integer dId;

private Department department;

public Employee() {
}

public Employee(Integer empId, String empName, String gender, String phone, Integer dId, Department department) {
    this.empId=empId;
    this.empName=empName;
    this.gender=gender;
    this.phone=phone;
    this.dId=dId;
    this.department=department;
}

public Integer getEmpId() {
    return empId;
}

public void setEmpId(Integer empId) {
    this.empId=empId;
}

public String getEmpName() {
    return empName;
}

public void setEmpName(String empName) {
    this.empName=empName;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender=gender;
}

public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone=phone;
}

public Integer getdId() {
    return dId;
}

public void setdId(Integer dId) {
    this.dId=dId;
}

public Department getDepartment() {
    return department;
}

public void setDepartment(Department department) {
    this.department=department;
}

@Override
public String toString() {
    return "Employee{" +
            "empId=" + empId +
            ", empName='" + empName + '\'' +
            ", gender='" + gender + '\'' +
            ", phone='" + phone + '\'' +
            ", dId=" + dId +
            ", department=" + department +
            '}';
}

}

package cn.it.domain;

import java.io.Serializable;

public class Department{
private Integer deptId;
private String deptName;

public Department() {
}

public Department(Integer deptId, String deptName) {
    this.deptId=deptId;
    this.deptName=deptName;
}

public Integer getDeptId() {
    return deptId;
}

public void setDeptId(Integer deptId) {
    this.deptId=deptId;
}

public String getDeptName() {
    return deptName;
}

public void setDeptName(String deptName) {
    this.deptName=deptName;
}

@Override
public String toString() {
    return "Department{" +
            "deptId=" + deptId +
            ", deptName='" + deptName + '\'' +
            '}';
}

}

sql方式
package cn.it.dao;

import cn.it.domain.Employee;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface EmployeeDao {
@Select(“select empId,empName,gender,phone,dId,deptId,deptName from employee left join department on employee.dId=department.deptId”)
@Results(id=“true”,value={
@Result(property=“empId”,column=“empId”),
@Result(property=“empName”,column=“empName”),
@Result(property=“gender”,column=“gender”),
@Result(property=“phone”,column=“phone”),
@Result(property=“department.deptName”,column=“deptName”)
})
public List findAll();

}

上一篇:基于SSM实现公司内部培训系统的开发


下一篇:快速搭建一个简单的SSM框架