NutzCN Logo
问答 nutz前端传递复杂对象,后端接收时对象里面的列表只能是NutMap类型吗
发布于 1151天前 作者 wx_g5rmh75r1uqrjd0u5l54 1306 次浏览 复制 上一个帖子 下一个帖子
标签:

前端传值

jQ.ajax({
                            type: "POST",
                            url: url,
                            contentType: 'application/json',
                            dataType: "JSON",
                            data: JSON.stringify(Object.assign({},data.field,{creditScoreOptionList: table.cache["test"]})),
                            success: function (data) {
                                if (data.code === 0) {
                                    parent.window.doClose();
                                } else {
                                    alert("请求失败!请联系管理员!");
                                }
                            },
                            error: function () {
                                alert("请求失败!请联系管理员!");
                            }
                        });

后端接收

 @At
    @Ok("json")
    @AdaptBy(type = JsonAdaptor.class)
    public Map<String,Object> insertCreditScore(HttpServletRequest request,
                                                CreditScore creditScore,
                                                @Attr("userInfo") User user) {
        return creditScoreLogic.insertCreditScore(request,creditScore,user);
    }

实体类

@Table("CREDIT_SCORE")
public class CreditScore {
    @Name
    private String id;
    private String province_id;
    private String province;
    private String city_id;
    private String city;
    private String certification_organization;
    private Integer is_valid;
    private String emp_id;
    private String emp_name;
    private Date create_date;
    private String update_id;
    private String update_user;
    private Date update_date;
    private String attachmentdata;

    @Readonly
    private List<CreditScoreOption> creditScoreOptionList;
}

报错

java.lang.ClassCastException: org.nutz.lang.util.NutMap cannot be cast to cn.zn.pm.creditscore.data.CreditScoreOption
	at cn.zn.pm.creditscore.logic.CreditScoreLogic.insertCreditScore(CreditScoreLogic.java:140)
	at cn.zn.pm.creditscore.act.CreditScoreAct.insertCreditScore(CreditScoreAct.java:47)
	at cn.zn.pm.creditscore.act.CreditScoreAct$FM$insertCreditScore$0d11f5c469ed196649ab1ea8aa48e334.invoke(CreditScoreAct.java)
4 回复

CreditScoreOption也贴一下

都是普通的字段

@Table("CREDIT_SCORE_OPTION")
public class CreditScoreOption {
    @Name
    private String id;
    private String credit_score_id;
    private String option_name;
    private String score;
    private String actual_score;
    private String deduct_reason;
    private String emp_id;
    private String emp_name;
    private Date create_date;
    private String update_id;
    private String update_user;
    private Date update_date;
}

不得不说,适配器好拉跨

添加回复
请先登陆
回到顶部