请问这种数组对象格式的前端传到后端,后端如何接收啊。然后保存到数据库要什么格式啊。
我现在后端是这样的,那个TestQuestions字段就是来接收前端试题的。用string格式的一致报错说:Invalid character found in the request target(在请求目标中发现无效字符),请问如何处理呢。我数据库用的text格式接收的。因为题目可能比较多,我准备把所有题目一起存在一个字段内
@RestController
@RequestMapping("/TestQuestions")
public class TestQuestionsController {
@Resource
TestQuestionsMapper testQuestionsMapper;
//保存词条,试卷标题,试卷内容,状态,创建人
@CrossOrigin(origins ="*",maxAge = 3600)
@GetMapping("/setTestQuestions")
public void findContent(@RequestParam("entryName") String entryName, @RequestParam("paperName") String paperName, @RequestParam("paperTitle") String paperTitle, @RequestParam("state") String state,@RequestParam("TestQuestions") String TestQuestions){
testQuestionsMapper.save(entryName,paperName,paperTitle,state,TestQuestions);
}
}
保存的情况一般用post,接实体,你的问题都是json了也就是不固定了,那就直接一个string接吧
@PostMapping("/setTestQuestions")
public void findContent(@RequestBody Questions questions){
testQuestionsMapper.save(questions);
//testQuestionsMapper.save(questions.getEntryName(),questions.getPaperName(),questions.getPaperTitle(),questions.getStatus(),questions.getTestQuestions());
}
public class Questions {
private String entryName;
private String paperName;
private String paperTitle;
private String status;
private String testQuestions;
public String getEntryName() {
return entryName;
}
public void setEntryName(String entryName) {
this.entryName = entryName;
}
public String getPaperName() {
return paperName;
}
public void setPaperName(String paperName) {
this.paperName = paperName;
}
public String getPaperTitle() {
return paperTitle;
}
public void setPaperTitle(String paperTitle) {
this.paperTitle = paperTitle;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTestQuestions() {
return testQuestions;
}
public void setTestQuestions(String testQuestions) {
this.testQuestions = testQuestions;
}
}
搞个VO啊,List
你把你要接收的参数整合到一个类当中,比如A,然后用List<A>接收