java.lang.IllegalStateException:无法转换类型的值

问题描述 投票:0回答:1

[当我将SubmitState设置为ModelAndView的属性时,我遇到以下异常:

java.lang.IllegalStateException: Cannot convert value of type 'example.package.SubmitState' to required type 'java.lang.String': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:262)
    at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:73)

设置方法:model.addAttribute(someField, submitState);

设置完成后,我尝试重定向到页面,但出现异常。

SubmitState:

public class SubmitState implements Serializable {

    private String msgClass;

    private String msgKey;

    public void setMsgClass(String msgClass) {
        this.msgClass = msgClass;
    }

    public String getMsgClass() {
        return msgClass;
    }

    public void setMsgKey(String msgKey) {
        this.msgKey = msgKey;
    }

    public String getMsgKey() {
        return msgKey;
    }
}
java spring spring-mvc
1个回答
0
投票
model.addAttribute("some-key", submitState);
© www.soinside.com 2019 - 2024. All rights reserved.