其中有一个带有var geoJsonLayer = L.geoJson(false, {onEachFeature: addMyPopup}).addTo(map);
的restcontroller映射。
// Initialise the three reference points
var hydrat1 = L.latLng(<..>, <..>);
var hydrat2 = L.latLng(<..>, <..>);
var hydrat3 = L.latLng(<..>, <..>);
// This gets called for every point in the GeoJSON
function addMyPopup ( feature, layer) {
if ((layer.getLatLng().distanceTo(hydrat1) < 5)
||(layer.getLatLng().distanceTo(hydrat2) < 5)
||(layer.getLatLng().distanceTo(hydrat3) < 5)) {
// Do something
}
layer.bindPopup("My ID is: " + feature.properties.id);
作为正文,也可以正确解析 @RequestBody TypeA
。
我要实现的目的是使完全不发送正文(TypeA
为空)具有相同的逻辑。
代码:
{}
到目前为止,我看到的唯一可能的解决方案是设置@RequestBody
,将类型包装在Optional中,然后使用@PostMapping('/post')
public ResponseEntity processPost(@RequestBody(required=false) Optional<TypeA> body) {
return service.someAction(body.orElse(new TypeA());
}
,它虽然有效,但看起来无效。
是否有适当的方法来获得这个?
答案 0 :(得分:1)
您可以尝试
@PostMapping('/post')
public ResponseEntity processPost(@NotNull(message = "you can add null description") @RequestBody TypeA body) {
}
答案 1 :(得分:0)
我会做这样的事情:
@PostMapping('/post')
public ResponseEntity processPost(@RequestBody(required=false) TypeA body) {
return service.someAction(body == null ? new TypeA(): body);
}