mybatis 多表联查的mapper怎么写
sql语句,确认过可以在数据库中查到数据,但是mapper该怎么写?平常用的hibernate,突然用mabatis,玩不了了……
public class Customer {
private int id;
private String name;
private String telephone;
private String email;
private int fieldId;
以下省略get,set
public class Field {
private int id;
private String rent;
private String fieldName;
private Date leaseStartDate;
private Date leaseEndDate;
以下省略get,set
<select id="getCustomerById" resultMap="customerResult" parameterType="entity.Customer">
select c.id as id,c.name as name, c.telephone as telephone,c.email as email,
f.fieldName as field
from customer c,field f
where c.id=#{id} and c.fieldId=f.id
</select>
<resultMap type="entity.Customer" id="customerResult">
<result property="id" column="Id"/>
<result property="name" column="Name"/>
<result property="telephone" column="Telephone"/>
<result property="email" column="Email"/>
<collection property="field" ofType="entity.Field" column="id" select="getCustomerById">
<result property="id" column="Id"/>
<result property="fieldname" column="FieldName"/>
</collection>
</resultMap>