项目场景:
提示:这里简述项目相关背景:
例如:项目场景:示例:资源领用表(主表),资源表(副表)。一对多的关系
问题描述:
提示:这里描述项目中遇到的问题:
例如:前台使用高级搜索,模糊查询多个值,有主表中的值也有副表中的值。
APP 中接收数据代码:
@Override
public void run() {
bytes = mmInStream.read(buffer);
mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget();
}
原因分析:
提示:这里填写问题的分析:
例如:主表中xml有办法获取到,关键字查询的keyWrod(关键字),使用 了mybatis中的collection 标签,调用了子查询column中可以传递多个值,但是column取值的来源是sql语句返回的参数,也就是sql中的表头,取数值。而keyWrod只是前端和我定义的一个临时变量,需要通过column属性传入到付表调用的xml中的查询方法中去
解决方案:
提示:这里填写该问题的具体解决方案:
例如:利用了mysql的特性,将输入的值转化成新的一列。然后到返回的参数中获取出来。
普通的查询:
将输入值返回的查询:
<resultMap id="AddGetAssets2" type="com.ruoyi.epidemic.domain.AddGetAssets">
<result property="getId" column="get_id" />
<result property="getTime" column="get_time" />
<result property="getOddNumbers" column="get_odd_numbers" />
<result property="getPersonNameId" column="get_person_name_id" />
<result property="getUseCompanyId" column="get_use_company_id" />
<result property="getUseDepartmentId" column="get_use_department_id" />
<result property="getUseAreaId" column="get_use_area_id" />
<result property="getUseStation" column="get_use_station" />
<result property="getUseDisposePersonId" column="get_use_dispose_person_id" />
<result property="getRemark" column="get_remark" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="createById" column="create_by_id" />
<!-- 自定义 -->
<result property="getPerson" column="getPerson" /> <!-- 领用人 -->
<result property="getDisposePerson" column="getDisposePerson" /> <!-- 领用处理人 -->
<result property="getDepartment" column="getDepartment" /> <!-- 领用部门 -->
<result property="getCompany" column="getCompany" /> <!-- 领用公司 -->
<result property="getUseArea" column="getUseArea" /> <!-- 领用后使用地 -->
<result property="keyWord" column="keyWord"/> <!-- 关键字 -->
<!-- 调用赋值 -->
<!-- property 属性的名称需要跟实体类的中名称对应 column 传入一个值不需要中括号 多个值才需要 -->
<!-- javaType 返回类型 -->
<!-- ofType 副表对象的路径 -->
<!-- select 调用的mapper的方法路径,我这里填写的实体类的路径。没有填写xml的路径 -->
<collection property="assetsList" column="{getId=get_id,keyWord=keyWord}" javaType="java.util.ArrayList" ofType="com.ruoyi.epidemic.domain.AddAssets" select="com.ruoyi.epidemic.mapper.AddAssetsMapper.selectAddAssetsInId" />
</resultMap>
<sql id="selectAddGetAssetsVo">
select aga.get_id, aga.get_time, aga.get_odd_numbers, aga.get_person_name_id,
aga.get_use_company_id,
aga.get_use_department_id,
aga.get_use_area_id,
aga.get_use_station, aga.get_use_dispose_person_id, aga.get_remark, aga.create_time, aga.create_by, aga.create_by_id,
su.user_name as 'getPersonName', -- 领用人
sd.dept_name as 'getUseCompany', -- 领用后使用公司
sd2.dept_name as 'getUseDepartment',
aua.area_name as 'getUseArea',
su2.user_name as 'getUseDisposePerson',
<!-- 多表关键字模糊查询的重点 将主表的值,放入返回参数中 -->
#{
keyWord} as 'keyWord'
from add_get_assets aga
left join sys_user su on aga.get_person_name_id = su.user_id
LEFT join sys_dept sd on aga.get_use_company_id = sd.dept_id
LEFT join sys_dept sd2 on aga.get_use_department_id = sd2.dept_id
LEFT join add_use_area aua on aga.get_use_area_id = aua.id
LEFT join sys_user su2 on aga.get_use_dispose_person_id = su2.user_id
</sql>