实际请求参数不满足参数条件“dietaryrestrictionssearches”:active={304, 305}

分享于2022年07月17日 intellij-idea java mysql-workbench 问答
【问题标题】:实际请求参数不满足参数条件“dietaryrestrictionssearches”:active={304, 305}(Parameter conditions "dietaryrestrictionssearches" not met for actual request parameters: active={304, 305})
【发布时间】:2022-05-08 00:44:08
【问题描述】:

我的控制器和模型。我选中了两个复选框,它应该将这些值 30 和 305 放入表中,但我收到了这条消息。任何帮助将不胜感激

@RequestMapping(value="/add",method=RequestMethod.POST, params = {"dietaryrestrictionssearches"})
    public String processUserDietaryRestrictions(@ModelAttribute @Valid User newUser,

                                    @RequestBody List dietaryrestrictionssearches,
                                    Errors errors, Model model) {

        if (errors.hasErrors()) {
            model.addAttribute("title", "AddUserRestriction");
            return "add";
        }

        if (!dietaryrestrictionssearches.isEmpty()) {

            List drsObjs = (List) dietaryRestrictionsRepository.findAllById(dietaryrestrictionssearches);
            if (!drsObjs.isEmpty()) {
                newUser.setDietaryrestrictionssearches(drsObjs);
            }
            userRepository.save(newUser);
            return "redirect:/selection/" + newUser.getId();
        }
        return "redirect:../add";
    }


@Entity
public class DietaryRestrictionsSearch {

    @Id
    private int restrict_id;

    @Column
    private String restrictions;

    public List getUsers() {
        return users;
    }

    public void setUsers(List users) {
        this.users = users;
    }

    @ManyToMany(mappedBy="dietaryrestrictionssearches")
    private List users = new ArrayList<>();

    public DietaryRestrictionsSearch() {}


    public DietaryRestrictionsSearch(String restrictions, int restrict_id) {
        super();
        this.restrictions = restrictions;
        this.restrict_id = restrict_id;
    }
  //getters and setters

  • 我查看了您的 cmets,但没有看到任何附加信息。你做了某种改变吗?对不起,如果我错过了。

【解决方案1】:

消息说您正在发送 1 个名称为“active”的参数,该参数具有该值,但端点 /add 还需要一个名为 dietrestrictionssearches 的参数,因此它不能满足请求。

如果您发送的内容是正确的并且您不需要 Dietrestrictionssearches,只需在 @RequestParam (name ="dietaryrestrictionssearches") 中更改它

伊万