- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
enter image description here > 被这个问题困扰了好几天了。我相信这个问题必须做
with the class itself. Or the relationship between the class in question and the class its column is joined on.
Here are my classes: Mod
package com.matt.Keyword.models;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Entity
@Table(name = "Mods")
public class Mod {
@Id
@GeneratedValue
private int id;
@NotNull
private Integer role;
@NotNull
@Size(min = 1, message = "An entry is required")
private String entry;
@Column(name = "user_id")
private Integer userid;
public Mod(Integer role, String entry) {
this.role = role;
this.entry = entry;
}
public Mod() {
}
public int getId() {
return id;
}
public int getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
public String getEntry() {
return entry;
}
public void setEntry(String entry) {
this.entry = entry;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid= userid;
}
}
帐户
package com.matt.Keyword.models;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Entity
public class Account {
@Id
@GeneratedValue
private int id;
@NotNull
@Size(min = 3, message = "Try again")
private String name;
@NotNull
@Size(min = 1, message = "A password is required")
private String password;
@Column(name = "user_id")
private Integer userid;
public Account(String name, String password) {
this.name = name;
this.password = password;
}
public Account() {
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
}
Account and Mod classes are very similar and share a relationship with the user_id column in the user class.
用户
package com.matt.Keyword.models;
import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.List;
@Entity
public class User {
@Id
@GeneratedValue
@Column(name = "user_id")
private int id;
@Size(min=3, message = "Try again")
private String email;
@Size(min=1, message = "A password is required")
private String password;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private List<Account> accounts;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private List<Mod> mods;
public User(String email, String password) {
this.email = email;
this.password = password;
}
public User() {}
public int getId() {
return id;
}
public void setId(Integer id){
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Account> getAccounts() {
return accounts;
}
public void setAccounts(List<Account> accounts) {
this.accounts = accounts;
}
public List<Mod> getMods() {
return mods;
}
public void setMods(List<Mod> mods) {
this.mods = mods;
}
@Override
public String toString()
{
return email + " " + password;
}
}
The exception gets thrown when I load the index page from my mods controller. I am using thymeleaf to render views. Here is my mods controller. The Mods database has objects saved to it and in this controller during debugging the attribute being passed to the view contains a populated list of Mod objects. ModController
package com.matt.Keyword.controllers;
import com.matt.Keyword.models.Mod;
import com.matt.Keyword.models.User;
import com.matt.Keyword.models.data.ModDao;
import com.matt.Keyword.models.data.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
//test commit note
//second try
//third try
/**
* Created by LaunchCode
*/
@Controller
@RequestMapping("mod")
public class ModController {
@Autowired
private UserDao userDao;
@Autowired
private ModDao modDao;
@RequestMapping(value = "")
public String index(Model model, HttpSession session) {
if (session.getAttribute("currentUser") == null) {
return "redirect:/keyword/login";
}
session.getAttribute("currentUser");
model.addAttribute("title", "Mods");
model.addAttribute("mods", modDao.findAll());
return "mods/index";
}
@RequestMapping(value = "add", method = RequestMethod.GET)
public String displayModForm(Model model, HttpSession session) {
if (session.getAttribute("currentUser") == null) {
return "redirect:/keyword/login";
}
model.addAttribute("title", "Add a new mod");
model.addAttribute(new Mod());
return "mods/add";
}
@RequestMapping(value = "add", method = RequestMethod.POST)
public String processAddModForm(@ModelAttribute @Valid Mod newMod,
Errors errors, Model model, HttpSession session) {
if (errors.hasErrors()) {
model.addAttribute("title", "List of Mods");
return "mods/add";
}
User currentUser = (User) session.getAttribute("currentUser");
session.getId();
currentUser.setId(currentUser.getId());
newMod.setUserid(currentUser.getId());
modDao.save(newMod);
return "redirect:";
}
}
Here is the mod/index page using thymeleaf.
模组/指数
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head th:replace="fragments :: head"></head>
<body class="container">
<h1 th:text="${title}">Default Title</h1>
<p th:unless="${mods} and ${mods.size()}">No current mods</p>
<nav th:replace="fragments :: navigation"></nav>
<p th:text="${session.currentUser.email}"></p>
<table class="table">
<tr>
<th>Type</th>
<th>Entry</th>
</tr>
<div th:if="${mods} != null">
<tr th:each="mod : ${mods}">
<div th:if="${mod.userid} == ${session.currentUser.id}">
<td th:text="${mod.role}"></td>
<td th:text="${mod.entry}"></td>
</div>
</tr>
</div>
</table>
</body>
</html>
The exception seems to be associated with the for th:each statement. Particularly with the "mod" iterator variable. Here is the stack trace for the full error: Trace
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/mods/index.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/mods/index.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.standard.processor.StandardEachTagProcessor' (template: "mods/index" - line 21, col 17)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
... 52 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.standard.processor.StandardEachTagProcessor' (template: "mods/index" - line 21, col 17)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117)
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314)
at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleOpenElementEnd(TemplateHandlerAdapterMarkupHandler.java:304)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:278)
at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleOpenElementEnd(OutputExpressionInlinePreProcessorHandler.java:186)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:124)
at org.attoparser.HtmlElement.handleOpenElementEnd(HtmlElement.java:109)
at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297)
at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402)
at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159)
at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301)
... 54 more
Caused by: java.lang.IllegalArgumentException: Iteration variable cannot be null
at org.thymeleaf.util.Validate.notNull(Validate.java:37)
at org.thymeleaf.standard.expression.Each.<init>(Each.java:49)
at org.thymeleaf.standard.expression.EachUtils.composeEach(EachUtils.java:169)
at org.thymeleaf.standard.expression.EachUtils.internalParseEach(EachUtils.java:94)
at org.thymeleaf.standard.expression.EachUtils.parseEach(EachUtils.java:65)
at org.thymeleaf.standard.processor.StandardEachTagProcessor.doProcess(StandardEachTagProcessor.java:59)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
... 67 more
感谢任何帮助。预先感谢您看看是否你有时间。
Debugger in mod controller Here is a to link to my repo if you want to download it and give it a run.
最佳答案
事实证明,这个问题是一个相当棘手的问题。其决议的故事如下...
通过堆栈跟踪判断:
Caused by: java.lang.IllegalArgumentException: Iteration variable cannot be null
thymeleaf 模板中有一个迭代,其中有 null
正在迭代的变量。唯一使用th:each
我能找到的是:
<div th:if="${mods} != null">
<tr th:each="mod : ${mods}">
...
</tr>
</div>
看来mods
是null
因此th:each="mod : ${mods}"
这就是问题所在。
但是,对此进行了检查 <div th:if="${mods} != null">
。或者有吗?以下内容会更有用吗:
<div th:if="${mods != null}">
即。移动}
这样null
检查是否在表达式内。
这没有帮助,所以结果是 modDao.findAll()
经过检查,发现了两个元素。所以它一定是别的东西。
查看 basics of iteration in Thymeleaf建议也许 findAll()
返回的集合不是 th:each
支持的类型之一可以迭代。
因此这个集合被复制到 Iterable
中并给出不同的名称,问题就解决了。
有趣的是,如果迭代变量的名称为 mod
问题仍然出现。结果mod
是 Thymeleaf 中的关键字,用于模运算 ( %
)。
最终,看似正确的代码存在两个问题:
th:each
迭代的集合。 ;和mod
是 Thymeleaf 中的关键字,不应用作变量名。关于java.lang.IllegalArgumentException : Iteration variable cannot be null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54453156/
最近开始学习oracle和sql。 在学习的过程中,我遇到了几个问题,我的 friend 在接受采访时被问到这些问题。 SELECT * FROM Employees WHERE NULL IS N
这个问题在这里已经有了答案: Can we subtract NULL pointers? (4 个回答) 关闭 2 个月前。 是否定义了NULL - NULL? (char *)NULL - (ch
是否有推荐的方法(根据 .net Framework 指南)检查 null,例如: if (value == null) {//code1} else {//code2} 或 if (value !=
我正在尝试将值插入数据库,但出现这样的错误任何人都可以告诉我为什么该值为空,如下所示: An exception occurred while executing 'INSERT INTO perso
这个问题在这里已经有了答案: String concatenation with a null seems to nullify the entire string - is that desire
您好,我正在 Android 联系人搜索模块中工作。我正在查询下方运行。 cur = context.getContentResolver().query(ContactsContract.Data.
下面的 SQL 表定义说明了从我的 MYSQL 数据库创建表的语句之一,该数据库是由我公司的前开发人员开发的。 DROP TABLE IF EXISTS `classifieds`.`category
我主要有应用程序开发背景。在编程语言中 variable == null或 variable != null有效。 当涉及到 SQL 时,以下查询不会给出任何语法错误,但也不会返回正确的结果。 sel
我在尝试检查某些元素是否为 NULL 时遇到段错误或不。任何人都可以帮忙吗? void addEdge(int i, int j) { if (i >= 0 && j > 0)
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
下面查询的关系代数表达式是什么?我找不到“Is Null”的表达式。 SELECT reader.name FROM reader LEFT JOIN book_borrow ON reader.ca
我正在尝试使用三元运算符来检查值是否为 null 并返回一个表达式或另一个。将此合并到 LINQ 表达式时,我遇到的是 LINQ 表达式的 Transact-SQL 转换试图执行“column = n
我在给定的代码中看到了以下行: select(0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL, &timeout); http://linux
var re = /null/g; re.test('null null'); //> true re.test('null null'); //> true re.test('null null')
这个问题在这里已经有了答案: 关闭 13 年前。 我今天避开了一场关于数据库中空值的激烈辩论。 我的观点是 null 是未指定值的极好指示符。团队中有意见的其他每个人都认为零和空字符串是可行的方法。
由于此错误,我无法在模拟器中运行我的应用: Error:null value in entry: streamOutputFolder=null 或 gradle - Error:null value
我正在尝试在 Android 应用程序中创建电影数据库,但它返回错误。知道这意味着什么吗? public Cursor returnData() { return db.query(TABLE
我一直在检查浏览器中的日期函数以及运行时间 new Date (null, null, null); 在开发工具控制台中,它给出了有效的日期 Chrome v 61 回归 Sun Dec 31 189
为什么 NA==NULL 会导致 logical (0) 而不是 FALSE? 为什么 NULL==NULL 会导致 logical(0) 而不是 TRUE? 最佳答案 NULL 是一个“零长度”对象
我是一名优秀的程序员,十分优秀!