Mybatis one-to-many fuzzy query multi-table multi-field query

Project scene:

Tip: Here is a brief description of the project related background:
for example: project scenario: example: resource application table (main table), resource table (secondary table). One-to-many relationship


Problem Description:

Tips: Here is a description of the problems encountered in the project:
For example, the front desk uses advanced search to fuzzy query multiple values, there are values ​​in the main table and values ​​in the secondary table.
Code for receiving data in APP:

@Override
        public void run() {
    
    
            bytes = mmInStream.read(buffer);
            mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget();
        }

Cause Analysis:

Tip: Fill in the analysis of the problem here:
For example, there is a way to get the xml in the main table. The keyWrod (keyword) of the keyword query is used. The collection tag in mybatis is used. Multiple values ​​can be passed in the subquery column when called, but The source of the column value is the parameter returned by the sql statement, that is, the header in the sql, and the value is taken. The keyWrod is just a temporary variable defined by the front end and me, and it needs to be passed to the query method in the xml called by the payment table through the column attribute.


solution:

Tip: Fill in the specific solution to the problem here:
For example: Use the characteristics of mysql to convert the entered value into a new column. Then get it out of the returned parameters.

Ordinary query: query
Insert picture description here
that returns the input value:
Insert picture description here

    <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>

Guess you like

Origin blog.csdn.net/c_v_sCtrl/article/details/115368034