<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.InvitationMapper">
<resultMap id="baseResultMap" type="Invitation">
<id property="id" column="ID"></id>
<result property="title" column="title"></result>
<result property="summary" column="summary"></result>
<result property="author" column="author"></result>
<result property="createdate" column="createdate"></result>
<collection property="replay_detailList" ofType="Replay_detail" >
<id property="id" column="rid"></id>
<result property="content" column="content"></result>
<result property="author" column="rauthor"></result>
<result property="createdate" column="rcreatedate"></result>
</collection>
</resultMap>
<resultMap id="lazeQueryResultMap" type="Invitation">
<id property="id" column="ID"></id>
<result property="title" column="title"></result>
<result property="summary" column="summary"></result>
<result property="author" column="author"></result>
<result property="createdate" column="createdate"></result>
<collection property="replay_detailList" ofType="Replay_detail" select="mapper.Replay_detailMapper.selectByInvId" column="id">
</collection>
</resultMap>
<!--id:该条语句的唯一标识
parameterType:表示入参类型
resultType:返回结果将要封装成的类型-->
<!--基本类型及String入参时,与#{}中的字符没有关系-->
<!--1.通过传统多条select方式实现-->
<select id="selectById" parameterType="java.lang.Integer" resultType="Invitation">
select * from Invitation where id = #{a}
</select>
<!--3.join关联查询,通过查询帖子列表,将其中的回复查询出来-->
<select id="selectByIdAndJoin" resultMap="baseResultMap">
SELECT invitation.*,replay_detail.id as rid,replay_detail.content,replay_detail.author as rauthor,replay_detail.createdate as rcreatedate from invitation,replay_detail where invitation.id=replay_detail.invid and invitation.id=#{id}
</select>
<!--<select id="selectAll" resultType="Invitation">-->
<!--select * from invitation-->
<!--</select>-->
<!--4.通过mybatis配置多条select方式实现(验证lazy加载)-->
<select id="lazeQueryById" resultMap="lazeQueryResultMap">
select * from Invitation where id = #{a}
</select>
<!--引用类型入参,是POJO中的属性对应的get方法的后缀,首字母小写-->
<!--<insert id="insert">-->
<!--insert into invitation (title,summary,author,createdate) values (#{title},#{summary},#{author},#{createdate})-->
<!--</insert>-->
<!--<delete id="delete" parameterType="java.lang.Integer">-->
<!--delete from invitation where id = #{id}-->
<!--</delete>-->
<!--<update id="update">-->
<!--update invitation set title=#{title},summary=#{summary} where id=#{id}-->
<!--</update>-->
</mapper>
package mapper;
import model.Invitation;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
public interface InvitationMapper {
Invitation selectById(int id);
// List<Invitation> selectAll();
// Integer insert(@Param("title") String title,@Param("summary") String summary,@Param("author") String author,@Param("createdate") Date createdate);
// Integer delete(int id);
// Integer update(@Param("title")String title,@Param("summary")String summary,@Param("id")int id);
Invitation selectByIdAndJoin(int id);
Invitation lazeQueryById(int id);
}
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.Replay_detailMapper">
<!--id:该条语句的唯一标识
parameterType:表示入参类型
resultType:返回结果将要封装成的类型-->
<!--基本类型及String入参时,与#{}中的字符没有关系-->
<select id="selectById" parameterType="java.lang.Integer" resultType="model.Replay_detail">
select * from replay_detail where id = #{a}
</select>
<select id="selectByInvId" parameterType="java.lang.Integer" resultType="model.Replay_detail">
select * from replay_detail where invid = #{a}
</select>
<select id="selectByIdAndSubQuery" resultType="model.Replay_detail">
select * from replay_detail where invid = (select id from invitation where id = #{a})
</select>
<!--<select id="selectAll" resultType="model.Replay_detail">-->
<!--select * from replay_detail-->
<!--</select>-->
<!--<!–引用类型入参,是POJO中的属性对应的get方法的后缀,首字母小写–>-->
<insert id="insert" keyColumn="ID" keyProperty="id" useGeneratedKeys="true">
insert into replay_detail (invid,content,author,createdate) values (#{invid},#{content},#{author},#{createdate})
</insert>
<!--<delete id="delete" parameterType="java.lang.Integer">-->
<!--delete from replay_detail where invid = #{id}-->
<!--</delete>-->
<!--<update id="update">-->
<!--update replay_detail set content=#{content},author=#{author} where id=#{id}-->
<!--</update>-->
</mapper>
package mapper;
import model.Replay_detail;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
public interface Replay_detailMapper {
Replay_detail selectById(int id);
// List<Replay_detail> selectAll();
// Integer insert(@Param("invid") int invid, @Param("content") String content, @Param("author") String author, @Param("createdate") Date createdate);
// Integer delete(int id);
// Integer update(@Param("content")String content,@Param("author")String author,@Param("id")int id);
List<Replay_detail> selectByInvId(int invid);
List<Replay_detail> selectByIdAndSubQuery(int invid);
Integer insert(Replay_detail replay_detail);
}