• mybatis注解映射的简单分类


    转自:https://blog.csdn.net/yalishadaa/article/details/56038992

    1、普通映射

        @Select("select * from user where id=#{id}")
        public User getUser(int id);
        @Insert("insert into user(id,name) values (#{id},#{name})")
        public int insert(User user);
        @Update(update user set name=#{name} where id=#{id})
        public int update(User user);
        @Delete("delete from user where id=#{id}")
        public  int delete(int id);

    2、结果集映射

        @Select("select * from user")
        @Results({
                @Result(id=true,property =""id,column = "id")
                @Result(property = "name" column="name")
        })
        public List<User> getAllUsers();

    3、关系映射

    一对一

    @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();  

    一对多

     @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);  
  • 相关阅读:
    将一个dropdownlist从一个div复制到另一个div
    【转】AOP 那点事儿(续集)
    【转】AOP 那点事儿
    spring 简单配置
    spring 基础原理
    jvm简介
    jre、jdk和jvm的关系
    【转】Jvm工作原理
    servlet简述
    Filter简述
  • 原文地址:https://www.cnblogs.com/saifei1125/p/12185803.html
Copyright © 2020-2023  润新知