对于resultMap没有理解清楚惹的祸

resultmap的使用

这个是我的表的设计字段
在这里插入图片描述

这是我的输入参数

@Slf4j
@Data
//这里是写入数据库字段;
public class SpecificMedicine {
    private Integer mId;
    private Integer pId;
    private Integer userId;
    private String name;
    private String ingredient;
    private String property;
    private String compatible;
    private String antagonism;

    //写构造方法 给mybatis使用
    public SpecificMedicine(){
        log.debug("model.product.Product被调用");
    }

   /* public Product()*/

    public SpecificMedicine(user user, SpecificMedicineParam param) {
        log.debug("model.product.SpecificMedicine被调用 param={},user={}",param,user);
        //this.mId= user.getUserId();
        //this.mId=user.getUserId();
        //this.mId=param.getMId();
        /*this.pId=param.getPId();
        this.userId=getUserId();*/
        this.name=param.getName();
        this.ingredient = param.getIngredient();
        this.property = param.getProperty();
        this.compatible =param.getCompatible();
        this.antagonism = param.getAntagonism();
    }
}

这是是我的xml配置

<select id="selectAll" resultMap="sAll" resultType="com.walnut.medicinequestionandanswersystem.model.product.SpecificMedicine">
        select m_name,m_ingredient,m_property,m_compatible,m_antagonism from manager_specificmatter order by m_id asc
    </select>

我很大一段时间在这个请求返回前端数据库里面的内容,一直显示为空,我就很纳闷不应该的啊,
而且在我的动态资源中一直显示的是500,也就是是服务器有问题。我就反复检查,没有问题呀,心里想。
给你们看一下我的js中的内容


var xhr=new XMLHttpRequest();

xhr.open('get','/medicine/listmatter.json');

xhr.onload =function(){

    console.log(this.status);
    console.log(this.responseText);

    //序列化responseText
    var ret=JSON.parse(this.responseText)

    if(ret.redirectUrl){
        //如果不为空说明还没登录,需要先登录
        location.assign(ret.redirectUrl)
        return; //其实不用return 只是习惯问题;
    }

    var ma=ret.data;
    var otbody=document.querySelector("tbody")
    for(var matter of ma){
        var html="<tr>"+
            `<td>${matter.name}</td>`+
            `<td>${matter.ingredient}</td>`+
            `<td>${matter.property}</td>`+
            `<td>${matter.compatible}</td>`+
            `<td>${matter.antagonism}</td>`+
            "</tr>"
        otbody.innerHTML +=html;
    }
}
xhr.send()


此时这里的

```html
 for(var matter of ma)//也是错表示不可以迭代
xhr.send()//这个Ajax请求不能发送(500错误);


然后我就坚信是我的后端的问题;
就开始排错,经过好几天的检查,发现可能是字段映射的问题,就在经过学习后开始映射

<resultMap id="sAll" type="com.walnut.medicinequestionandanswersystem.model.product.SpecificMedicine">
        <id property="mId" column="m_id"></id>
        <result property="name" column="m_name"></result>
        <result property="ingredient" column="m_ingredient"></result>
        <result property="property" column="m_property"></result>
        <result property="compatible" column="m_compatible"></result>
        <result property="antagonism" column="m_antagonism"></result>
    </resultMap>
    

最后成功返回浏览
在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值