0
Follow
0
View

The SpringBoot form is saved

m15797953108 未验证用户
2023-02-28 19:28
< div class = " md_content_show“数据- v - 3967 e397 = " " >

@PostMapping("/submitOptions")
@ResponseBody
public AjaxResult submitOptions(@RequestParam String semester, @RequestParam String options) {
    // 解析前端提交的选项数据
    String[] selectoptions = options.split("&");
    List questionOptions = new ArrayList<>();
    for (String selectoption : selectoptions) {
        String[] optionArray = selectoption.split("=");
        String qidstr = optionArray[1].replace("\"", "");
        Long questionId = Long.parseLong(qidstr);
        String optionValue = optionArray[0];
        QuestionOption questionOption = new QuestionOption();
        questionOption.setQuestionId(questionId);
        questionOption.setOptionValue(optionValue);
        questionOptions.add(questionOption);
    }

    // 查询题目标题并存储
    for (QuestionOption questionOption : questionOptions) {
        Long questionId = questionOption.getQuestionId();
        String optionValue = questionOption.getOptionValue();
        String questionTitle = questionService.getQuestionTitleById(questionId); // 假设查询题目标题的方法为 getQuestionTitleById(Long questionId)
        OverallEvaluation overallEvaluation = new OverallEvaluation();
        overallEvaluation.setSemester(semester);
        overallEvaluation.setQuestionTitle(questionTitle);
        overallEvaluation.setSelfAssessment(optionValue);
        overallEvaluationService.saveOverallEvaluation(overallEvaluation); // 假设保存到数据库的方法为 saveOverallEvaluation(OverallEvaluation overallEvaluation)
    }
    return AjaxResult.success();
}


dunmas 注册会员
2023-02-28 19:28

Monster Group and GPt-based tune-up:
Serializes the form data on the front end into a parameter format that meets the requirements of the backend interface, and sends a POST request to the backend using AJAX.

Here are examples of possible modification code:

function submitData() {
    var formData = $('#form-overallevaluation-add').serialize();
    var semester = '2022-01'; // 替换为您要提交的学期信息
    $.ajax({
        type: "POST",
        url: prefix + "/submitOptions",
        data: {
            semester: semester,
            options: formData
        },
        success: function(result) {
            if (result.code == web_status.SUCCESS) {
                $.modal.msgSuccess("提交成功");
                $.modal.close();
            } else {
                $.modal.msgError(result.msg);
            }
        }
    });
}


The

modified code submits the string returned by the serialize() method to the back end as the options parameter, and the semester parameter is set manually. The back-end interface parameters are also modified accordingly.

dong951113 注册会员
2023-02-28 19:28
< div class = "md_content_show e397 data - v - 3967" = "" >

the back-end how to parse? I also need to query the title of the title through the title ID and then save the database. Would you mind writing a method on the back end?

cxzakira 注册会员
2023-02-28 19:28
https://www.baidu.com/link?url=YIG3sZ7aZYzZ37S-eVxfP0pO9DPpQWXi8AuQyljA05Mcj3Tit505L1WHnIp98bhUhf4kmN5yCy0BakzWj6BSgq& wd =, eqid = c11aa8fa0010a16d0000000263fddc60 < / >
< !- - - - - >

About the Author

Question Info

Publish Time
2023-02-28 19:28
Update Time
2023-02-28 19:28

Related Question

为什么我们使用Optional[ListNode]?

如何让一个Discord机器人有条件地提醒?

使用js和jq无法切换display效果

I get a error for 'useSelector'(action is undefined)

Javascript dynamic form post with paramters to ApiController post method

Visual Studio for Mac 2022预览更改快捷键

删除list[副本]元素中的单词

怎么在list中进行翻译

无法解析模块说明符“form-data”.相对引用必须以“/”,“”开头./"或"../"

拦截并修改某个sql语句(mybatisplus篇)