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. 洛谷 P1962 斐波那契数列

    题目链接:https://www.luogu.org/problemnew/show/P1962 题目大意: 略 分析: 由于数据规模很大,需要用矩阵快速幂来解. 代码如下: #pragma GCC ...

  2. Maven版本不一致的时候,使用指定版本进行编译

    最近用Maven打包项目(本地jdk11)后放到服务器(jdk8)后,报[java.lang.UnsupportedClassVersionError]版本不一致错误. 网上资料说是修改Intelli ...

  3. Nginx Http 过滤模块

    L69 执行顺序在content阶段后 log阶段前调用的 也就是处理完用户业务后 准备记录处理日志之前 我们可以到nginx http_model.c里查看 数组 执行顺序从下至上顺序执行 copy ...

  4. python爬虫基础应用----爬取校花网视频

    一.爬虫简单介绍 爬虫是什么? 爬虫是首先使用模拟浏览器访问网站获取数据,然后通过解析过滤获得有价值的信息,最后保存到到自己库中的程序. 爬虫程序包括哪些模块? python中的爬虫程序主要包括,re ...

  5. Keras 获取中间某一层输出

    1.使用函数模型API,新建一个model,将输入和输出定义为原来的model的输入和想要的那一层的输出,然后重新进行predict. #coding=utf-8 import seaborn as ...

  6. postgresSQL 实现数据修改后,自动更新updated_date/ts等字段

    1. 需求说明: 实现MYSQL中有on update CURRENT_TIMESTAMP 2. 需求分析 由于数据库迁移需要将MYSQL中的数据迁移到postgresSQL中,由于MYSQL中有on ...

  7. content-type 组件

    content-type初识 什么是content-type ContentType是Django的内置的一个应用,可以追踪项目中所有的APP和model的对应关系,并记录在ContentType表中 ...

  8. 20175209 《Arrays和String单元测试》

    20175209 <Arrays和String单元测试> 题目 在IDEA中以TDD的方式对String类和Arrays类进行学习,测试相关方法的正常,错误和边界情况 String类 ch ...

  9. 分析web.xml

    <?xml version="1.0" encoding="UTF-8"?>  //xml的版本:1.0 和 编码:utf-8 <web-ap ...

  10. Word转PDF(SaveAsPDFandXPS + jacob)

    Windows系统下 1.下载所需插件和jar包 SaveAsPDFandXPS(微软自带office转PDF.XPS):http://www.microsoft.com/zh-cn/download ...