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版,下载 ... 
随机推荐
- python读写excel文件
			'''xlrd和xlwt处理的是xls文件,单个sheet最大行数是65535,如果有更大需要的,建议使用openpyxl函数,最大行数达到1048576.'''import openpyxl ''' ... 
- Idea中最最常见的快捷键
			掌握如下快捷键,基本就够用了.没必要记那么多. Ø 命令:Ctrl+Shift+A可以查找所有Intellij的命令,并且每个命令后面还有其快捷键.所以它不仅是一大神键,也是查找学习快捷键的工具. ... 
- WEB工具类
			import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; ... 
- Django3 Django 路由分发,反向解析,2.0版本的path
			urls配置像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是以这种方式告诉Django,对于客户端发来的某个URL调用哪一段逻辑代码对应执行. 1.简 ... 
- PS 怎么去掉图片上的文字
			第一步:打开需要去掉文字的图片. 第二步:在左侧工具栏中选择“吸管工具”. 第三步:在文字附近选取颜色. 第四步:在左侧工具栏中选择“矩形选框工具”,并选中要消除的文字. 第五步:在菜单栏“编辑”中选 ... 
- Appium环境搭建-完整版
			环境依赖 Node.js Appium Appium-desktop Appium-doctor Appium-Python-Client Python JDK Andriod SDK 以上所需的软件 ... 
- ES6和CommonJS的区别 以及 export和module.exports的区别
			ES6和CommonJS的区别 Javascript javascript是一种脚本编程语言,有自己独立的语法与语义,没有javascript,也就没有其他的那些概念了. ES6 JavaScript ... 
- ppi
			<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ... 
- Oracle篇 之 多表查询
			一.概念 从多个表中查询数据时,需要在表和表间建立连接,一般使用主外键建立连接 二.连接种类 1. 等连接:连接条件使用等号 非等连接:连接条件使用等号以外的其它符号 2. 内连接:根据指定的连接条件 ... 
- 【AGC030D】Inversion Sum DP
			题目大意 有一个序列 \(a_1,a_2,\ldots,a_n\),有 \(q\) 次操作,每次操作给你两个数 \(x,y\),你可以交换 \(a_x,a_y\),或者什么都不做. 问你所有 \(2^ ... 
