数据库中的表经常有业务关联关系。
- 实例
UserVO.java 定义参数,添加getset方法和tostring方法
public class UserVO implements Serializable {
private int empno;
private String ename;
private String dname;
}
UserMapper.xml 定义sql语句
<select id="findUserDepartment" resultType="cn.tedu.vo.UserVO">
select
e.empno,
e.ename,
d.dname
from
emp e
left join
dept d
on
e.deptno=d.deptno
</select>
UserMapper.java 定义抽象方法
List<UserVO> findUserDepartment();
测试方法
@Test
public void testFindUserDepartment(){
UserMapper mapper = ctx.getBean("userMapper",UserMapper.class);
List<UserVO> list = mapper.findUserDepartment();
list.forEach(u -> System.out.println(u));
}