Mybatis多对多处理
来源:互联网 发布:ubuntu如何设置源 编辑:程序博客网 时间:2024/05/02 00:25
1. 数据库中建立 3张表,2个对象,一张关联表
2. 关联表对应java 对象
private int id; private DataTag dataTag; private StorageData storageData;
3. DataTag
private int tagId; private String tagName; private int parent; private String userId; private List<StorageData> storageDataList;
4. StorageData
private String dataId; private String description; private byte[] content; private String fileName; private String ext;
根据需求决定对象是否加另一对象的List,通过tag要找dataList,所以tag中含 storageDataList
5.xml
<resultMap type="DataTag" id="dataTagMap"> <id property="tagId" column="tagId" /> <result property="tagName" column="tagName" /> <result property="parent" column="parent" /> <result property="userId" column="userId" /> </resultMap> <resultMap type="DataTag" id="dataTagStorageDataMap" extends="dataTagMap"> <collection property="storageDataList" ofType="StorageData"> <id property="dataId" column="dataId" /> <result property="description" column="description" /> <result property="ext" column="ext" /> <result property="fileName" column="fileName" /> <result property="content" column="content" /> </collection> </resultMap>
<select id="findTagByUserId" parameterType="string" resultMap="dataTagStorageDataMap"> SELECT t.tagId, t.tagName, t.parent, t.userId, d.dataId, d.description, d.ext, d.fileName, d.content FROM t_tag t LEFT JOIN t_tag_storage_data td ON t.tagId = td.tagId LEFT JOIN t_storage_data d ON td.dataId = d.dataId WHERE userId = #{userId} </select>
6. 插入操作,维护关系表
在stoargeData 中加
public void saveRelativity(TagStorageDataLink tagDataLink);
0 0
- Mybatis多对多处理
- mybatis 多对多 处理
- mybatis 多对多 处理
- mybatis多对多处理
- mybatis 多对多 处理
- mybatis多对多处理
- mybatis 多对多 处理
- mybatis 多对多 处理
- Mybatis多对一的处理
- mybatis 多对一,xml 文件的处理 学习总结
- mybatis 多对多
- Mybatis 多对多
- Mybatis多对多
- mybatis 多对多
- Mybatis多对一
- myBatis多对一
- mybatis多对一单表
- Mybatis 一对一,一对多,多对一,多对多 的处理
- colordialog对象在delphi中哪里加入
- eclipse修改字体大小
- qt GUI程序 改为控制台程序
- get、set、value、partial、where 、yield 上下文关键字
- MAC 下用到的命令
- Mybatis多对多处理
- innoDB同时支持多个BufferPool实例
- 《Cortex™-A系列编程者指南(V3.0)》第13章<中断处理>笔记
- HDU 1176 免费馅饼 数塔
- (将考核合格)发光体
- Linux kernel driver model
- YUV(YUV422、YUV420) 转RGB24
- 华为C语言笔试题集合
- 嵌入式 procfs编程小结