简体   繁体   English

Spring 启动 thymeleaf 映射对我不起作用

[英]Spring boot thymeleaf mapping is not working for me

I know theres a similar question in stackoverflow like mine.我知道 stackoverflow 中有一个类似的问题,就像我的一样。 I tried every answer that i could from this question none of these worked: Thymeleaf using path variables to th:href我尝试了从这个问题中可以得到的所有答案

Can you help me what did i wrong in my thymeleaf page?你能帮我在我的 thymeleaf 页面中做错了什么吗? URL that i would like to reach: localhost:8081/students/{stu_id}我想访问的 URL:localhost:8081/students/{stu_id}

My GetMapping looks like:我的 GetMapping 看起来像:

@GetMapping("/students")
    public ModelAndView viewStudentPage() {
        List<Student_Dim> listStudent = studentService.getAllStudents();
        return new ModelAndView("students","students", listStudent);
    }

@GetMapping("/students/{id}")  
    private ModelAndView getInfo(@PathVariable("id") String stu_id){
        Student_Dim student = studentService.getStudentById(stu_id);
        return new ModelAndView("student","student",student);
    } 

Href that i use (students.html):我使用的 Href(students.html):

<tbody>
            <tr th:each="student : ${students}">
                <td th:text="${student.stu_fname}">First Name</td>
                <td th:text="${student.stu_lname}">Last Name</td>
                <td th:text="${student.dep_code}">Department Code</td>
                <td th:text="${student.fac_code}">Faculty Code</td>
                <td th:text="${student.loc_code}">Location Code</td>
                <td th:text="${student.marriage_status}">Marriage Status</td>
                <td th:text="${student.address}">Address</td>
                <td>
                    <a href="@{/students/{id}(id=${student.stu_id})}">Edit</a>
                </td>
            </tr>
        </tbody>

You are using thymeleaf expression inside <a> tag.您在<a>标记内使用 thymeleaf 表达式。 You have to use th:href instead of href .您必须使用th:href而不是href

    <td>
        <a th:href="@{/students/{id}(id=${student.stu_id})}">Edit</a>
    </td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM