我有从 .raml 文件生成的类。在为控制器生成的接口中,我的参数上有@RequestBody。如果我尝试发出请求,则映射工作正常,但每次我的对象中有空字段时,都使用参数中的 @RequestBody 进行了注释。看起来这个注释被忽略了。我怎样才能让它从界面工作。
对于没有 Raml 的测试,我尝试为具有简单实现的控制器创建一个简单的接口,但我仍然在请求对象中获取空字段值。
从 .raml 生成的控制器接口
@RestController
@RequestMapping("/kbm")
public interface KbmController {
@RequestMapping(value = "", method = RequestMethod.PUT)
public ResponseEntity<KbmCalcResponse> updateKbm(
@Valid
@RequestBody
KbmCalcRequest kbmCalcRequest);
}
我的实现
@Component
@RequiredArgsConstructor
public class CalcKbmControllerImpl implements KbmController {
private final KbmService kbmService;
@Override
public ResponseEntity<KbmCalcResponse> updateKbm(KbmCalcRequest kbmCalcRequest) {
System.out.println(kbmCalcRequest.getInsurerID());
return ResponseEntity.ok(kbmService.calculate(kbmCalcRequest));
}
}
从 .raml 生成的请求模型
public class KbmCalcRequest implements Serializable
{
final static long serialVersionUID = 1692733266431420440L;
private String insurerID;
public KbmCalcRequest() {
super();
}
public KbmCalcRequest(String insurerID {
super();
this.insurerID = insurerID;
}
public String getInsurerID() {
return insurerID;
}
public void setInsurerID(String insurerID) {
this.insurerID = insurerID;
}
public int hashCode() {
return new HashCodeBuilder().append(insurerID).toHashCode();
}
public boolean equals(Object other) {
if (other == null) {
return false;
}
if (other == this) {
return true;
}
if (this.getClass()!= other.getClass()) {
return false;
}
KbmCalcRequest otherObject = ((KbmCalcRequest) other);
return new EqualsBuilder().append(insurerID, otherObject.insurerID).isEquals();
}
public String toString() {
return new ToStringBuilder(this).append("insurerID", insurerID).toString();
}
}