2016-12-02 21 views
0

今天你好我正在尝试使用一个html接口将项目添加到mysql数据库。我的错误是我的sql中的一个列不能为空,但我的一个部分的HTML应提供该信息,而不是空。我正在使用Java Spring和Thymeleaf作为我的框架和代码。使用mysql数据库项目制作列表应用程序不会添加

这是错误

2016-12-02 12:43:13.386 WARN 6932 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 23502, SQLState: 23502 
2016-12-02 12:43:13.386 ERROR 6932 --- [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : NULL not allowed for column "PRIORITY"; SQL statement: 
update list_items set contents=?, created_utc=?, is_checked=?, list_id=?, modified_utc=?, priority=? where id=? [23502-192] 
2016-12-02 12:43:13.386 INFO 6932 --- [nio-8080-exec-3] o.h.e.j.b.internal.AbstractBatchImpl  : HHH000010: On release of batch it still contained JDBC statements 
2016-12-02 12:43:15.685 ERROR 6932 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause 

org.h2.jdbc.JdbcSQLException: NULL not allowed for column "PRIORITY"; SQL statement: 
update list_items set contents=?, created_utc=?, is_checked=?, list_id=?, modified_utc=?, priority=? where id=? [23502-192] 

这里是我的HTML

这是我的控制器的一部分。

// GetMapping and PostMapping for editing items in lists. 
    @GetMapping("/ListsofLists/{id}/add") 
    public String listItemAdd(Model model, @PathVariable(name = "id") int id) { 
     model.addAttribute("id", id); 
     ListItem u = listItemRepo.findOne(id); 
     model.addAttribute("list_items", u); 
     return "list_item_add"; 
    } 

    @PostMapping("/ListsofLists/{id}/add") 
    public String listItemSave(@ModelAttribute @Valid ListItem listItem, BindingResult result, Model model) { 
     listItemRepo.save(listItem); 
     return "redirect:/ListsofLists/{id}"; 
    } 

回答

0

如果你更改优先级下拉看起来像这样:

<select th:field="*{priority}"> 
    <option value="0">It can wait</option> 
    <option value="1">Need it soon</option> 
    <option value="2">Grab it now</option> 
</select> 

是否已确认的任何数据绑定到你的对象?您也可能需要@ModelAttribute("list_items")

+0

我刚刚尝试了