0

I want to pass 2 values from html link to my controller.

<a th:href="@{/classesTable/saveProfessor/{professorId}/{classesId} (profesorId=${professor.id}), (classesId=${classes.id})}"</a>

And here is my controller

@RequestMapping(value = "/classesTable/saveProfessor/{professorId}/{classesId}")
public ModelAndView saveClassesProfessor(@RequestParam("classesId") long classesId,
                                         @RequestParam("professorId") long professorId) {

    Classes classes = classesRepository.findOne(classesId);
    Profesor profesor = professorRepository.findOne(professorId);

    classes.getProfesors().add(professor);
    profesor.getClasses().add(classes);

    return new ModelAndView("redirect:/classesTable");
}

First I was just passing professor ID like this

<a th:href="@{/classesTable/saveProfessor/{professorId} (profesorId=${professor.id})"</a>

And it would recognize ID from professor when I would hover over link. But when I added classesId like in example above, URL in my browser looks like this.

http://localhost:8080/classesTable/saveProfesor/%7BprofesorId%7D/19%20(profesorId=$%7Bprofesor.id%7D),

Number 19 is actually ID of my classes. I am getting 404 error. What am I missing here?

1 Answer 1

1

You have a typo and the syntax of your url is a bit off. It should look like this:

th:href="@{/classesTable/saveProfessor/{professorId}/{classesId} (professorId=${professor.id}, classesId=${classes.id})}"
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, problem was in my brackets. Don't know how did I miss it. Thank you for help. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.