POJO与VO类区别
- POJO:实体类与数据库中的表一一对应,实体类属性与数据库表的字段一一对应。—— 用于数据层
- VO:用于需要把某页面的所有数据封装起来。—— 用于表示层,逻辑层
在今天的开发中需要在一个页面中获取三张表的信息,如果采用pojo实体类,返回的对象值不好显示,因此笔者采用了Vo类实现页面数据的封装。
cutomer_info表:
customer_home_demand表:
customer_flow表:
编写VO类:
public class CustomerVo {
private String name;
private String phone;
private Integer sex;
private String age;
private Integer source;
private Integer maritalStatus;
private Integer isCar;
private String address;
private String employer;
private String position;
private Integer education;
private Integer spendingPower;
private String remark;
private String houseType;
private String area;
private String floor;
private String carPlace;
private Integer payType;
private String focalPoint;
private String remark1;
private Integer flowType;
private String flowDesc;
}
对应的xml文件:对于查询多个表中的字段需要用到内连接inner join . . . on . . .(也可以简写为join . . . on . . .)
<select id="findById" resultType="com.pipeline.vo.output.merchant.CustomerVo">
SELECT
c.name,
c.sex,
c.phone,
c.remark,
c.age,
c.address,
c.marital_status,
c.is_car,
c.employer,
c.position,
c.education,
c.spending_power,
c.source,
d.house_type,d.area,d.floor,d.car_place,d.pay_type,d.focal_point,d.remark1,
f.flow_type,flow_desc
FROM customer_info c INNER JOIN customer_home_demand d ON c.id=d.id INNER JOIN customer_flow f on c.id=f.id
WHERE name=#{name}
</select>
然后编写相应的dao,service,controller层代码,较为简单,这里不贴出来。
采用debug执行程序后,利用Postman工具测试api接口,如下,页面信息全部被查询出来: