MyBatis的基本注解:

增删改查

@Select("select * from teacher")

 public List<Teacher> selAll();

 //增删改返回值都是int

 @Insert("insert into teacher values(default,#{name})")

 public int add(Teacher teacher);

 @Update("update teacher set name=#{name} where id=#{id}")

 public int update(Teacher teacher);

 @Delete("delete from teacher where id=#{id}")

 public int delete(int id);

  

MyBatis映射

1.普通映射

@Select("select * from mybatis_Student where id=#{id}")
public Student getStudent(int id);
@Insert("insert into mybatis_Student (name, age, remark, pic,grade_id,address_id) values (#{name},#{age},#{remark}, #{pic},#{grade.id},#{address.id})")
public int insert(Student student);
@Update("update mybatis_Student set name=#{name},age=#{age} where id=#{id}")
public int update(Student student);
@Delete("delete from mybatis_Student where id=#{id}")
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.关系映射

一对一

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

  

MyBatis的基本注解的更多相关文章

  1. Mybatis的@Options注解

    mybatis的@Options注解能够设置缓存时间,能够为对象生成自增的key 第一个使用场景: 有一个表 CREATE TABLE instance ( instance_id BIGINT UN ...

  2. mybatis 使用@Select 注解,因为字符编码不一致导致mybatis 报错

    使用 mybatis 的@Select 注解, @Select({ "<script>select " + ALL_COLUMNS + " from &quo ...

  3. SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版)

    SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版) ================================ ©Copyright 蕃薯耀 2 ...

  4. 关于Mybatis的@Param注解 及 mybatis Mapper中各种传递参数的方法

    原文:https://blog.csdn.net/mrqiang9001/article/details/79520436 关于Mybatis的@Param注解   Mybatis 作为一个轻量级的数 ...

  5. Mybatis基于接口注解配置SQL映射器(二)

    Mybatis之增强型注解 MyBatis提供了简单的Java注解,使得我们可以不配置XML格式的Mapper文件,也能方便的编写简单的数据库操作代码.但是注解对动态SQL的支持一直差强人意,即使My ...

  6. Mybatis基于接口注解配置SQL映射器(一)

    上文已经讲解了基于XML配置的SQL映射器,在XML配置的基础上MyBatis提供了简单的Java注解,使得我们可以不配置XML格式的Mapper文件,也能方便的编写简单的数据库操作代码. Mybat ...

  7. Spring Boot入门系列(十九)整合mybatis,使用注解实现动态Sql、参数传递等常用操作!

    前面介绍了Spring Boot 整合mybatis 使用注解的方式实现数据库操作,介绍了如何自动生成注解版的mapper 和pojo类. 接下来介绍使用mybatis 常用注解以及如何传参数等数据库 ...

  8. Mybatis框架基于注解的方式,实对数据现增删改查

    编写Mybatis代码,与spring不一样,不需要导入插件,只需导入架包即可: 在lib下 导入mybatis架包:mybatis-3.1.1.jarmysql驱动架包:mysql-connecto ...

  9. SpringBoot整合Mybatis【非注解版】

    接上文:SpringBoot整合Mybatis[注解版] 一.项目创建 新建一个工程 ​ 选择Spring Initializr,配置JDK版本 ​ 输入项目名 ​ 选择构建web项目所需的state ...

随机推荐

  1. 用例建模Use Case Modeling——传感器智能分析引擎

    系统用例分析 我的工程实践小组做的课题主要是实现传感器数据采集平台的设计与开发.该搜索引擎完成对传感器数据的采集和发布,企业可以在平台上上传自己的传感器数据信息,同时也能够浏览市面上其他传感器信息,以 ...

  2. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  3. OpenCV3入门(八)图像边缘检测

    1.边缘检测基础 图像的边缘是图像的基本特征,边缘点是灰度阶跃变化的像素点,即灰度值的导数较大或极大的地方,边缘检测是图像识别的第一步.用图像的一阶微分和二阶微分来增强图像的灰度跳变,而边缘也就是灰度 ...

  4. space transport protocols

    VSAT系统对TCP的改进 https://www.vsat-systems.com/broadband-satellite-internet/index.html TCP/IP over satel ...

  5. k8s系列---存储卷pv/pvc。configMap/secert

    因为pod是有生命周期的,pod一重启,里面的数据就没了.所以我们需要数据持久化存储. 在k8s中,存储卷不属于容器,而是属于pod.也就是说同一个pod中的容器可以共享一个存储卷. 存储卷可以是宿主 ...

  6. HDU 1017 直接暴力。

    C - 3 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  7. lua学习之深入函数第二篇

    深入函数 2 非全局的函数 函数是第一类值,函数可以存储到全局变量,局部变量,table 字段中 lua 函数库中的大部分函数存储到 table 字段中 Lib = {} Lib.foo = func ...

  8. pyHamcrest

    概念 Hamcrest是用于编写匹配器对象的框架.他提供了一套匹配符Matcher,这些匹配符更接近自然语言,可读性高,更加灵活.Hamcrest还有很好的可扩展性,能够创建自定义的匹配器. 支持语言 ...

  9. Oracle Linux下安装Oracle11gR2

    Linux上Oracle11g R2安装及配置 一. 安装环境准备 1.  环境说明 Linux服务器系统:Oracle Linux Release 6 Update 2 (64bit),先安装好. ...

  10. asp.net网站作为websocket服务端的应用该如何写

    最近被websocket的一个问题困扰了很久,有一个需求是在web网站中搭建websocket服务.客户端通过网页与服务器建立连接,然后服务器根据ip给客户端网页发送信息. 其实,这个需求并不难,只是 ...