答案 0 :(得分:4)
如果您明确检查TypeMismatchException,只需致电getValue()
答案 1 :(得分:2)
你可以从org.springframework.beans.TypeMismatchException获取价值,只需使用Object getValue(),例如,使用以下代码:
...
} catch(Exception exception) {
if(exception instanceof TypeMismatchException) {
Object value = ((TypeMismatchException) exp).getValue;
... // what you want to do with value
}
}
或只是
...
} catch(TypeMismatchException exception) {
Object value = exp.getValue;
... // what you want to do with value
}
因为org.springframework.beans.TypeMismatchException定义为
package org.springframework.beans;
public class TypeMismatchException extends PropertyAccessException {
...
/**
* Return the offending value (may be {@code null})
*/
@Override
public Object getValue() {
return this.value;
}
...
}