MyBatis通过注解实现映射中的嵌套语句和嵌套结果
案例描述:查看订单或购物车订单信息的同时查询出该订单中所有书籍的信息。
一、嵌套语句
@Select("select* from shopcart where shopcartid = #{id}")
@Results({ @Result(id = true, column = "shopcartid", property = "shopCartId"),
@Result(column = "bookid", property = "bookId"), @Result(column = "amount", property = "amount"),
@Result(column = "price", property = "price"), @Result(column = "status", property = "status"),
@Result(column = "bookid", property = "book", one = @One(select = "com.yh.mybatis.mapper.BookMapper.findBookInfoById")) })
ShopCart findShopCartInfoById(int id);
二、嵌套结果
// 查找刚刚添加的订单信息
@Select("select orderinfo.*,book.bookname,book.imgurl,book.introduction,book.packstyle,book.sellerid,book.price bookprice from orderinfo,book where orderinfo.bookid = book.bookid and orderid like '${orderId}%'")
@Results({ @Result(id = true, column = "identityid", property = "identityId"),
@Result(column = "orderid", property = "orderId"), @Result(column = "buyerid", property = "buyerId"),
@Result(column = "bookid", property = "bookId"), @Result(column = "amount", property = "amount"),
@Result(column = "orderdate", property = "orderDate"), @Result(column = "express", property = "express"),
@Result(column = "payment", property = "payment"), @Result(column = "addressid", property = "addressId"),
@Result(column = "price", property = "price"), @Result(column = "message", property = "message"),
@Result(column = "status", property = "status"),
// 自定义类成员变量的属性
@Result(column = "bookname", property = "book.bookName"),
@Result(column = "sellerid", property = "book.sellerId"),
@Result(column = "bookprice", property = "book.price"),
@Result(column = "imgurl", property = "book.imgUrl"),
@Result(column = "introduction", property = "book.introduction"),
@Result(column = "packstyle", property = "book.packStyle") })
List<Order> findLastOrder(@Param("orderId") String orderId);
MyBatis通过注解实现映射中的嵌套语句和嵌套结果的更多相关文章
- SQL Server中INSERT EXEC语句不能嵌套使用(转载)
问: I have three stored procedures Sp1, Sp2 and Sp3.The first one (Sp1) will execute the second one ( ...
- mybatis 使用注解简化xml映射文件
目录 关于mybatis注解 初次简单使用mybatis注解示例 利用注解实现指定映射 使用注解实现表间关联(1对1) 关于mybatis注解 注解在java中特别常见,mybatis中也支持注解. ...
- 小峰mybatis(4)mybatis使用注解配置sql映射器
主流开发还是使用xml来配置:使用注解配置比较快,但是不支持所有功能:有些功能还是得用配置文件: 一.基本映射语句: @Inert @Update @Delete @Select 二.结果集映射语句 ...
- 【Mybatis架构】Mapper映射文件中的#{}与${}
前言 还记得当初从北京回来的时候,跟着倪文杰师姐做JavaITOO的一卡通模块,我亲姐贾梦洁带着我一块做,期间,我遇到了一个特别奇葩的问题,就死我要实现Mybatis的模糊查询,根据当时亲姐教给我方法 ...
- 小峰mybatis(5)mybatis使用注解配置sql映射器--动态sql
一.使用注解配置映射器 动态sql: 用的并不是很多,了解下: Student.java 实体bean: package com.cy.model; public class Student{ pri ...
- MyBatis 源码分析 - 映射文件解析过程
1.简介 在上一篇文章中,我详细分析了 MyBatis 配置文件的解析过程.由于上一篇文章的篇幅比较大,加之映射文件解析过程也比较复杂的原因.所以我将映射文件解析过程的分析内容从上一篇文章中抽取出来, ...
- mybatis学习(一)-------XML 映射配置文件详解
XML 映射配置文件 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置(settings)和属性(properties)信息.文档的顶层结构如下: configuration 配 ...
- Spring+Mybatis基于注解整合Redis
基于这段时间折腾redis遇到了各种问题,想着整理一下.本文主要介绍基于Spring+Mybatis以注解的形式整合Redis.废话少说,进入正题. 首先准备Redis,我下的是Windows版,下载 ...
- 【转载】Mybatis多参数查询映射
转载地址:http://www.07net01.com/zhishi/402787.html 最近在做一个Mybatis的项目,由于是接触不久,虽然看了一下资料,但在实际开发中还是暴 露了很多问题,其 ...
随机推荐
- selenium基本使用,及cannot find chrome binary解决方案
什么是selenium? Selenium是一个用于Web应用程序测试的工具. Selenium 测试直接运行在浏览器中,就像真正的用户在操作一样. 支持通过各种driver(FirfoxDriver ...
- 如何将rabbitmq集群中的某个节点移除.
首先将要移除的节点停机. root@rabbitmq-03:~# rabbitmqctl stop Stopping and halting node 'rabbit@rabbitmq-03' ... ...
- request.setAttribute()和session.setAttribute()的区别详解
我们在Servlet和页面间传值时,经常会用到request.setAttribute()和session.setAttribute(),下面是两段示例用法 request.setAttribute( ...
- linux的ip文件参数说明
TYPE=Ethernet # 网卡类型:为以太网 PROXY_METHOD=none # 代理方式:关闭状态 BROWSER_ONLY=no # 只是浏览器:否 BOOTPROTO=dhcp # 网 ...
- SpringCloud升级之路2020.0.x版-45. 实现公共日志记录
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 我们这一节在前面实现的带有链路信息的 Publisher 的工厂的基础上,实现公共日志记录 ...
- 洛谷 P7360 -「JZOI-1」红包(Min-Max 容斥+推式子)
洛谷题面传送门 hot tea. 首先注意到这个 \(\text{lcm}\) 特别棘手,并且这里的 \(k\) 大得离谱,我们也没办法直接枚举每个质因子的贡献来计算答案.不过考虑到如果我们把这里的 ...
- 洛谷 P6772 - [NOI2020]美食家(广义矩阵快速幂)
题面传送门 题意: 有一张 \(n\) 个点 \(m\) 条边的有向图,第 \(0\) 天的时候你在 \(1\) 号城市,第 \(T\) 天的时候你要回到 \(1\) 号城市. 每条边上的边权表示从城 ...
- Codeforces 590E - Birthday(AC 自动机+Dilworth 定理+二分图匹配)
题面传送门 AC 自动机有时只是辅助建图的工具,真的 首先看到多串问题,果断建出 AC 自动机.设 \(m=\sum|s_i|\). 不难发现子串的包含关系构成了一个偏序集,于是我们考虑转化为图论,若 ...
- Codeforces 685C - Optimal Point(分类讨论+乱搞)
Codeforces 题面传送门 & 洛谷题面传送门 分类讨论神题. 首先看到最大值最小,一眼二分答案,于是问题转化为判定性问题,即是否 \(\exists x_0,y_0,z_0\) 满足 ...
- 【Linux】tmux安装(非root)及其使用
tmux(terminal multiplexer)是Linux上的终端复用神器. 1. 安装 (1)下载 下载及其依赖软件. wget -c https://github.com/tmux/tmux ...