基于spring-MVC开发一个HTTP接口还是比较简单的,没啥好说的,直接上代码
@RestController
@RequestMapping("/demo")
public class test {
@RequestMapping(value = "/test",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public xx test(@RequestBody Map<String, Object> paramMap) {
}
以上是简单的一个示例,HTTP路径为http://localhost:8080/demo/test限制了传参与返回都是JSON格式的数据,方便对接。遇到获取不到请求参数的情况请在参数前加@RequestMapping注解。