【问题标题】:Parameter conditions "dietaryrestrictionssearches" not met for actual request parameters: active={304, 305}实际请求参数不满足参数条件“dietaryrestrictionssearches”: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<Integer> dietaryrestrictionssearches,
                                    Errors errors, Model model) {

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

        if (!dietaryrestrictionssearches.isEmpty()) {

            List<DietaryRestrictionsSearch> drsObjs = (List<DietaryRestrictionsSearch>) 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<User> getUsers() {
        return users;
    }

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

    @ManyToMany(mappedBy="dietaryrestrictionssearches")
    private List<User> 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,但没有看到任何附加信息。你做了某种改变吗?对不起,如果我错过了。

标签: java intellij-idea mysql-workbench


【解决方案1】:

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

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

伊万

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 2012-02-14
    • 2014-05-01
    • 2012-03-22
    相关资源
    最近更新 更多