使用mybatis对查询数据进行分组

使用mybatis对查询数据进行分组

SELECT a.id AS a_id,a.name AS a_name,a.`desc` AS a_desc,a.op AS a_op,b.id AS b_id,b.priority AS b_priority,b.`content` AS b_content
FROM agent AS a 
LEFT JOIN (SELECT * FROM text_response WHERE intent_id IS NULL ) AS b 
ON a.id=b.`agent_id` WHERE a.id=39


a_id  a_name        a_desc    a_op    b_id  b_priority  b_content                                                              
39    股票应用      (NULL)    1       360    1          小库委屈,但小库不能说,上帝请让小库我更聪明吧  
39    股票应用      (NULL)    1       361    1          小库还要加强学习,主人加油训练小库                    
39    股票应用      (NULL)    1       362    1          小库还不能理解,但小库会努力学习新东西的           
39    股票应用      (NULL)    1       363    1          哎呀,小库不能理解,好好训练小库好不                 


public interface AgentDao {
    Agent selectAgentRelaById(Integer id);
    Agent selectById(Integer agent_id);
}



<?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.csf.ops.ai.dao.AgentDao">

    <resultMap type="com.csf.ops.ai.entity.Agent" id="agent">
        <id column="a_id" property="id" />
        <result column="a_name" property="name" />
        <result column="a_desc" property="desc" />
        <result column="a_op" property="op" />
        <!-- 描述集合属性 -->
        <collection property="responses" ofType="com.csf.ops.ai.entity.TextResponse">
            <id column="b_id" property="id" />
            <result column="b_priority" property="priority" />
            <result column="b_content" property="content" />
        </collection>
    </resultMap>
    
    <select id="selectAgentRelaById" parameterType="int" resultMap="agent">
        SELECT a.id AS a_id,a.name AS a_name,a.`desc` AS a_desc,a.op AS
        a_op,b.id AS b_id,b.priority AS b_priority,b.`content` AS b_content
        FROM agent AS a LEFT JOIN (SELECT * FROM text_response WHERE intent_id
        IS NULL ) AS b ON a.id=b.`agent_id` WHERE a.id=#{id}
    </select>

    <select id="selectById" parameterType="int" resultType="com.csf.ops.ai.entity.Agent">
        select * from agent where id=#{id}
    </select>
    
</mapper>


{
    "id": 39,
    "op": 1,
    "name": "股票应用",
    "responses": [
        {
            "id": 360,
            "priority": 1,
            "content": "小库委屈,但小库不能说,上帝请让小库我更聪明吧"
        },
        {
            "id": 361,
            "priority": 1,
            "content": "小库还要加强学习,主人加油训练小库"
        },
        {
            "id": 362,
            "priority": 1,
            "content": "小库还不能理解,但小库会努力学习新东西的"
        },
        {
            "id": 363,
            "priority": 1,
            "content": "哎呀,小库不能理解,好好训练小库好不"
        }
    ]
}

public class Agent implements Serializable{
    private Integer id;
    private Integer op;
    private String developer;
    private String name;
    private String desc;
    private List<TextResponse> responses;
}

public class TextResponse {
    private Integer id;
    private Integer priority;
    private String content;
    private Integer agent_id;
    private Integer intent_id;

}

 

转载于:https://www.cnblogs.com/xiaolei2017/p/7977102.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值