The writing of Mybaits Mapper.xml

Source: Internet
Author: User

Used to mybaits generator, long time not write mybaits, found will not write, here first put down some examples, for later use when reference
Project Example Download address:
Https://gitee.com/paincupid/simple-springmvc

Mybaits Config Example

Package com.paincupid.springmvc.persistence;

Import com.paincupid.springmvc.domain.Student;
Import Org.apache.ibatis.annotations.Param;

Import java.util.List;

Public interface Studentvomapper {

    int insertstudentbyvomapper (Student Student);

    List<student> Liststudentbyclassnoandsex (@Param ("Classno") Integer Classno, @Param ("sex") Boolean sex);

    Student Getstudentbyid (Long ID);

    int Updatestudentnamebyid (@Param ("id") Long ID, @Param ("name") String name);

    /**
     * If There is a 1 param, do not need use @Param annotation
     * @param ID * @return */
    int Deletestudentbyid (Long ID);

    int Updatestudent2columnval (@Param ("IQ") Integer IQ, @Param ("Cultivatehobby") String cultivatehobby);

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!--   Important:studentvomapper ' s name must be the same as the Java file!!!!!!!!! --<mapper namespace= "Com.paincupid.springmvc.persistence.StudentVoMapper" > <resultmap id= " Baseresultmap "type=" com.paincupid.springmvc.domain.Student "> <id column=" id "jdbctype=" BIGINT "property=" id "/> <result column=" name "jdbctype=" VARCHAR "property=" name "/> <result column=" height "Jdbctyp
        E= "DOUBLE" property= "height"/> <result column= "class_no" jdbctype= "INTEGER" property= "Classno"/> <result column= "Sex" jdbctype= "BIT" property= "Sex"/> <result column= "IQ" jdbctype= "INTEGER" property= "IQ" /> <result column= "Focus" jdbctype= "BIT" property= "Focus"/> <result column= "Cultivate_hobby" J Dbctype= "VARCHAR" property= "CultivatEhobby "/> <result column=" Phone "jdbctype=" INTEGER "property=" Phone "/> <result column=" address 
        "Jdbctype=" VARCHAR "property=" Address "/> <result column=" Is_delete "jdbctype=" BIT "property=" Isdelete "/> <result column= "modifier" jdbctype= "VARCHAR" property= "modifier"/> <result column= "Gmt_create" J Dbctype= "Date" property= "Gmtcreate"/> <result column= "gmt_modified" jdbctype= "date" property= "GmtModified"/&
        Gt <result column= "bak" jdbctype= "VARCHAR" property= "bak"/> </resultMap> <insert id= "Insertstudentbyv Omapper "keycolumn=" id "keyproperty=" id "parametertype=" com.paincupid.springmvc.domain.Student "us
          Egeneratedkeys= "true" > INSERT into T_student (name,class_no,is_delete,modifier,gmt_create, gmt_modified)
    VALUES (#{name},#{classno},#{isdelete},#{modifier},#{gmtcreate},#{gmtmodified}); </insert> <select id= "ListstudEntbyclassnoandsex "resultmap=" Baseresultmap "> select * from t_student where class_no = #{classno} and sex= #{sex,jdbctype=bit} </select> <select id= "Getstudentbyid" resultmap= "Baseresultmap" parametertype= "Long" > select * from T_student where id=#{id} </select> <update id= "Updatestudentnamebyid" par

    Ametertype= "Student" > UPDATE t_student SET name = #{name} WHERE id = #{id} </update> <update id= "Updatestudent2columnval" > Update t_student SET cultivate_hobby = #{cultivatehobby} , focus = ' 1 ' WHERE iq > #{iq} </update> <delete id= "Deletestudentbyid" parametertype= "Long" &
        Gt DELETE from t_student WHERE id = #{id} </delete> </mapper>

Mybaits Generator Config Example

Package com.paincupid.springmvc.persistence;

Import com.paincupid.springmvc.domain.Student;
Import Com.paincupid.springmvc.domain.StudentExample;
Import java.util.List;
Import Org.apache.ibatis.annotations.Param;

Public interface Studentmapper {
    long countbyexample (studentexample example);

    int Deletebyexample (studentexample example);

    int Deletebyprimarykey (Long ID);

    int Insert (Student record);

    int insertselective (Student record);

    List<student> Selectbyexample (studentexample example);

    Student Selectbyprimarykey (Long ID);

    int updatebyexampleselective (@Param ("record") Student record, @Param ("example") studentexample example);

    int Updatebyexample (@Param ("record") Student record, @Param ("example") studentexample example);

    int updatebyprimarykeyselective (Student record);

    int Updatebyprimarykey (Student record);
}
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" > < Mapper namespace= "Com.paincupid.springmvc.persistence.StudentMapper" > <resultmap id= "baseresultmap" type= " Com.paincupid.springmvc.domain.Student "> <!----> <id column=" id "jdbctype=" BIGINT "property= "id"/> <result column= "name" jdbctype= "VARCHAR" property= "name"/> <result column= "height" jdbctype= " DOUBLE "property=" height "/> <result column=" class_no "jdbctype=" INTEGER "property=" Classno "/> <resul t column= "Sex" jdbctype= "BIT" property= "Sex"/> <result column= "IQ" jdbctype= "INTEGER" property= "IQ"/> &  Lt;result column= "Focus" jdbctype= "BIT" property= "Focus"/> <result column= "Cultivate_hobby" jdbctype= "VARCHAR" property= "Cultivatehobby"/> <result column= "Phone" jdbctype= "INTEGER" property= "Phone"/> <rEsult column= "Address" jdbctype= "VARCHAR" property= "Address"/> <result column= "Is_delete" jdbctype= "BIT" proper ty= "Isdelete"/> <result column= "modifier" jdbctype= "VARCHAR" property= "modifier"/> <result column= "g Mt_create "jdbctype=" date "property=" Gmtcreate "/> <result column=" gmt_modified "jdbctype=" date "property=" GmtM Odified "/> <result column=" bak "jdbctype=" VARCHAR "property=" bak "/> </resultMap> <sql id=" Exam Ple_where_clause "> <!----> <where> <foreach collection=" Oredcriteria "item=" Crit Eria "separator=" or "> <if test=" criteria.valid "> <trim prefix=" ("prefixoverrides=" and "Suff
                ix= ")" > <foreach collection= "Criteria.criteria" item= "criterion" > <choose> 
                <when test= "Criterion.novalue" > and ${criterion.condition} </when> <when test= "Criterion.singlevalue" > and ${criterion.condition} #{criterion.value} </whe n> <when test= "Criterion.betweenvalue" > and ${criterion.condition} #{criterion.
                  Value} and #{criterion.secondvalue} </when> <when test= "Criterion.listvalue" > and ${criterion.condition} <foreach close= ")" collection= "Criterion.value" item= "Li Stitem "open=" ("separator=", "> #{listitem} </foreach> < /when> </choose> </foreach> </trim> </if> &lt ;/foreach> </where> </sql> <sql id= "Update_by_example_where_clause" > <!----&
    Gt <where> <foreach collection= "Example.oredcriteria" item= "Criteria" separator= "or" > <if test= " Criteria.valid "&Gt <trim prefix= "(" prefixoverrides= "and" suffix= ")" > <foreach collection= "Criteria.criteria" item= "Crit Erion "> <choose> <when test=" Criterion.novalue "> and ${crit
                  Erion.condition} </when> <when test= "Criterion.singlevalue" > and ${criterion.condition} #{criterion.value} </when> <when test= "CRITERION.BETW
                Eenvalue "> ${criterion.condition} #{criterion.value} and #{criterion.secondvalue}
                  </when> <when test= "Criterion.listvalue" > and ${criterion.condition}
                    <foreach close= ")" collection= "Criterion.value" item= "ListItem" open= "(" separator= "," >
            #{listitem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id=  "Base_column_list" > <!----> ID, name, height, class_no, sex, IQ, focus, cultivate_hobby, phone, Address, is_delete, modifier, gmt_create, gmt_modified, bak </sql> <select id= "Selectbyexample" Paramete 
    Rtype= "Com.paincupid.springmvc.domain.StudentExample" resultmap= "Baseresultmap" > <!----> select <if test= "distinct" > distinct </if> <include refid= "Base_column_list"/> from t_s Tudent <if test= "_parameter! = null" > <include refid= "example_where_clause"/> </if> & 
      Lt;if test= "Orderbyclause! = null" > ORDER by ${orderbyclause} </if> <if test= "Limit! = null" > <if test= "Offset! = null" > Limit ${offset}, ${limit} </if> <if test= "offset = = N Ull "> Limit ${limit} </if> </if> </select> <select id= "Selectbyprimarykey" parametertype= "Java.lang. Long "resultmap=" Baseresultmap "> <!----> select

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.