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版,下载 ...
随机推荐
- Nginx配置http跳转https访问
Nginx强制http跳转https访问有以下几个方法 nginx的rewrite方法 可以把所有的HTTP请求通过rewrite重写到HTTPS上 配置 方法一 server{ listen ; s ...
- win 解压安装mysql步骤
5 安装成功之后,启动mysql时报错: 系统错误2,找不到指定的文件.原因:有的系统安装过MySQL没有卸载干净,或者系统自带精简版的MySQL导致注册表关于MySQL的配置与实际安装路径不一致. ...
- [转帖]Zoom
Zoom美国上市:华裔创始人为大股东 创业想法来自“异地恋” https://baijiahao.baidu.com/s?id=1631166070308020680&wfr=spider&a ...
- Kafka如何保证消息的顺序性
1. 问题 比如说我们建了一个 topic,有三个 partition.生产者在写的时候,其实可以指定一个 key,比如说我们指定了某个订单 id 作为 key,那么这个订单相关的数据,一定会被分发到 ...
- [数据库] windows server 2003下mysql出现10048错误的解决办法 Can't connect to MySQL server on '127.0.0.1' (10048)(抄)
网站访问量大了的时候mysql连接数自然就多了,当超出mysql最大连接数的时候就会出现错误,当出现too many字样的错误的时候一般是因为连接数的问题,只需要修改最大连接数max_conectio ...
- Django_rest framework 框架介绍
restful介绍 restful协议 一切皆是资源,操作只是请求方式 URL 设计 原先的URL设计方式 在url 中体现出操作行为 /books/ books /books/add/ addbo ...
- python@wraps实现原理
@wraps作用 python中的装饰器装饰过的函数其实就不是函数本身了,我们可以看看下面的例子 import time def timmer(func): """tim ...
- 【学习笔记】JS知识点整理
1 原型/原型链 1-1 原型 定义:原型是function对象的一个属性,定义了构造函数制造出的对象的公共祖先.通过该构造函数产生的对象,可以继承该原型的属性和方法. 原型是一个对象. 可以利用原型 ...
- vue axios使用方法
首先安装axios: cnpm install axios -save 安装成功后,在main.js页面引用: import axios from 'axios' import Qs from 'qs ...
- codeblocks(其它软件)修改后缀文件的打开默认方式