Home > Enterprise >  How to write the request url if have a two path variable in Spring?
How to write the request url if have a two path variable in Spring?

Time:04-06

I have two pages: studentExam and accessedExam. In the accessedExam page, I have implement the pagination using the PagedListHolder.

In order navigate back and forth, I have add the path variable of the page number in the request url. But I failed to link this between this two pages with the button because the program always indicate that the request url is false. My question is how to write the request url if have a two path variable in Spring?

Below are the getMapping for the studentExam and accessedExam

@GetMapping("/student_Exam")
    public String viewStudentHomePage(Model model, Principal principal) {
        model.addAttribute("user",new User());
        model.addAttribute("exam",new Exam());
            
        User user = userService.findUserByEmailPrincipal(principal.getName());      
        
        model.addAttribute("profile_Username", user.getUsername());
        model.addAttribute("enrolledExamList",user.getRegisteredExam());
        
        return "/student/studentExam";
    }
@GetMapping("/exam/{id}/{pageNumber}")
public String viewExamPage(Model model, Principal principal,@PathVariable( name= "id") Long examId, @PathVariable(name="pageNumber") int pageNumber) {
}

The button that I used to navigate from studentExam to accessedExam page

<div  style="width: 18rem;" th:each = "exam:${enrolledExamList}">                      
    <a id="exmRedirectBtn" th:href = "@{/exam/{id}/{pageNumber}(id=${exam.id})(pageNumber=${pageNumber})}" >Access</a>
</div>  

CodePudding user response:

See the docs for standard url syntax .

th:href="@{/exam/{id}/{pageNumber}(id=${exam.id}, pageNumber=${pageNumber})}"
  • Related