Extension of mapper in MyBatis

Source: Internet
Author: User

With Mbgenerator automatically generating MyBatis entities and Mapper (XML and interface) files, if you want to add new operations to the mapper, it is not convenient to change the automatically generated files, the workaround is to define a new interface and a new mapper XML file.

Blogextmapper.java

Public interface Blogextmapper extends Blogmapper {list<blog> selectall ();    List<blog> selectrecent ();    List<blog> selectbyyearmonth (String yearmonth);    List<blog> selectactiveblogs ();    List<blog> selectbestblogs ();    List<blogstatistic> Groupbyyearmonth ();    list<blog> selectblogsbycategory (int categoryid); list<blog> selectblogsbyrange (int offset);}

The select operation that corresponds to the new XML definition and interface method.

Blogextmapper.xml:

<mapper namespace= "Com.icool.cms.data.mybatis.extend.BlogExtMapper"  >     <resultmap id= "Groupbyyearmonthmap"  type= "com.icool.cms.data.mybatis.BlogStatistic" >         <result column= "C"  property= "Count"  jdbcType= " INTEGER " />        <result column=" y " property=" Year " jdbctype=" VARCHAR " />        <result column" = "M"  property= "month"  jdbctype= "VARCHAR"  />    </resultMap>     <select id= "SelectAll"  resultmap= " Com.icool.cms.data.mybatis.BlogMapper.ResultMapWithBLOBs ">           select          <include refid= " Com.icool.cms.data.mybatis.BlogMapper.Base_Column_List " />              ,           <include refid= "Com.icool.cms.data.mybatis.BlogMapper.Blob_Column_List"  />          from BLOG order by  Createtime desc    </select&gt, .....

The main point of attention here is how to reuse some of the resultmap defined in Blogmapper.xml, which is very simple, with the full package name:

Com.icool.cms.data.mybatis.BlogMapper.ResultMapWithBLOBs


Extension of mapper in MyBatis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.