获取不到数据怎么回事

获取不到这个orgInstitute的instituteName

img

img

$("#myTab").bootstrapTable({
            url: "/owep/organization/branchList/getBranchListList",
            toolbar: '#toolbar', // 工具按钮用哪个容器
            pagination: true,
            cache: false,
            clickToSelect: true, //单击选中
            sortable: true, //是否启用排序
            sortOrder: "asc", // 排序方式
            sidePagination: "client", // 分页方式:client客户端分页,server服务端分页(*)
            pageNumber: 1,
            pageSize: 3,
            pageList: [3, 6, 9, 12],
            /*  search:true,*/
            strictSearch: false,                 //查询时是否严格匹配, true表示严格匹配,false表示模糊匹配
            /* showRefresh:true,*/
            uniqueId: "ID",
            columns: [{
                field: 'checked',
                checkbox: true, /* 是否添加复选框*/
                //跟据返回每行的数据
                formatter: function (value, row, index) {
                    return row.id;
                }
            }, {
                    field: 'branchName',
                    title: '分支名称'
                }, {
                    field: 'orgInstitute.instituteName',     
                    title: '所属机构',
                    /*formatter: function (value, row, index) {
                    return value;
                    }*/
                }, {
                    field: 'createTime',
                    title: '创建时间',
                }, {

                    field: 'operator',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    width: '10%',
                    // visible: false,
                    formatter: function (value, row, index) {
                        return '<a  data-toggle="modal" data-target="#updateModal" title="修改">' +
                            '<i class="glyphicon glyphicon-edit"></i> ' +
                            '</a>' +
                            '<a href="javascript:void(0)" title="删除">' +
                            '<i class="glyphicon glyphicon-trash text-danger"></i> ' +
                            '</a>';
                    },
                    events: {
                        'click a[title=删除]': function (e, value, row, index) {
                            swal({
                                title: "您确定要删除这条信息吗",
                                text: "删除后将无法恢复,请谨慎操作!",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "删除",
                                closeOnConfirm: false
                            }, function () {
                                //
                                $.ajax({
                                    //发送AJAX请求
                                    url: "/owep/organization/branchList/deleteById?id=" + row.id,
                                    method: "GET",
                                    async: true,
                                    dataType: "text",
                                    success: function (data) {
                                        if (data == "成功") {
                                            swal("删除成功!", "您已经永久删除了这条信息。", "success");
                                        } else {
                                            alert("删除失败!");
                                        }
                                        window.location.reload();
                                    },
                                    error: function (jqXHR) {
                                        alert("删除失败");
                                    }

                                });
                            });
                        },
                    }
                }]
        });

就在这个里面所属机构那块我把orgInstitute.id就可以获取到id 但是orgInstitute.instituteName这样我就获取不到这个instituteName

@GetMapping(value = "/branchList/getBranchListList",produces = "application/json")
    @ResponseBody
    public Object toOrganizationBranchList(Integer id){
        List<BranchInstitute> branchInstitutes = branchInstituteService.findAllBranch();
        System.out.println("分支机构:");
        branchInstitutes.forEach(System.out::println);
        return branchInstitutes;
    }

xml里面也设置好了怎么回事

<resultMap id="BaseResultMap" type="com.kclm.owep.entity.BranchInstitute">
    <id column="id" jdbcType="INTEGER" property="id" />
    <!--<result column="branch_name" jdbcType="INTEGER" property="branchName" />-->
    <!--<result column="fk_org_id" jdbcType="INTEGER" property="fkOrgId" />-->
    <result column="branch_name" jdbcType="VARCHAR" property="branchName" />
    <result column="fk_org_id" jdbcType="INTEGER" property="orgInstitute.id" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="last_access_time" jdbcType="TIMESTAMP" property="lastAccessTime" />
  </resultMap>
<sql id="BranchInstitute_column_List">
    id,
    branch_name,
    fk_org_id,
    version,
    create_time,
    last_access_time
  </sql>
  <!--查询所有的行为-->
  <select id="selectAll" resultMap="BaseResultMap">
    select
    <include refid="BranchInstitute_column_List"/>
    from t_branch_institute
  </select>

怎么解决呀?

引用 皆我百晓生 小程序回复内容作答:
根据你提供的代码和描述,可能有以下几个问题导致获取不到orgInstitute的instituteName:

  1. 在Java代码中,你返回的是BranchInstitute对象的List,而不是包含instituteName的对象列表。请确保BranchInstitute对象中已经正确设置了orgInstitute的属性。

  2. 在XML文件中的resultMap中,你使用了column="fk_org_id"来映射orgInstitute的id属性,但是没有使用相应的column来映射instituteName属性。请确保在SQL查询中也包含了instituteName的列,并在resultMap中进行相应的映射。

  3. 在前端代码中,你使用了BootstrapTable作为表格插件,并通过url属性指定了后端接口的URL。请确保后端接口的返回数据中包含了orgInstitute的属性,并在columns中设置了正确的field属性来获取instituteName。

根据以上的问题,你可以检查和确认这些代码和配置是否正确,并且确保在后端接口返回的数据中包含了orgInstitute的instituteName属性。

实体类 数据库是否一致? html的name属性是否写?

【以下回答由 GPT 生成】

问题分析: 根据提供的代码,设定了BootstrapTable的url为"/owep/organization/branchList/getBranchListList",表示从该地址获取数据。然后用columns属性定义了表格的列,包括'checked'、'branchName'、'orgInstitute.instituteName'和'createTime'等。现在的问题是,无法正确获取到'orgInstitute.instituteName'字段的值。

问题解决方案: 1. 确保数据接口返回了正确的数据格式,包括orgInstitute.instituteName字段的值。可以通过在浏览器中打开/owep/organization/branchList/getBranchListList查看返回的数据,确保其中包含了orgInstitute.instituteName字段,并且有正确的值。 2. 检查数据的返回格式,确保该字段的命名是正确的。可以查看接口返回的数据,确认字段名是否为orgInstitute.instituteName,而不是其他类似的名称。 3. 鉴于tittle属性的拼写错误,需要确认该字段在返回对象中的命名是否正确。如果命名不一致,可以通过formatter函数直接取到正确的数据。例如更改代码中的columns部分如下:

columns: [{
   field: 'checked',
   checkbox: true,
   formatter: function (value, row, index) {
      return row.id;
   }
}, {
   field: 'branchName',
   title: '分支名称'
}, {
   field: 'orgInstitute.instituteName',
   title: '所属机构',
   formatter: function (value, row, index) {
      return row.orgInstitute ? row.orgInstitute.instituteName : '';
   }
}, {
   field: 'createTime',
   title: '创建时间',
}]

这样,在获取到数据后,会检查row.orgInstitute是否存在,如果存在,则将instituteName作为该字段的值返回。否则,返回一个空字符串。

如果以上步骤都没有解决问题,可以进一步检查BootstrapTable的版本和使用的JavaScript库的兼容性,也可以尝试使用浏览器的开发者工具来排查问题所在。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^