mysql -- collection一对多查询
2024-09-04 19:59:13
数据库表
角色组表:
CREATE TABLE `sso_character_group` (
`group_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色组ID',
`group_name` varchar(255) DEFAULT NULL COMMENT '角色组名称',
PRIMARY KEY (`group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
角色表:
CREATE TABLE `sso_character` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色ID',
`name` varchar(255) DEFAULT NULL COMMENT '角色名称',
`group_id` int(11) DEFAULT NULL COMMENT '所属角色组ID',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
一个角色组包含多个角色
两个POJO
//CharacterGroup.java
package cn.com.hiveview.entity.module.portal;
import lombok.Data; @Data
public class CharacterCondition {
private Integer id;
private String name;
} //Character.java
package cn.com.hiveview.entity.module.portal; import lombok.Data;
import java.util.List; @Data
public class CharacterGroupCondition {
private Integer groupId;
private String groupName;
private List<CharacterCondition> characterList;
}
controller--mapper层都是直接调用下一层,此处省略
直接上mapper.xml
<resultMap id="characterGroup" type="cn.com.hiveview.entity.module.portal.CharacterGroupCondition">
<id column="group_id" property="groupId"/>
<result column="group_name" property="groupName"/>
<collection property="characterList" column="{groupId=group_id}" select="getCharacterList"/>
</resultMap> <select id="getList" resultMap="characterGroup" parameterType="cn.com.hiveview.entity.module.portal.CharacterGroupCondition">
SELECT group_id,group_name FROM sso_character_group
</select> <select id="getCharacterList" resultType="cn.com.hiveview.entity.module.portal.CharacterCondition">
select id,name from sso_character where group_id=#{groupId}
</select>
结果展示
最新文章
- Android入门(十):界面的布局方式及其实际应用
- Android Studio 自定义debug签名文件keystore
- nodejs events模块
- android 入门-android属性介绍
- VmWare Workstation 10 安装 Ubuntu 14.04 问题解决
- CodeForces 527B Error Correct System
- 利用MiddleGen-hibernate-r5生成hbm文件及POJO文件
- Cocos2d-x 3.0final 终结者系列教程01-无论是从cocos2d-x2.x升级到版本cocos2d-x3.x
- java并发之固定对象与实例
- PHP获取字符串编码与转码
- Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated ?
- BZOJ 3674 可持久化并查集
- 免费ss账号网站
- PowerDesign生成数据库
- 【Java】【路径】
- CS程序中XML编码Encode和解码Decode
- asp.net mvc5 安装
- 【第三章】Shell 变量的数值计算
- (beta冲刺5/7)
- java栈的实现
热门文章
- C#调用smtp邮件发送几个大坑
- PDF.JS 读取文件流前端展示 C#
- Delphi中的Val函数和iif函数(出错的时候,会有索引值)
- 修改Samba密码后无法登录
- 0016 CSS 背景:background
- windows下PostgreSQL 安装与配置
- iptables 添加80端口规则
- java基础之----分布式事务tcc
- 通俗易懂理清mybatis中SqlSessionSql、SqlSessionTemplate、SessionFactory和SqlSessionFactoryBean之间的关系
- 6.python在windows下用批处理文件在运行中输入程序名直接运行的方法