mybatis多表查询多字段接收问题

mybatis多表查询多字段接收问题

在网上查了一下,没有发现很好的方案,基本都是要在实体类里面注入另一个实体类的字段。或者新写一个中间实体类接收。这样有时候要加字段,什么的都要调整实体类。今天学习到一种新的返回方式,Map返回数据类型来接收。

1、Mybatis文件写法(resultType使用Map)

    <select id="test" parameterType="String" resultType="Map">
     select a.butler_id,a.user_id,b.order_id,a.in_time
     from ce_phoenix_relative a left outer join ce_phoenix_future b on a.user_id=b.cellphone
     where a.butler_id=#{
     butler_id,jdbcType=VARCHAR} order by a.in_time desc
    </select>

2、Mapper接口使用Map类型接收

 List<Map<String,String>> selectFutureMemberByButler(String butler_id);

3、Controller也是同样使用Map

    @RequestMapping(value = "/getFutureMemberData")
    @ResponseBody
    public RespEntity getFutureMemberData(String butler_id){
     
        List<Map<String,String>> futureMemberList= futureMemberService.selectFutureMemberByButler(butler_id);

        return new RespEntity(RespCode.SUCCESS, futureMemberList);
    }

4、前端在js里面遍历获取到的数据

                        $.ajax({
     
                            url: url,
                            data: {
     butler_id: butlerId},
                            type: "GET",
                            dataType: "json",
                            async: true,
                            success: function (data) {
     
                                console.log(data)
                                if(data.code==200){
     
                                    let result = data.data;
                                    if(result.length>0){
     
                                        let totalStr = "";
                                        let selectArr = [];
                                        for(let j=0;j<result.length;j++){
     
                                            let month = parseInt((result[j].in_time).slice(5,7));
                                            console.log(month);
                                            if(start<=month&&month<=end){
     
                                                selectArr.push(result[j]);
                                            }
                                        }
                                        console.log(selectArr);
                                        let arrStart = (page-1)*10;
                                        let arrEnd = (page-1)*10+10;
                                        if(arrEnd>selectArr.length){
     
                                            arrEnd = selectArr.length;
                                        }
                                        totalPage = Math.ceil(selectArr.length/10)
                                        let resultArr = selectArr.slice(arrStart,arrEnd);

                                        for(let i=0;i<resultArr.length;i++){
     
                                            // let date = (resultArr[i].in_time).slice(0,10);
                                            // let time = (resultArr[i].in_time).slice(11,19);
                                            let formatDate = new Date(resultArr[i].in_time)
                                            let date = formatDate.getFullYear() + '-' + (formatDate.getMonth() + 1) + '-' + formatDate.getDate()
                                            let time = formatDate.getHours() + ':' + formatDate.getMinutes() + ':' + formatDate.getSeconds()
                                            let state = "成功开通";
                                            let stateClass = "badge_success";
                                            if(resultArr[i].order_id==null){
     
                                                state = "处理中";
                                                stateClass = "badge_unfinish";
                                            }
                                            let sonStr = '
\n' + '
'+date+'
\n'
+ '
'+time+'
\n'
+ '
'+resultArr[i].user_id+'
\n'
+ '
\n' + '
+stateClass+'">'+state+'
\n'
+ '
\n'
+ '
'
; totalStr = totalStr + sonStr; } $("#content").html(totalStr); }else{ alert("暂时没有数据!"); $("#content").html(""); } } $("#loading").css("display","none"); } })

你可能感兴趣的:(代码记录,学习记录,java,mybatis)