mapper一对多简单写法笔记

分表存储,并且查询数据

mapper一对多简单写法笔记mapper一对多简单写法笔记

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.questionnaire.study.mapper.DivOptingsContenMapper">
    <resultMap id="BaseResultMap" type="com.questionnaire.study.pojo.DivOptingsConten">
        <id column="num" property="num" jdbcType="INTEGER"/>
        <result column="content" property="content" jdbcType="VARCHAR"/>
        <result column="options" property="options" jdbcType="VARCHAR"/>
        <result column="strength_index" property="strengthIndex" jdbcType="VARCHAR"/>
        <result column="open_index" property="openIndex" jdbcType="VARCHAR"/>
        <result column="title_number" property="titleNumber" jdbcType="INTEGER"/>
        <collection property="divOptingsTitles" ofType="com.questionnaire.study.pojo.DivOptingsTitle">
            <id column="id" property="id" jdbcType="INTEGER"/>
            <result column="title_name" property="titleName" jdbcType="VARCHAR"/>
            <result column="title_type" property="titleType" jdbcType="VARCHAR"/>
            <result column="title_ describe" property="titleDescribe" jdbcType="VARCHAR"/>
            <result column="title_num" property="titleNum" jdbcType="INTEGER"/>
            <result column="titlt_mark" property="titltMark" jdbcType="VARCHAR"/>
        </collection>
    </resultMap>

    <!-- 查询所有题库 -->
    <select id="findAllQuestion" resultMap="BaseResultMap">
        SELECT
        `div_optings_conten`.`num`,
        `div_optings_conten`.`content`,
        `div_optings_conten`.`open_index`,
        `div_optings_conten`.`strength_index`,
        `div_optings_conten`.`title_number`,
        `div_optings_title`.`title_ describe`,
        `div_optings_title`.`title_name`,
        `div_optings_title`.`title_num`,
        `div_optings_title`.`title_type`,
        `div_optings_title`.`titlt_mark`
        from
        `div_optings_conten`
        LEFT JOIN `div_optings_title`
        ON `div_optings_title`.`title_num` = `div_optings_conten`.`title_number`
    </select>

实体

public class DivOptingsConten implements Serializable {
    private Integer num;

    private String content;

    private String options;

    private String strengthIndex;

    private String openIndex;

    private Integer titleNumber;

    List<DivOptingsTitle> divOptingsTitles;

标题:

public class DivOptingsTitle implements Serializable {
    private Integer id;

    private String titleName;

    private String titleType;

    private String titleDescribe;

    private Integer titleNum;

    private String titltMark;

mapper一对多简单写法笔记

上一篇:axios.all is not a function


下一篇:iPhone 手机发送短信,报告“尚未送达”