晚上好,我不再有解决方案。我一直在犹豫是否寻求帮助,但我几乎陷入了死胡同。
我正在开发一个 Spring boot 2.0.5 Spring MVC 5.0.9、ThymeLeaf 3.0.9 项目,需要在几周内交付..我已经遇到了几个星期的问题...做了我的研究并尝试了所有可能的解决方案我仍然有同样的问题。
事实上,我的控制器没有将我的模型变量绑定到我的视图...它总是呈现“EL1007E:无法在 null 上找到属性或字段'fieldName'”..
我几乎尝试了一切(因为我的代码很好)..
- 升级和降级 JDK/JRE 并将其与 Eclipse 版本匹配一次工作,得到了我需要的信息,但随后又遇到了同样的问题。
使用 ModelAndView 而不是 String 来渲染网页
mvn clean/mvn install /mvn dependency:resolve ...我发现有用的每个命令
- 删除 ./m2 存储库以消除不必要的依赖项
- 甚至设置一个新的工作空间..编译调试
我真的被困住了..
你能给我一些建议吗?
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
data-layout-decorate="~{index}">
<head>
<meta charset="UTF-8" />
<title>Page test</title>
</head>
<body>
<div data-layout-fragment="content">
<div class="container">
<div class="row">
<div class="col-sm-6" align="center">
<form th:action="@{/consulter}" method="get"
th:object="${paramSociete}">
<input type="text" name="nomSociete" class="form-control"
placeholder="AMEN BANK" />
<button type="submit">Clique moi !!</button>
</form>
<br /> <br /> <br /> <br />
<div>
<div>
<label>Nom Banque :</label><Label th:inline="text">
[[${paramSociete.nomSociete}]]</Label>
</div>
<div>
<label>Reference msg:</Label><Label th:inline="text">[[${paramSociete.initialMsg}]]</Label>
</div>
<div>
<label>chemin dacces:</label> <Label th:inline="text">[[${paramSociete.pathMsgEmis}]]</Label>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
@Controller
public class ParamSocieteController {
@Autowired
private ParamSocieteServiceImpl societeServiceImpl;
@Autowired
public void setSocieteServiceImpl(ParamSocieteServiceImpl societeServiceImpl) {
this.societeServiceImpl = societeServiceImpl;
}
@RequestMapping(value="/")
public String showTest() {
System.out.println("Here we go !!");
return "ThymeTest";
}
@RequestMapping(value = "/consulter")
public String afficherAmenBank(Model model, String nomSociete) {
ParamSociete societe = societeServiceImpl.findSociete(nomSociete);
if (societe == null) {
model.addAttribute("paramSociete", new ParamSociete());
} else {
model.addAttribute("nomSociete", nomSociete);
model.addAttribute("paramSociete", societe);
System.out.println(societe.getNomSociete());
System.out.println(societeServiceImpl.findSociete(societe.getNomSociete()).toString());
}
return "ThymeTest";
}
}
所以我在控制器中什么也没做,但在我看来是这样做的:
我用 th:if 测试了我的对象是否存在
<div th:if="${paramSociete}">
<div>
<label>Nom Banque :</label><Label th:inline="text">
[[${paramSociete.nomSociete}]]</Label>
</div>
<div>
<label>Reference msg:</Label><Label th:inline="text">[[${paramSociete.initialMsg}]]</Label>
</div>
<div>
<label>chemin dacces:</label> <Label th:inline="text">[[${paramSociete.pathMsgEmis}]]</Label>
</div>
</div>
好的。所以问题非常简单。您的视图有这行代码:
${paramSociete.nomSociete}
所以它尝试显示该属性nomSociete
模型属性的paramSociete
。错误信息告诉你
Property or field 'nomSociete' cannot be found on null
So paramSociete
一片空白。这意味着不存在这样的模型属性。让我们检查。在显示该页面之前,您是否在模型中添加了这样的属性?映射到浏览器地址栏中 URL 的控制器的方法只有
@RequestMapping(value="/")
public String showTest() {
System.out.println("Here we go !!");
return "ThymeTest";
}
因此它显示了您的视图,但是不,模型中根本没有属性。这解释了这一点paramSociete
一片空白。
就如此容易。如果您希望页面显示公司名称,则该公司必须存在。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)