- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试将 GeoJsonPoint JSON 的 POST 请求映射到 GeoJsonPoint 模型时,但没有成功。
REST Controller :
@RestController
@RequestMapping("/location")
public class LocationController {
@PostMapping(consumes = "application/json")
public MyLocation recieveAddress(@RequestBody MyLocation location) {
return location;
}
@GetMapping(consumes = "application/json")
public MyLocation returnAddress() {
MyLocation loc = new MyLocation();
loc.setLocation(new GeoJsonPoint(0.123321, 0.3453455));
return loc;
}
}
类(class):
public class MyLocation {
private GeoJsonPoint location;
public MyLocation() {
}
public void setLocation(GeoJsonPoint location) {
this.location = location;
}
public GeoJsonPoint getLocation() {
return this.location;
}
}
GET请求返回:
{
"location": {
"x": 0.123321,
"y": 0.3453455,
"type": "Point",
"coordinates": [
0.123321,
0.3453455
]
}
}
当发布上述内容并进行调试时,我得到:
DEBUG 11860 --- [nio-8090-exec-2] o.s.b.a.e.mvc.EndpointHandlerMapping : Looking up handler method for path /location
DEBUG 11860 --- [nio-8090-exec-2] o.s.b.a.e.mvc.EndpointHandlerMapping : Did not find handler method for [/location]
在寻找解决方案时,我遇到了这个问题,但运气不佳:
@Configuration
public class JacksonConfig {
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
b.modulesToInstall(new GeoJsonModule());
return b;
}
}
Spring boot 应用程序是:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
有人可以协助或提供任何指导吗?
最佳答案
我重新创建了整个场景,当 postman 调用电话时,GET 和 POST 都对我有用。您可以检查一下在服务器启动过程中是否收到以下行吗?
2018-09-03 15:10:41.995 INFO 17536 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :映射“{[/location],methods=[POST],consumes=[application/json]}”到公共(public)com .example.demo.location.MyLocation com.example.demo.location.LocationController.recieveAddress(com.example.demo.location.MyLocation)
如果您看到这一行,则意味着您的方法已准备好可供访问。尝试使用以下配置使用 Postman 进行调用:https://pasteboard.co/HCba9qa.png
确保发布的数据如下所示:
{
"location": {
"type": "Point",
"coordinates": [
0.123321,
0.3453455
]
}
}
因为不需要发送 X 和 Y 坐标。我已经使用 MongoRepository 将这些数据保存在 MongoDB 中,它的作用就像一个魅力。如果您遇到任何问题,请告诉我。
关于java - Spring @RequestBody 与 GeoJsonPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48088738/
当我定义 requestBody 时,它不会显示在 swagger 文档中。我想为 swagger 中的 gpx 文件创建一组图像和单个文件上传。如何才能实现 requestBody 像参数属性一样显
我正在使用 Spring 4.x 做 Spring Rest Api 项目 这有效: Controller.java @PostMapping("newTransaction") Transactio
我正在向服务器发送一个 JSON 对象,该服务器将填充我的域对象报告。 public class CustomReport {String name; String name; String emai
我有一个非常琐碎的问题,它占用了我很多时间。 我有一个 Spring Rest 服务,它接受 @RequestBody 中的模型对象。我在模型对象中传递的是格式为 yyyy-MM-dd'T'HH:mm
我一直在开发 Spring Boot Rest api 服务,这是我的 Rest Controller 方法之一: @RequestMapping(value = "manager", method
我使用 Spring Boot 2.0.8.RELEASE。 我有一个 @RestController 方法,如下所示: @PostMapping("/message") public
类(class): class Person { private String name; private List addr; } c
我有以下类作为我的@RequestBody,但我无法发送我的请求,我尝试以不同的格式准备 JSON,但它们都不起作用。 处理程序 @RequestMapping("/grades") @Respons
@PatchMapping("/update") HttpEntity updateOnlyIfFieldIsPresent(@RequestBody Person person) { if(
我正在尝试使用 apache 集合中的 MultiValueMap(MultiMap 的实现)。我正在使用 Spring MVC 的 @RequestBody 注释。但是,我不断收到 HTTPMedi
Requestbody 没有映射到我在这里使用的对象。 PaymentRequest 中的所有字段都为空。我看到注释和映射一切似乎都是正确的。 @RestController @RequestMapp
假设以下 JSON: { "attr_A": "val_A", "array_A": [{ "attr_B": "val_B" }] } 以及以下两个类: public class C
JavaScript 代码: function deleteMarks(list){ $http.post('/api/marks/delete/all',list).then( fu
我是 Java/Spring 的新手,正在尝试在现有项目中设置 API 端点。我基本上已经复制了一些当前正在工作的其他端点,但我的端点在被击中时没有验证,这似乎是因为 @RequestBody 没有填
我正在使用 postman 来测试我的请求。所以我从 postman 那里选择了显示代码 fragment 的选项并选择了 OkHttp fragment 是: OkHttpClient client
我使用 Spring-boot 2.0.1 和 WebFlux 作为 Rest 服务器。 在我的 RestController 中,我想自动反序列化一个对象(产品)。但我收到 Jackson 错误,就
我创建了一个简单的 REST 服务 (POST)。但是当我从 postman 那里调用这个服务时,@RequestBody 没有收到任何值。 import org.springframework.ht
PostMan传参给@RequestBody(接受前端参数) 今天新接手一个项目框架,需要改造,但后台写好方法,准备用postman 测试时候,发现用以前传参方式不行,需要需要将json字符串转成
springmvc @RequestBody String类型参数 通过如下配置: <bean id="mappingJacksonHttpMessageConverter&qu
目录 SpringMVC @RequestBody为null 关于inputsteam的一些理解 @RequestBody 自动映射原理的简单介
我是一名优秀的程序员,十分优秀!