@JsonAutoDetect
public class Params {
private int[][] matrix;
private int row;
private int col;
private int num;
[...getters and setters]
@PostMapping(path = "/check")
@CrossOrigin(origins = "http://localhost:3000")
public boolean check(@RequestBody final Params params) {
return sudokuGenerator.checkValue(params.getMatrix(), params.getRow(), params.getCol(), params.getNum());
}
至关重要的是,客户端应该传递带有其属性的对象,而没有任何类型的包装,因此采用这种方式:
axios.post('http://localhost:8090/api/check', {
matrix: this.props.rows,
"row": row - 1,
"col": col - 1,
"num": input.textContent
})
而不是以这种方式(带有根属性“ params”):
axios.post('http://localhost:8090/api/check', {
"params" : {
matrix: this.props.rows,
"row": row - 1,
"col": col - 1,
"num": input.textContent
}
})