如有两个查询方法查询的表相同,仅返回对象包含的字段不同,A方法返回a、b、c字段,B方法返回d、e、f字段;则可以新建C方法,同时查询a、b、c、d、e、f字段,在接口中做对象转换。
1、对象定义:(省略get、set方法)
public class SchoolInfoBO {
private Integer id;
private String schoolId;
private String schoolName;
private String schoolAddress;
}
public class SchoolBaseInfo {
private Integer id;
private String schoolId;
private String schoolName;
}
public class SchoolAddressInfo {
private String schoolId;
private String schoolAddress;
}
2、dao层:
@Repository
public interface SchoolMapper {
SchoolInfoBO getSchoolInfoBySchoolId(@Param("schoolId") String schoolId);
}
<select id="getSchoolInfoBySchoolId" resultType="xx.xxx.bo.SchoolInfoBO">