@问题:
三表联查:123
关系:1与2为一对多的关系,2与3为一对一关系
表1:
表2:
表3:
<id column="organize_id" jdbcType="INTEGER" property="organizeId" />
<result column="big_organize_id" jdbcType="INTEGER" property="bigOrganizeId" />
<result column="organize_name" jdbcType="VARCHAR" property="organizeName" />
<result column="big_organize_name" jdbcType="VARCHAR" property="bigOrganizeName" />
<collection property="tbActionDetailEntityList" javaType="java.util.ArrayList" ofType="com.gw.scm.provider.commons.entity.TbActionDetailEntity">
<result column="action_id" jdbcType="INTEGER" property="actionId" />
<result column="action_name" jdbcType="VARCHAR" property="actionName" />
<result column="organize_name" jdbcType="VARCHAR" property="organizeName" />
<result column="action_description" jdbcType="VARCHAR" property="actionDescription" />
<result column="action_result" jdbcType="VARCHAR" property="actionResult" />
<association property="tbActionEntity" javaType="com.gw.scm.provider.commons.entity.TbActionEntity">
<result column="goal_id" jdbcType="INTEGER" property="goalId" />
<result column="goal_name" jdbcType="VARCHAR" property="goalName" />
<result column="goal_progress_content" jdbcType="VARCHAR" property="goalProgressContent" />
<result column="action_name" jdbcType="VARCHAR" property="actionName" />
<result column="action_person" jdbcType="VARCHAR" property="actionPerson" />
<result column="action_plan_start_time" jdbcType="VARCHAR" property="actionPlanStartTime" />
<result column="action_plan_end_time" jdbcType="VARCHAR" property="actionPlanEndTime" />
<result column="action_status" jdbcType="VARCHAR" property="actionStatus" /></association>
</collection>
</resultMap>
<select id="getMapByBigOrganizeId" parameterType="com.gw.scm.provider.commons.entity.TbOrganizeEntity" resultMap="NewResultMap">
select *
from tb_organize t1
inner join tb_action_detail t2
on t1.organize_id=t2.organize_id
inner join tb_action t3
on t2.action_id=t3.action_id
where t1.big_organize_id = #{bigOrganizeId}
</select>
1、如果表一与表二中的主键一样就把第二个表的主键在xml文件中配置时候改个别名(百度一下有很多博客)
2、在表1的实体类中要加入表2的实体集合(必须是集合,如果实体跟集合同时存在表1实体类中可能出现不识别集合,只识别实体情况,就会只返回一条数据)
如果是一对多对多情况就把标签换成标签并且按照上面的逻辑在实体类中写集合
出现返回数据是全的但是字段数据都是null表示实体类中的集合属性没有生效,将集合属性删掉重新写一下,然后清理一下idea缓存,再启动项目
关联查询mybatis框架标签
1、学生表和衣品表
create table STUDENT(
ID NUMBER(38,0) GENERATED BY DEFAULT ON NULL AS IDENTITY CONSTRAINT STUDENT_ID_PK PRIMARY KEY,
NAME VARCHAR2(100) NOT NULL
);
create table CLOTHES(
ID NUMBER(38,0) GENERATED BY DEFAULT ON NULL AS IDENTITY CONSTRAINT CLOTHES_ID_PK PRIMARY KEY,
STUDENT_ID NUMBER(38,0),
NAME VARCHAR2(100) NOT NULL
);
2、需求:查询一个学生多套衣服
1、创建返回vo(包含学生表字段以及衣品对象)
2、编写查学生表sql,正常写,返回值要返回一个自定义resultMap,衣品查询正常写,条件正常写
<select id="selectStudent" parameterType="com.xxx.entity.Student" resultMap="recordMap" fetchSize="50">
select * from Student
</select>
<select id="selectSubList" parameterType="java.lang.Long" resultType="com.xxx.entity.CLOTHES" fetchSize="50">
select * from CLOTHES where stadent_id =#{
id}
</select>
3、resultMap自定义列表
/**
* public class StudentVo extends Student {
*
* private List<CLOTHES> subList;
*
* }
*/
<resultMap id="recordMap" type="com.xxx.vo.StudentVo">
<result column="ID" jdbcType="NUMERIC" property="id"/>
<result column="NAME" jdbcType="VARCHAR" property="name"/>
<collection
//查询衣品表条件(这里的ID是Student查询返回的ID,对应子表student_id字段)
column="ID"
//返回给StudentVo实体中指定的属性字段
property="subList"
//tudentVo实体中指定的属性字段对象类型
ofType="com.xxx.entity.CLOTHES"
//指定类路径和方法
select="com.xxx.mapper.CLOTHESMapper.selectSubList">
</collection>
//自定义resultmap,type指向的对象为自定义StudentVo 对象,
//
一对1也可以这么写,多个表最佳
链接: link.
图片:
带尺寸的图片:
居中的图片:
居中并且带尺寸的图片:
当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。
如何插入一段漂亮的代码片
去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片
.
// An highlighted block
var foo = 'bar';
生成一个适合你的列表
- 项目
- 项目
- 项目
- 项目
- 项目1
- 项目2
- 项目3
- 计划任务
- 完成任务
创建一个表格
一个简单的表格是这么创建的:
项目 | Value |
---|---|
电脑 | $1600 |
手机 | $12 |
导管 | $1 |
设定内容居中、居左、居右
使用:---------:
居中
使用:----------
居左
使用----------:
居右
第一列 | 第二列 | 第三列 |
---|---|---|
第一列文本居中 | 第二列文本居右 | 第三列文本居左 |
SmartyPants
SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:
TYPE | ASCII | HTML |
---|---|---|
Single backticks | 'Isn't this fun?' |
‘Isn’t this fun?’ |
Quotes | "Isn't this fun?" |
“Isn’t this fun?” |
Dashes | -- is en-dash, --- is em-dash |
– is en-dash, — is em-dash |
创建一个自定义列表
-
Markdown
- Text-to- HTML conversion tool Authors
- John
- Luke