Mybatis常用注解对应的目标和标签如表所示:

注解 目标 对应的XML标签
@CacheNamespace 类 <cache>
@CacheNamespaceRef 类 <cacheRef>
@Results 方法 <resultMap>
@Result 方法

<result>

<id>

@One 方法 <association>
@Many   方法 <collection>

@Insert

@Update

@Delete

方法

<insert>

<update>

<delete>

@InsertProvider

@UpdateProvider

@DeleteProvider

@SelectProvider

方法

<insert>

<update>

<delete>

<select>

允许创建动态SQL

@Param  参数 N/A
@Options  方法 映射语句的属性
@select 方法 <select>

@Select 简单查询

@Select(" Select * from user ")
@Results({
@Result(id = true, column = "id", property = "id"),
@Result(column = "name", property = "name"),
@Result(column = "tel", property = "tel"),
@Result(column = "birth", property = "birth"),
@Result(column = "address", property = "address")
})
List<User> queryAllUser();

@Insert 简单插入

@Insert(" insert into user(name,sex,age) values(#{name},#{sex},#{age} " )
int saveUser(User user);

@Update 简单更新

@Update("update user set name= #{name} ,sex = #{sex},age =#{age} where id = #{id}")
void updateUserById(User user);

@Delete 简单删除

@Delete("delete from  user  where id =#{id} ")
void deleteById(Integer id);

@One

@Select(" select * from user where id = #{id} ")
@Results(
value = {
@Result(column = "name",property = "name"),
@Result(column = "type",property = "type",
//one指示我们,查询出来的结果只有一个。
one = @One(select="com.xxxx.UserMapper.findTypeById",
//及时加载
fetchType = FetchType.EAGER))
}
)
User findUserById(Integer id);

@Many

 @Select(" select * from dept")
@Results({
@Result(id = true, column = "did", property = "did"),
@Result(column = "name", property = "name"),
@Result(column = "address", property = "address"),
@Result(column = "id",property = "emps",
//many指示我们,查询出来的结果有很多个
many = @Many(
//select = sql语句
select = "com.xxxx.EmpMapper.findAllEmpByDid",
//懒加载
fetchType = FetchType.LAZY))
})
List<Dept> findAllDept();

Mybatis 常用注解的更多相关文章

  1. spring,spring mvc,mybatis 常用注解

    文章来源:https://www.cnblogs.com/hello-tl/p/9209063.html  0.在spring,soring mvc, mybistis 中的常用注解有一下 <! ...

  2. spring注解开发中常用注解以及简单配置

    一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...

  3. SpringBoot | 第六章:常用注解介绍及简单使用

    前言 之前几个章节,大部分都是算介绍springboot的一些外围配置,比如日志配置等.这章节开始,开始总结一些关于springboot的综合开发的知识点.由于SpringBoot本身是基于Sprin ...

  4. springboot部分常用注解

    目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...

  5. spring常用注解笔记

    spring常用注解解释: 1. Mybatis的映射文件xxxMapper.xml中resultMap标签的作用 resultMap标签是为了映射select查询出来结果的集合,其主要 作用是将实体 ...

  6. mybatis使用注解替代xml配置,动态生成Sql

    mybatis使用注解替代xml配置时,遇到判断条件是否为null或者为空时,@Select很难搞定,不知道怎么办? mybatis3中增加了使用注解来配置Mapper的新特性,使用 SelectPr ...

  7. SpringBoot系列-整合Mybatis(注解方式)

    目录 一.常用注解说明 二.实战 三.测试 四.注意事项 上一篇文章<SpringBoot系列-整合Mybatis(XML配置方式)>介绍了XML配置方式整合的过程,本文介绍下Spring ...

  8. spring boot的一些常用注解

    spring boot的一些常用注解: 使用@SpringBootApplication注释: 许多Spring Boot开发人员喜欢他们的应用程序使用自动配置,组件扫描,并能够在其“应用程序类”上定 ...

  9. Spring+Mybatis基于注解整合Redis

    基于这段时间折腾redis遇到了各种问题,想着整理一下.本文主要介绍基于Spring+Mybatis以注解的形式整合Redis.废话少说,进入正题. 首先准备Redis,我下的是Windows版,下载 ...

随机推荐

  1. VS2019 实用操作

    本文列出了在编写程序过程中的几个非常实用的操作方式,通过这些操作方式,可以在一定程度上减少重复操作.提高编码效率.改善编程体验. 列模式操作 列操作是一项很常用且实用的功能,可以一次性修改不同的行. ...

  2. Map the Debris 轨道周期

    返回一个数组,其内容是把原数组中对应元素的平均海拔转换成其对应的轨道周期. 原数组中会包含格式化的对象内容,像这样 {name: 'name', avgAlt: avgAlt}. 至于轨道周期怎么求, ...

  3. DAY19、日常模块

    一.hashlib模块:加密1.基本使用:import hashlibcipher = hashlib.md5('需要加密的数据(二进制形式)'.encode('utf-8'))print(ciphe ...

  4. 搭建Eureka注册中心

    创建一个Spring Boot工程,命名为eureka-server,并在pom.xml中引入必要的依赖,代码如下. <parent> <groupId>org.springf ...

  5. macbook 入门

    前面的话 第一次使用 Mac 之前,需要改变一些原有思维,不应该使用 Windows 的思维习惯去使用 Mac,Mac 会节省系统维护.清理杀毒.升级驱动等操作的时间,让我们可以专注做真正重要的事情, ...

  6. Oracle查询所有表的字段明细

    SELECT USER_TAB_COLS.TABLE_NAME as 表名, UTC.COMMENTS as 表中文名, USER_TAB_COLS.COLUMN_ID as 列序号, USER_TA ...

  7. Verilog语言实现并行(循环冗余码)CRC校验

    1 前言 (1)    什么是CRC校验? CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能, ...

  8. 1.0--->刚开始看这里

    PyQt5使用笔记 创建一个小窗口 import sys from PyQt5.QtWidgets import * #程序实例化 app = QApplication(sys.argv) # #创建 ...

  9. Spring项目使用Junit4测试配置

    我们经常要写junit测试,在不启动整个web项目的情况下,测试自己的service实现或者是dao实现,我们来充分利用下junit4的强大功能. 1.junit4的测试类 import java.u ...

  10. 为vue添加公用方法,vue添加通用方法

    common.js var common =function() { return{ f1:function(){ console.log("this is common f1().&quo ...