为什么我在Thymeleaf中的锚标记未重定向到本地文件

问题描述

我正在尝试使用aThymeleaf中的Spring boot标记重定向到另一个本地网页,但这是 不工作。我正在从index.html重定向到同一文件夹中的addEdit.html

这是我的代码。

index.html

<div class="container">
          <p th:text="${message}"></p>
          <a th:href="@{/addEdit.html}" class="btn btn-outline-info">Add Employee</a> //not working
           <table class="table table-bordered table-dark">
               <thead class="">
                   <tr> 
                        <th>#</th>
                        <th>Name</th>
                        <th>Departmen</th>
                        <th>Position</th>
                         <th></th>
                         <th></th>
                       
                   </tr>
               </thead>
               
               <tbody>
                    <tr th:each="employee : ${employees}" >
                         <th th:text="${employee.id}"></th>
                         <td th:text="${employee.name}"></td>
                         <td th:text="${employee.department}"></td>
                         <td th:text="${employee.position}"></td>
                         <td>
                             <form action="delete">
                                <input type="submit" value="Delete" class="btn btn-outline-warning"/>
                             </form>
                         </td>
                          <td>
                             <form action="edit">
                                <input type="submit" value="Edit" class="btn btn-outline-info"/>
                             </form>
                         </td>
                    </tr>
                   
               </tbody>
               
           </table>
          </div>

我的EmployeeController

 @Autowired
 private employeeRepo repo;
 
 @RequestMapping("/")
 public String home(Model model) {
     List<Employee> list = new ArrayList<>();
     list = repo.findAll();
     model.addAttribute("employees",list);
     return "index";
 }
 
 @PostMapping("/addEmployee")
 public void addEmployee(Employee employee,Model model) {
     repo.save(employee);
     model.addAttribute("message","Add Successfully");
     home(model);
 }

我的addEdit.html

<div class="container bg-light">
      <form action="addEmployee">
            <input class="form-control form-control-sm" type="text" placeholder="Name" name="name"><br>
            <input class="form-control form-control-sm" type="text" placeholder="Department" name="department"><br>
            <input class="form-control form-control-sm" type="text" placeholder="Position" name="postion"><br/>
            <input type="submit" value="Add Employee" class="btn btn-outline-success btn-lg btn-block">
      </form>
 </div>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)