Mybatis 常用注解
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 常用注解的更多相关文章
- spring,spring mvc,mybatis 常用注解
文章来源:https://www.cnblogs.com/hello-tl/p/9209063.html 0.在spring,soring mvc, mybistis 中的常用注解有一下 <! ...
- spring注解开发中常用注解以及简单配置
一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...
- SpringBoot | 第六章:常用注解介绍及简单使用
前言 之前几个章节,大部分都是算介绍springboot的一些外围配置,比如日志配置等.这章节开始,开始总结一些关于springboot的综合开发的知识点.由于SpringBoot本身是基于Sprin ...
- springboot部分常用注解
目录:[持续更新.....] spring 部分常用注解 spring boot 学习之路1(简单入门) spring boot 学习之路2(注解介绍) spring boot 学习之路3( 集成my ...
- spring常用注解笔记
spring常用注解解释: 1. Mybatis的映射文件xxxMapper.xml中resultMap标签的作用 resultMap标签是为了映射select查询出来结果的集合,其主要 作用是将实体 ...
- mybatis使用注解替代xml配置,动态生成Sql
mybatis使用注解替代xml配置时,遇到判断条件是否为null或者为空时,@Select很难搞定,不知道怎么办? mybatis3中增加了使用注解来配置Mapper的新特性,使用 SelectPr ...
- SpringBoot系列-整合Mybatis(注解方式)
目录 一.常用注解说明 二.实战 三.测试 四.注意事项 上一篇文章<SpringBoot系列-整合Mybatis(XML配置方式)>介绍了XML配置方式整合的过程,本文介绍下Spring ...
- spring boot的一些常用注解
spring boot的一些常用注解: 使用@SpringBootApplication注释: 许多Spring Boot开发人员喜欢他们的应用程序使用自动配置,组件扫描,并能够在其“应用程序类”上定 ...
- Spring+Mybatis基于注解整合Redis
基于这段时间折腾redis遇到了各种问题,想着整理一下.本文主要介绍基于Spring+Mybatis以注解的形式整合Redis.废话少说,进入正题. 首先准备Redis,我下的是Windows版,下载 ...
随机推荐
- vue 中 assets 和 static 的区别
Vue中的静态资源管理(src下的assets和static文件夹的区别)
- quotes 整站数据爬取存mongo
安装完成scrapy后爬取部分信息已经不能满足躁动的心了,那么试试http://quotes.toscrape.com/整站数据爬取 第一部分 项目创建 1.进入到存储项目的文件夹,执行指令 scra ...
- Linux(Ubuntu)使用日记------为程序添加桌面快捷方式
我们Ubuntu中的所以的程序的快捷方式都放在了/usr/share/applications文件夹下,都是以.desktop结尾的文件.我们可以在这个文件夹下创建我们的快捷方式,然后复制到桌面即可 ...
- 新建promise
callback(){ const promise =new Promise((resolve,rejest)=>{ console.log('2') 代码 resolve('true') }) ...
- C博客作业01--分支、顺序结构
1.本章学习总结 1.1 思维导图 1.2 本章学习体会及代码量学习体会 1.2.1 学习体会 在暑假已经有初步接触c语言,所以在学习c语言的开始会比较轻松,但仍然解题时候步骤太过于繁琐,简单的题目复 ...
- [ffmpeg] 定制滤波器
如果有定制ffmpeg滤波器的需求,有两个结构体是必须要了解的:AVFilter.AVFilterPad,所定制的滤波器主要就是通过填充这两个结构体来实现的.我们下面将详细解析这两个结构体,并通过对滤 ...
- BZOJ3236[Ahoi2013]作业——莫队+树状数组/莫队+分块
题目描述 输入 输出 样例输入 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 样例输出 2 2 1 1 3 2 2 1 提示 N=100000,M=1000000 ...
- PHP——??空合并运算符和?:三元运算符
前言 在上一篇随笔,用三元运算符简单写的一个东西,引发了对他的兴趣,所以打算研究下. PHP7的新特性: https://php.net/manual/zh/migration70.new-featu ...
- P1536 村村通
原题链接 https://www.luogu.org/problemnew/show/P1536 昨天刚学的并查集,今天正好练习一下,于是就找到了这个题 看起来好像很简单,尤其是你明白了思路之后,完全 ...
- webpack中跨域请求proxy代理(vue与react脚手架不同设置方法)
因为浏览器有同源策略的限制,导致我们在本地开发的时候,请求不同域名的接口会存在跨域的问题 解决跨域的问题有很多方式,这里主要整理下代理模式来解决跨域的问题 代理方式能够实现的机制大体: 本地服务器 - ...