'Parameter conditions "dietaryrestrictionssearches" not met for actual request parameters: active={304, 305}
my controller and model. I check two checkboxes and it should put those values 30 and 305 into table but I get this message. Any help would be appreciated
@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
Solution 1:[1]
The message says that you are sending 1 parameter with name 'active' with that values, but the endpoint /add require also a parameter called dietaryrestrictionssearches so it does not satisfy the request.
If what you send is right and you don't need that dietaryrestrictionssearches , simply change it in a @RequestParam (name ="dietaryrestrictionssearches ")
Ivan
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ivan.rosina |