zoukankan      html  css  js  c++  java
  • Mybatis中的几种注解映射

    1、  普通映射

    2、 @Select("select * from mybatis_Student where id=#{id}")    

    3、 public Student getStudent(int id);    

    4、 @Insert("insert into mybatis_Student (name, age, remark, pic,grade_id,address_id) values (#{name},#{age},#{remark}, #{pic},#{grade.id},#{address.id})")    

    5、 public int insert(Student student);    

    6、 @Update("update mybatis_Student set name=#{name},age=#{age} where id=#{id}")    

    7、 public int update(Student student);    

    8、 @Delete("delete from mybatis_Student where id=#{id}")    

    9、 public int delete(int id);  

    2、结果集映射

    @Select("select * from mybatis_Student")    

    @Results({    

     @Result(id=true,property="id",column="id"),    

        @Result(property="name",column="name"),    

      @Result(property="age",column="age")    

    })    

    public List<Student> getAllStudents(); 

    3、关系映射

    3.1、一对一

    @Select("select * from mybatis_Student")    

    @Results({    

     @Result(id=true,property="id",column="id"),    

    @Result(property="name",column="name"),    

    @Result(property="age",column="age"),    

      @Result(property="address",column="address_id",one=@One(select="com.skymr.mybatis.mappers.AddressMapper.getAddress"))    

    })    

    public List<Student> getAllStudents();  

    3.2、一对多

    @Select("select * from mybatis_grade where id=#{id}")      @Results({          @Result(id=true,column="id",property="id"),          @Result(column="grade_name",property="gradeName"),       @Result(property="students",column="id",many=@Many(select="com.skymr.mybatis.mappers.Student2Mapper.getStudentsByGradeId"))      })    

       public Grade getGrade(int id); 

  • 相关阅读:
    hdu 1290 献给杭电五十周年校庆的礼物 (DP)
    hdu 3123 GCC (数学)
    hdu 1207 汉诺塔II (DP)
    hdu 1267 下沙的沙子有几粒? (DP)
    hdu 1249 三角形 (DP)
    hdu 2132 An easy problem (递推)
    hdu 2139 Calculate the formula (递推)
    hdu 1284 钱币兑换问题 (DP)
    hdu 4151 The Special Number (DP)
    hdu 1143 Tri Tiling (DP)
  • 原文地址:https://www.cnblogs.com/-zpy/p/8654148.html
Copyright © 2011-2022 走看看