实体类里含有list,mybatis的mapper文件配置

实体类

public class LayoutBean {
     
	
	private Integer l_id;
	private String name;
	private String summarize;
	private String describe;
	private String image;
	private Double price;
	private Integer limit;
	private Date create_date;
	private Date modif_date;
	private Integer state;
    private List<RoomBean> rooms;

}
public class RoomBean {
     
	
	private Integer r_id;
	private String plate;
	private Integer l_id;
	private Integer floor;
	private Integer state;
	private Boolean booked;

}

mapper文件配置

 <resultMap type="ssm.beans.LayoutBean" id="LayoutResultMap">  
		<id property="l_id" column="l_id" />
		<result column="name" property="name" jdbcType="VARCHAR" />
		<result column="summarize" property="summarize" jdbcType="VARCHAR" />
		<result column="describe" property="describe" jdbcType="VARCHAR" />
		<result column="image" property="image" jdbcType="VARCHAR" />
		<result column="price" property="price" jdbcType="DECIMAL" />
		<result column="limit" property="limit" jdbcType="INTEGER" />
		<result column="create_date" property="create_date" jdbcType="TIMESTAMP" />
		<result column="modif_date" property="modif_date" jdbcType="TIMESTAMP" />
		<result column="state" property="state" jdbcType="INTEGER" />
        <collection property="rooms" ofType="ssm.beans.RoomBean"  resultMap="RoomResultMap" />  
    </resultMap>
    <resultMap type="ssm.beans.RoomBean" id="RoomResultMap">  
		<id property="r_id" column="r_id" />
		<result column="l_id" property="l_id" jdbcType="INTEGER" />
		<result column="plate" property="plate" jdbcType="VARCHAR" />
		<result column="floor" property="floor" jdbcType="INTEGER" />
		<result column="state" property="state" jdbcType="INTEGER" />
    </resultMap>
    <select id="getLayoutAndRoomBeans" resultMap="LayoutResultMap">
	    SELECT *
        FROM layout_info la left outer join room_info ro on la.l_id = ro.l_id;
	</select>

注意
mysql类型为intdatetime的,mybatis的jdbcType需要写成INTEGERTIMESTAMP(或DATE),否则会抛No enum constant org.apache.ibatis.type.JdbcType.INTNo enum constant org.apache.ibatis.type.JdbcType.DATETIME异常

你可能感兴趣的:(mybatis,mysql)