处理 raw 原始数据,例如提交的时 application/json, application/xml等
@RequestMapping(value = "/something", method = RequestMethod.PUT)
public void handle(@RequestBody String body, Writer writer) throws IOException {
writer.write(body);
}
package cn.netkiller.api.restful;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestRestController {
@RequestMapping(value = "/test/list/{siteId}", method = RequestMethod.POST)
public List<String> ping(@PathVariable("siteId") int siteId, @RequestBody List<String> tags) {
System.out.println(String.format("%d, %s", siteId, tags));
return (tags);
}
}
$ curl -H "Content-Type: application/json" -X POST -d '["Neo","Netkiller"]' http://localhost:8440/test/list/22.json
["Neo","Netkiller"]
@PostMapping("/finance/list")
public String financeList(@RequestBody Map<String,String> map) {
return financeService.financeList(map);
}
% curl -H "Content-Type: application/json" -X POST -d '{"date":"2017-11-08"}' http://localhost:8440/finance/list.json