ISSUE: I am trying to POST to an array to a controller but nothing seems to be happening, there is no info in the logs or on the terminal
I have a JSON array as follows
[
{
"artifact_id": 10,
"session_id":45,
"user_id": "user99"
}
]
I am trying to use this with a.saveAll() from my CRUD repo but nothing seems to happen it does not even seem to print my System.out.print("test"); message. My @Entity class is as follows
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ESearch_results", schema = "public")
public class ESearchResponse {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "primary_key", nullable = false)
int primary_key;
@Column(name = "artifact_id")
int artifact_id;
@Column(name = "session_id")
int session_id;
@Column(name = "user_id")
String user_id;
}
my controller is as follows
@RestController
public class EsearchTestController {
@Autowired
private EsearchResponseService EsearchResponseService;
@CrossOrigin
@PostMapping("/justATest")
public String testController(@RequestBody List<ESearchResponse> ESearchResponseTypo){
String result = "this test passed";
// System.out.print("\u001B[35m"+EsearchResponseService.saveESearchResult(ESearchResponseTypo));
System.out.print("\u001B[35m"+ESearchResponseTypo.size());
EsearchResponseService.saveESearchResult(ESearchResponseTypo);
return result;
}
}
I have tried many things and I believe my root issue here is the way I am passing the JSON array in the request body.
Try add a @RequestMapping("/some_path")
to your controller.
I used to getting the same problem, and it was the lack of @RequestMapping
annotation in my case.
And be careful of your port settings in properties
file:
server.port=8000
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.