0
@Override
public void validate(Object target, Errors errors) {

    Date today = new Date();
    MiniStatementViewModel miniStatementViewModel=(MiniStatementViewModel) target;


    else if(miniStatementViewModel.getFinancialTransactionType()==null)
    {
    errors.rejectValue("financialTransactionType","financialTransactionTypeNull");
    }

这是我在此金融交易类型中的验证器代码在模型中作为对象的金融交易类型

public class MiniStatementViewModel {


private boolean isMiniStatement;

private Date fromDate;

private Date toDate;

private String accountCode;

private FinancialTransactionType financialTransactionType;

所以,当我在 JSP 上显示错误消息时,会给出一个错误消息,例如

Failed to convert property value of type java.lang.String to required type mkcl.os.apps.solar.account.model.FinancialTransactionType for property financialTransactionType; 
nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type mkcl.os.apps.solar.account.model.FinancialTransactionType for value NONE; 
nested exception is java.lang.IllegalArgumentException: No enum const class mkcl.os.apps.solar.account.model.FinancialTransactionType.NONE
4

1 回答 1

0

该错误意味着您正在NONE从表单中获取 String 值,并且为了将该值放入financialTransactionType字段中,它执行 FinancialTransactionType.valueOf("NONE") 并返回错误,因为它不存在。

将您的班级更改为:

public class MiniStatementViewModel {


private boolean isMiniStatement;

private Date fromDate;

private Date toDate;

private String accountCode;

private String financialTransactionType;

和你的验证者:

@Override
public void validate(Object target, Errors errors) {

    Date today = new Date();
    MiniStatementViewModel miniStatementViewModel=(MiniStatementViewModel) target;


    else if(FinancialTransactionType.valueOf(miniStatementViewModel.getFinancialTransactionType())==null)
    {
    errors.rejectValue("financialTransactionType","financialTransactionTypeNull");
    }
于 2013-09-03T07:04:55.010 回答