如何解决尝试更新我的数据库中的原始文件时,BeanResult'fileName'的BindingResult或普通目标对象都可以作为请求属性“
在尝试更新数据库中的一行时遇到此异常。我在Google进行了很多研究,发现我应该添加已经完成的@modelAttribute。
我还发现我需要在@ModelAttribute之后添加bindind结果,但这也不起作用,因此我将其删除。我使用JPA进行持久性处理数据,使用spring boot和thymeleaf进行视图处理。
-
这些是我的控制器之一,用于更新和渲染视图
@GetMapping("/edit/{id}") public ModelAndView UpdateList(@PathVariable(name="id") String id) { ModelAndView mav = new ModelAndView("updateList"); com.pfe.ClientRest.model.Files files = fileServ.get(id); mav.addObject("Files",files); return mav ; } @PostMapping("/Save") public String saveRepport(@ModelAttribute("Files") com.pfe.ClientRest.model.Files dbfile) { fileServ.save(dbfile); return "/redirect:/ListFile"; }
-
这是我的实体类,我有getter的设置方法和构造方法
@Table( name="Files") @Entity public class Files { @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid",strategy = "uuid2") @Id private String id; private String FileName; private String Verif; public String getId() { return id; }
这是我的模板。
<div class="container">
<h1> Modifier les informations du Rapports</h1>
<form action="#" th:action="@{/Save}" th:objects="${Files}"
method="post" >
<input type="text" th:field=*{id} readonly="readonly"/>
<input type="text" th:field="*{fileName}" placeholder="Nom du Fichier"
class="form-control mb-4
col-4">
<input type="text" th:field="*{verif}" placeholder="Accepted/Rejected"
class="form-control mb-4
col-4">
<button type="submit" class="btn btn-info col-2"> Mettre à jour</button>
</form>
</div>
解决方法
html页面和实体类中的字段名称不匹配。这些区分大小写。所以正确的应该是
private String fileName;
private String verif;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。