my batis collection 다 중 조건 조회 실현 방법
4497 단어 mybatiscollection
선언:
업 무 는 my batis 조 회 를 통 해 포 함 된 집합 으로 돌아 가 야 합 니 다.여러 번 조회 하 는 것 이 너무 번 거 로 워 서 자체 적 인 고급 조회 로 문 제 를 해결 해 야 합 니 다.다음은 코드 입 니 다.테스트 를 통 과 했 습 니 다.
자신의 이 해 를 말 해 보 세 요.바로 메 인 조회 결과 집합 에 하위 조회 결과 집합 이 포함 되 어 있 습 니 다.여러 개의 키 로 조회 할 수 있 습 니 다.모든 하위 조회 조건 은 메 인 조회 결과 에서 집중 적 으로 가 져 오고 값 을 사용자 정의 로 되 돌려 줍 니 다.collection 태그 의 property 는 메 인 조회 에 집합 한 이름 입 니 다.여러 개 있 으 면 collection 을 다시 씁 니 다.column 은 하위 조회 매개 변수 입 니 다.단일 매개 변 수 는 메 인 조회 와 결합 하여 결 과 를 되 돌려 줍 니 다.예 를 들 어 user 를 직접 씁 니 다.id,데이터베이스 필드 라면 여러 조건 으로 패키지 합 니 다.예 를 들 어{userId=userid,theme=theme},그리고 하위 조회 의 parameter Type 은"java.util.Map"이 라 고 쓰 여 있 습 니 다.다 중 조건 조 회 는 my batis 3.0 이후 에 만 있 는 것 같 습 니 다.인터넷 자 료 를 보면 검증 되 지 않 았 습 니 다.of Type 은 집합 대상 이 고 select 는 아래 의 문구 에 대응 합 니 다.
구현 코드:
<resultMap id="BaseResultMap" type="web.model.UserMessage" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="theme" property="theme" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="theme_time" property="themeTime" jdbcType="TIMESTAMP" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="yn" property="yn" jdbcType="INTEGER" />
</resultMap>
<resultMap id="BaseVoResultMap" type="web.model.vo.UserMessageVo" extends="BaseResultMap">
<collection property="userMessageDetailList" column="{userId=user_id,theme=theme}" javaType="java.util.ArrayList" ofType="web.model.UserMessageDetail" select="selectUserMessageDetailById"/>
</resultMap>
<resultMap id="BaseDetailResultMap" type="web.model.UserMessageDetail" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_message_id" property="userMessageId" jdbcType="INTEGER" />
<result column="sponsor_id" property="sponsorId" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="user_type" property="userType" jdbcType="INTEGER" />
<result column="provider_id" property="providerId" jdbcType="INTEGER" />
<result column="message" property="message" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="message_time" property="messageTime" jdbcType="TIMESTAMP" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="yn" property="yn" jdbcType="INTEGER" />
</resultMap>
<select id="selectUserMessageById" resultMap="BaseVoResultMap" parameterType="java.lang.Integer">
select * from user_message where user_id = #{userId,jdbcType=INTEGER}
</select>
<select id="selectUserMessageDetailById" resultMap="BaseDetailResultMap" parameterType="java.util.Map">
select * from user_message_detail where user_id = #{userId,jdbcType=INTEGER} and message = #{theme,jdbcType=VARCHAR}
</select>
selectUserMessage ById,이것 은 주 조회 입 니 다.VO 에는 private List이 속성,다음은 반환 값 구조 캡 처 입 니 다.
궁금 한 점 이 있 으 시 면 메 시 지 를 남기 거나 본 사이트 의 커 뮤 니 티 에 가서 토론 을 교류 하 세 요.읽 어 주 셔 서 감사합니다. 도움 이 되 셨 으 면 좋 겠 습 니 다.본 사이트 에 대한 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Mybatis가 키 id를 삽입하는 방법을 되돌려줍니다.mapper의 xml 파일에useGeneratedKeys 구성 KeyProperty를 사용하여 Id로 돌아가면 됩니다. PS: Mybatis의 insert에서 키 ID를 반환하는 방법 1、XyzMapper.xml 또...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.