mybatis 里面的 collection 嵌套两层后,如果里面那层有两条数据,最后返回的是两个 json 字符串,目标是想得到 1 个 json 字符串。把类型改为 List 也不行,有没有大佬教一教我呀。 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wwlearnbc

mybatis 里面的 collection 嵌套两层后,如果里面那层有两条数据,最后返回的是两个 json 字符串,目标是想得到 1 个 json 字符串。把类型改为 List 也不行,有没有大佬教一教我呀。

  •  
  •   wwlearnbc 2021 年 12 月 7 日 1041 次点击
    这是一个创建于 1600 天前的主题,其中的信息可能已经有所发展或是发生改变。
    问题遇到的现象和发生背景

    mybatis 里面的 collection 嵌套两层后,如果里面那层有两条数据,最后返回的是两个 json 字符串,目标是想得到 1 个 json 字符串。把类型改为 List 也不行,有没有大佬教一教我呀。

    问题相关代码,

    domain 层:

    public class Alltest extends BaseEntity { private static final long serialVersiOnUID= 1L; private List<Treatmentinfo> treatmentinfoList; private List<Treatmentpciinfo> treatmentpciinfoList; private List<Outcomeinfo> outcomeinfoList; private List<Registerinfo> registerinfoList; private List<Firstaidinfo> firstaidinfoList; 其他的几个嵌套就是在另外的 class 里面再嵌套一个 List ,代码太长就不展示了 
    因为全部数据太长了,我删除了中间的一些字段,保留前后数据和 collection 。 <resultMap id="AlltestResult" type="com.ruoyi.alltest.domain.Alltest"> <collection property="registerinfoList" javaType="java.util.List" resultMap="RegisterinfoResult"/> <collection property="firstaidinfoList" javaType="java.util.List" resultMap="FirstaidinfoResult"/> <collection property="outcomeinfoList" javaType="java.util.List" resultMap="OutcomeinfoResult"/> <collection property="treatmentinfoList" javaType="java.util.List" resultMap="TreatmentinfoResult"/> <collection property="treatmentpciinfoList" javaType="java.util.List" resultMap="TreatmentpciinfoResult"/> </resultMap> <!--人口信息表--> <resultMap type="com.ruoyi.patientme.domain.Registerinfo" id="RegisterinfoResult"> <result property="patientId" column="patient_id" /> <result property="register_id" column="REGISTER_ID" /> <result property="hospital_id" column="HOSPITAL_ID" /> <result property="name" column="NAME" /> <result property="gender" column="GENDER" /> <result property="age" column="AGE" /> <result property="birthday" column="BIRTHDAY" /> <result property="nation" column="NATION" /> <result property="fillin_person" column="FILLIN_PERSON" /> <result property="submit_audit_person" column="SUBMIT_AUDIT_PERSON" /> <result property="auditor" column="AUDITOR" /> <result property="archiving_person" column="ARCHIVING_PERSON" /> </resultMap> <!--急救信息表--> <resultMap type="com.ruoyi.emergencyaid.domain.Firstaidinfo" id="FirstaidinfoResult"> <result property="patientId" column="patient_id" /> <result property="inpatient_id" column="INPATIENT_ID" /> <result property="outpatient_id" column="OUTPATIENT_ID" /> <result property="attack_time" column="ATTACK_TIME" /> <result property="is_null_attack_detail_time" column="IS_NULL_ATTACK_DETAIL_TIME" /> <result property="attack_zone" column="ATTACK_ZONE" /> <result property="province" column="PROVINCE" /> <result property="city" column="CITY" /> <result property="area" column="AREA" /> <result property="attack_address" column="ATTACK_ADDRESS" /> <result property="medical_insurance_type" column="MEDICAL_INSURANCE_TYPE" /> <result property="medical_insurance_no" column="MEDICAL_INSURANCE_NO" /> <result property="serious_illness_insurance" column="SERIOUS_ILLNESS_INSURANCE" /> <result property="consciousness_type column="CONSCIOUSNESS_TYPE" /> <result property="respiration_rate" column="RESPIRATION_RATE" /> <result property="pulse_rate" column="PULSE_RATE" /> <result property="heart_rate" column="HEART_RATE" /> <result property="throm_end_time" column="THROM_END_TIME" /> <result property="throm_drug_type" column="THROM_DRUG_TYPE" /> <result property="throm_drug_code" column="THROM_DRUG_CODE" /> <result property="is_repatency" column="IS_REPATENCY" /> <result property="start_radiography_time" column="START_RADIOGRAPHY_TIME" /> <result property="is_repci" column="IS_REPCI" /> <result property="operation_time" column="OPERATION_TIME" /> <result property="hospital_position" column="HOSPITAL_POSITION" /> <result property="patient_remark" column="PATIENT_REMARK" /> </resultMap> <resultMap type="com.ruoyi.outcomeme.domain.Outcomeinfo" id="OutcomeinfoResult"> <result property="patientId" column="patient_id" /> <result property="cp_diagnosis_code" column="CP_DIAGNOSIS_CODE" /> <result property="diagnosis_time" column="DIAGNOSIS_TIME" /> <result property="is_heart_failure" column="IS_HEART_FAILURE" /> <result property="pcsk9_name" column="PCSK9_NAME" /> <result property="pcsk9_dose" column="PCSK9_DOSE" /> <collection property="outdrugdetailsList" javaType="java.util.List" resultMap="OutdrugdetailsResult" /> </resultMap> <resultMap type="Outdrugdetails" id="OutdrugdetailsResult"> <id property="myDrugId" column="my_drug_id" /> <result property="drug_id" column="DRUG_ID" /> <result property="patientId" column="patient_id" /> <result property="type" column="TYPE" /> <result property="name" column="sub_name" /> <result property="dose" column="DOSE" /> <result property="rete_count" column="RETE_COUNT" /> <result property="rete_time" column="RETE_TIME" /> <result property="other_drug_name" column="OTHER_DRUG_NAME" /> </resultMap> <!--胸痛诊疗--> <resultMap type="Treatmentinfo" id="TreatmentinfoResult"> <id property="patientId" column="patient_id" /> <result property="has_ecg_image" column="HAS_ECG_IMAGE" /> <result property="no_ecg_image_reason" column="NO_ECG_IMAGE_REASON" /> <result property="await_doctor_name" column="AWAIT_DOCTOR_NAME" /> <result property="await_treatment_type" column="AWAIT_TREATMENT_TYPE" /> <result property="await_patient_remark" column="AWAIT_PATIENT_REMARK" /> <collection property="ctntsList" javaType="java.util.List" resultMap="CtntsRrsult" /> <collection property="ecgsList" javaType="java.util.List" resultMap="EcgsResult" /> </resultMap> <resultMap id="CtntsRrsult" type="Ctnts"> <id property="ctntsId" column="CTNTS_ID" /> <result property="ctntsPatientId" column="ctnts_patient_id" /> <result property="type" column="TYPE" /> <result property="value" column="VALUE" /> <result property="unit" column="UNIT" /> <result property="status" column="STATUS" /> <result property="blood_time" column="BLOOD_TIME" /> <result property="report_time" column="REPORT_TIME" /> </resultMap> <resultMap id="EcgsResult" type="Ecgs"> <id property="ecgId" column="ECG_ID" /> <result property="patientId" column="patient_id" /> <result property="ecg_time" column="ECG_TIME" /> <result property="ecg_diagnose_time" column="ECG_DIAGNOSE_TIME" /> <result property="ecgimagefiles" column="ECGImageFiles" /> </resultMap> <!--导管室--> <resultMap type="com.ruoyi.cathlab.domain.Treatmentpciinfo" id="TreatmentpciinfoResult"> <result property="patientId" column="patient_id" /> <result property="activate_conduit_time" column="ACTIVATE_CONDUIT_TIME" /> <result property="patient_arrived_conduit_time" column="PATIENT_ARRIVED_CONDUIT_TIME" /> <result property="auxiliary_device" column="AUXILIARY_DEVICE" /> <result property="complication" column="COMPLICATION" /> <collection property="coronaryAngiographieList" javaType="java.util.List" resultMap="CoronaryAngiographieResult" /> </resultMap> <resultMap id="CoronaryAngiographieResult" type="CoronaryAngiographie"> <id property="caId" column="CA_ID" /> <result property="caPatientId" column="ca_patient_id" /> <result property="position" column="POSITION" /> <result property="narrow_level" column="NARROW_LEVEL" /> <result property="preoperative_timi_leve" column="PREOPERATIVE_TIMI_LEVE" /> <result property="bracket_thrombus" column="BRACKET_THROMBUS" /> <result property="branching_sick" column="BRANCHING_SICK" /> <result property="cto" column="CTO" /> <result property="ca_sick" column="CA_SICK" /> <result property="criminal_sick" column="CRIMINAL_SICK" /> <result property="pci" column="PCI" /> <result property="intraoperative_handle" column="INTRAOPERATIVE_HANDLE" /> <result property="balloon_expansion_time" column="BALLOON_EXPANSION_TIME" /> <result property="timi" column="TIMI" /> <result property="bracket_num" column="BRACKET_NUM" /> <result property="bracket_type" column="BRACKET_TYPE" /> </resultMap> <select id="selectAlltestByPatientId" parameterType="String" resultMap="AlltestResult"> SELECT * FROM registerinfo a, firstaidinfo b, outcomeinfo c LEFT JOIN outdrugdetails ON outdrugdetails.patient_id = c.patient_id, treatmentinfo d LEFT JOIN ctnts ON ctnts.ctnts_patient_id = d.patient_id LEFT JOIN ecgs ON ecgs.patient_id = d.patient_id, treatmentpciinfo e LEFT JOIN coronary_angiographie ON coronary_angiographie.ca_patient_id = e.patient_id WHERE a.patient_id = #{paientId} and a.patient_id = b.patient_id AND a.patient_id = c.patient_id AND a.patient_id = d.patient_id AND a.patient_id = e.patient_id </select> 
    运行结果及报错内容

    如果这个 Outdrugdetails 表里面对应的 patientId 有两条数据,目标最后的返回的数据是 1 条,但是返回了两条。

    我的解答思路和尝试过的方法

    我改了数据类型为 list 还是不行,sql 语句我目前只知道这么写,我试过将 select 语句嵌套在 collection 中但是报错了。现在不知道怎么解决这个问题。

    我想要达到的结果

    最后返回的结果可以正确的嵌套。

    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2851 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 09:32 PVG 17:32 LAX 02:32 JFK 05:32
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86