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);
最新文章
- Nginx的启动脚本(Centos)
- win7、linux安装使用pip、mitmproxy
- 设计模式之美:Composite(组合)
- sql语句查询数据库表结构信息
- [SAP ABAP开发技术总结]数据输入输出转换、小数位/单位/货币格式化
- 安卓 Dialogs(对话框)
- iOS开发中遇到的头文件找不到的问题解决办法
- nginx服务器绑定域名和设置根目录
- SQL日语词汇
- IOS 第三方开源库记录
- B. Fixed Points
- myeclipse中自己手动配置maven
- NLP 苏图南 打破自我设限 突破自我—在线播放—优酷网,视频高清在线观看
- geodocker-geomesa安装指南
- Aooms_微服务基础开发平台实战_002_工程构建
- linux下用ctrl+r快速搜索history命令
- 「Android」SurfaceFlinger分析
- 逻辑运算的妙用-Single Number
- CORS jsonp
- Linux-lvm逻辑卷管理和提示丢失pv物理卷
热门文章
- java的多线程和并发库
- @property &; @synthesize &; @dynamic 及相关属性作用探究
- Model验证简单易懂
- c# Reverse()的两点用法
- chrome浏览器页面获取绑定返回顶部动画事件插件
- 树莓派3B+学习笔记:7、挂载exfat格式U盘
- MIPI调试经验(转载)
- STM32 Startup**.s文件中使用的 __main C函数入口
- 第一篇随笔, 正在做 ESP32 , STM32 , 树莓派 RaspberryPi 的创客工具
- 使用xadmin更新数据时,报错expected string or bytes-like object