Java 如何在插入后自动更新视图

Java 如何在插入后自动更新视图,java,spring,spring-boot,spring-mvc,spring-data-jpa,Java,Spring,Spring Boot,Spring Mvc,Spring Data Jpa,我试图在插入数据库后自动更新视图(这里的列表名为emprunts)。我使用Springboot、H2、JPA、Thymeleaf 有办法吗?或者我必须在插入后使用Get请求刷新页面 非常感谢 HTML/View ... <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionEmprunts"> <div class="card-body"

我试图在插入数据库后自动更新视图(这里的列表名为
emprunts
)。我使用Springboot、H2、JPA、Thymeleaf

有办法吗?或者我必须在插入后使用Get请求刷新页面

非常感谢

HTML/View

...
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionEmprunts">
   <div class="card-body">
      <table class="table">
            <thead>
                  <tr>
                       <th scope="col">Usager</th>
                       <th scope="col">Exemplaire</th>
                       <th scope="col">Date de rendu</th>
                       <th scope="col">Statut</th>
                   </tr>
             </thead>
             <tbody>
                   <th:block th:each="emprunt : ${emprunts}">
                       <tr>
                       <!--/*@thymesVar id="emprunt" type="bibliotheque.model.Emprunt"*/-->
                           <td th:text="${emprunt.getUsager().getMail()}"></td>
                           <td th:text="${emprunt.getExemplaire().getOeuvre().getTitre()}"></td>
                           <td th:text="${emprunt.getDaterendu()}"></td>
                           <td th:text="${emprunt.getStatut()}"></td>
                        </tr>
                   </th:block>
              </tbody>
         </table>
    </div>
</div>
...
。。。
使用者
榜样
人渡日期
身材
...
控制器

@PostMapping
public ResponseEntity<?> newEmprunt(HttpEntity<String> infoEmprunt) throws IOException {
    ...
    repository.save(object);
    return new ResponseEntity<>(HttpStatus.CREATED);
}
@PostMapping
公共响应性newEmprunt(HttpEntity infoEmprunt)引发IOException{
...
保存(对象);
返回新的ResponseEntity(HttpStatus.CREATED);
}

如果您的视图技术是thymeleaf,则返回html页面而不是返回ResponseEntity(因为响应实体将返回json格式的数据),并在模型属性中添加数据

有办法吗?或者我必须在插入后使用Get请求刷新页面

无需刷新页面,只需从控制器返回html页面,如下所示

Emprunt emprunt = repository.save(object);    
model.addAttribute("emprunt", emprunt);    
return "show"; //show.html page

是的,我用百里香。好的,我需要使用
modelAndView.setStatus(404)
。最后,我返回的模型和视图以及列表内容将自动更新?为此,您可以在thymeleaf页面本身中执行空或空检查。因此,如果状态为404,则显示消息1;如果状态为403,则显示消息2,等等?并删除所有相关JS?我问了一个新问题:。也许你能帮我。。。