多条件查询的两种实现方式

1.
public BookCategory  findinfo7(int cateid);
 
  
<select id="findinfo7" resultMap="myMap">
    SELECT  <include refid="mylie">include> FROM   bookinfo,bookcategory   WHERE   bookcategory.cateid=bookinfo.bookcategory   AND  bookcategory.cateid=#{cateid}
select>
<resultMap id="myMap" type="cate">
       <id column="cateid" property="cateid">id>
    <result column="catename" property="catename">result>
    <collection property="list" ofType="Book">
       <id column="bookname" property="bookname">id>
        <result property="bookauthor" column="bookauthor">result>
    collection>
resultMap>
@Test
public void   TestBook7(){
    BookCategory category = bookDao.findinfo7(1);
    System.out.println(category.getCatename());
    for (Book item:category.getList()) {
        System.out.println(item.getBookname());
    }
}
2.
 
  
public BookCategory  findinfo8(int cateid);
<select id="findinfo8" resultMap="myMap2">
    SELECT   *  FROM   bookcategory   WHERE   cateid=#{cateid}
select>
<resultMap id="myMap2" type="cate">
    <id column="cateid" property="cateid">id>
    <result column="catename" property="catename">result>
    <collection property="list" ofType="Book" select="myselectcateidssss" column="cateid">

    collection>
resultMap>
<select id="myselectcateidssss" resultType="Book">
    SELECT  *  FROM    bookinfo   WHERE   bookcategory=#{cateid}
select>
@Test
public void   TestBook8(){
    BookCategory category = bookDao.findinfo8(1);
    System.out.println(category.getCatename());
    for (Book item:category.getList()) {
        System.out.println(item.getBookname());
    }
}

你可能感兴趣的:(多条件查询的两种实现方式)