Java Spring/Thymeleaf:在null上找不到属性或字段,但仍在呈现

Java Spring/Thymeleaf:在null上找不到属性或字段,但仍在呈现,java,sql,spring,jdbc,thymeleaf,Java,Sql,Spring,Jdbc,Thymeleaf,我有一个Spring/Thymeleaf应用程序 org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'projectName' cannot be found on null 但是,页面看起来很正常。所有变量都使用数据进行渲染。我只是担心每个请求都会抛出异常 这是控制器: @Controller @RequestMapping("/download")

我有一个Spring/Thymeleaf应用程序

org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'projectName' cannot be found on null
但是,页面看起来很正常。所有变量都使用数据进行渲染。我只是担心每个请求都会抛出异常

这是控制器:

@Controller
@RequestMapping("/download")
public class AppDownloaderController {

    @Autowired
    InstallLinkJoinedService installLinkJoinedService;

    @RequestMapping(value = "/link/{installLink}", method = RequestMethod.GET)
    public String getInstallLink(Model model, @PathVariable("installLink") String installLink) {
        InstallLinkJoined installLinkJoined = installLinkJoinedService.getInstallLinkWithID(installLink);
        if (installLinkJoined != null) {
            model.addAttribute("install", installLinkJoined);
        }
        return "download";
    }
}
有关html的一个片段:

<h3 class="achievement-heading text-primary" th:text="${install.projectName}"></h3>
我有所有领域的接受者和接受者

如果我注释掉有问题的行,我只会在下一个变量中得到一个异常

而且,如前所述,页面中的所有数据都显示出来了,因此模型对象显然不是空的


我遗漏了什么?

您正在通过检查null来添加
install
属性,如果它为null,则不会初始化任何内容&然后您在jsp
th:text=“${install.projectName}”
,因此它表示在null上找不到

所以换成

InstallLinkJoined installLinkJoined = installLinkJoinedService.getInstallLinkWithID(installLink);
if (installLinkJoined != null) {
    model.addAttribute("install", installLinkJoined);
} else {
    model.addAttribute("install", new InstallLinkJoined());
}

工作得很有魅力!
InstallLinkJoined installLinkJoined = installLinkJoinedService.getInstallLinkWithID(installLink);
if (installLinkJoined != null) {
    model.addAttribute("install", installLinkJoined);
} else {
    model.addAttribute("install", new InstallLinkJoined());
}