我尝试将json发送到控制器,但我无法在控制器上获得。服务器以415状态响应。我做错了什么?我在控制器上尝试了不同的类型,但它仍处于415状态。 Spring 4,Spring Boot使用 我的json:
@RequestMapping(value = "/test/{id}", method = RequestMethod.POST ,consumes = "application/json")
public void test(@RequestBody Foo allRequestParam){
System.out.println(allRequestParam);
}
我的控制器:
public class Foo implements Serializable {
private static final long serialVersionUID = -5054749928374932861L;
private String test;
private String right;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public String getRight() {
return right;
}
public void setRight(String right) {
this.right = right;
}
public Foo() {
}
public Foo(String test, String right) {
this.test = test;
this.right = right;
}
}
我的Foo:
@EnableAsync
@Configuration
@ComponentScan("base")
@EnableTransactionManagement
@EnableWebMvc
@EnableJpaRepositories({"base.contracts.repository", "base.edocs.repository"})
public class AppConfig extends WebMvcConfigurerAdapter {
private static final Logger logger = Logger.getLogger(AppConfig.class);
/*...some config......*/
@Bean
public MappingJackson2HttpMessageConverter jsonConverter(){
return new MappingJackson2HttpMessageConverter();
}
}
我把jackson包含在我的pom.xml和我的AppConfig中:
SharedPreferences