user8421021
user8421021

Reputation:

Passing two values from HTML to Controller using Thymeleaf th:href

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?

Upvotes: 0

Views: 4843

Answers (1)

Metroids
Metroids

Reputation: 20477

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})}"

Upvotes: 1

Related Questions