EL1007E:在NULL上找不到属性或字段'fieldName' [英] EL1007E: Property or field 'fieldName' cannot be found on null

查看:44
本文介绍了EL1007E:在NULL上找不到属性或字段'fieldName'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好,我已经没有解决办法了1.我一直在犹豫要不要寻求帮助,但我几乎走进了死胡同。 我正在做一个Spring Boot 2.0.5 Spring MVC 5.0.9,ThymeLeaf 3.0.9项目,需要在几周内删除。我已经遇到问题好几个星期了……我做了研究,尝试了所有可能的解决方案,我仍然有同样的问题。 事实上,我的控制器没有将我的模型变量绑定到我的视图……它总是呈现"EL1007E:属性或字段‘fieldName’无法在NULL上找到"。 我几乎什么都试过了(因为我的代码很好)..

  1. 升级和降级JDK/JRE并将它们与Eclipse版本进行匹配曾经奏效过一次,得到了我需要的信息,但随后又得到了同样的问题。
  2. 使用ModelAndView而不是字符串呈现网页

  3. MVN CLEAN/MVN INSTALL/MVN Dependency:解析.我找到的每个命令都有帮助

  4. 删除./m2存储库中不必要的依赖项
  5. 甚至设置新工作区..编译调试 我真的卡住了.. 你能给我一些建议吗!!
<!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}

因此它尝试显示模型属性paramSociete的属性nomSociete。错误消息告诉您

Property or field 'nomSociete' cannot be found on null 

SOparamSociete为空。这意味着没有这样的模型属性。我们来查一下。在显示该页面之前,您是否在模型中添加了这样的属性?映射到浏览器位置栏中的URL的控制器方法只有

@RequestMapping(value="/")
public String showTest() {
    System.out.println("Here we go !!");
    return "ThymeTest";
}

所以它会显示您的视图,但是没有,模型中根本没有属性。这说明paramSociete为空。

就这么简单。如果希望页面显示公司名称,则该公司必须存在。

这篇关于EL1007E:在NULL上找不到属性或字段&#39;fieldName&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆