2016-12-01 67 views
0

我有問題顯示我的SQL數據庫中的一些信息到Spring框架HTML表。我一直在查找數據庫中的某個項目時出現錯誤,但似乎找不到或看到它。 這是錯誤:試圖從一個SQL數據庫顯示信息到一個HTML表格

2016-12-01 13:40:13.340 WARN 7968 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 42122, SQLState: 42S22 
2016-12-01 13:40:13.340 ERROR 7968 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : Column "LISTITEM0_.SHOPPING_LIST_ID" not found; SQL statement: 
select listitem0_.id as id1_0_, listitem0_.contents as contents2_0_, listitem0_.created_utc as created_3_0_, listitem0_.is_checked as is_check4_0_, listitem0_.modified_utc as modified5_0_, listitem0_.priority as priority6_0_, listitem0_.shopping_list_id as shopping7_0_ from list_items listitem0_ [42122-192] 
2016-12-01 13:40:13.374 ERROR 7968 --- [nio-8080-exec-1] 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.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select listitem0_.id as id1_0_, listitem0_.contents as contents2_0_, listitem0_.created_utc as created_3_0_, listitem0_.is_checked as is_check4_0_, listitem0_.modified_utc as modified5_0_, listitem0_.priority as priority6_0_, listitem0_.shopping_list_id as shopping7_0_ from list_items listitem0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement] with root cause 

org.h2.jdbc.JdbcSQLException: Column "LISTITEM0_.SHOPPING_LIST_ID" not found; SQL statement: 
select listitem0_.id as id1_0_, listitem0_.contents as contents2_0_, listitem0_.created_utc as created_3_0_, listitem0_.is_checked as is_check4_0_, listitem0_.modified_utc as modified5_0_, listitem0_.priority as priority6_0_, listitem0_.shopping_list_id as shopping7_0_ from list_items listitem0_ [42122-192] 

我的HTML文檔是在這裏:

<!DOCTYPE HTML> 
<html xmlns:th="http://www.thymeleaf.org" 
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
    layout:decorator="layouts/basic"> 
<head> 
<title>Getting Started: Serving Web Content</title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</head> 
<body layout:fragment="content"> 
    <h1>Shopping List items</h1> 

     <table> 
      <thead> 
       <tr> 
        <th>&nbsp;</th> 
        <th>Content</th> 
        <th>Options</th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr th:each="listitem : ${list_items}"> 
        <td th:text="${listitem.contents}"></td> 
        <td><form method="POST" ><input type="hidden" name="listId" th:value="${}"/><button type="submit">Delete</button></form></td> 
       </tr> 
      </tbody> 
     </table> 

    <a href="/">Back</a> 
</body> 
</html> 

這裏也是我的Data.sql

insert into shoppinglist.lists (user_id, name, color, created_utc, modified_utc) values (1, 'Test List', '#000000', '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 
insert into shoppinglist.lists (user_id, name, color, created_utc, modified_utc) values (2, 'Test List 2', '#000000', '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 
insert into shoppinglist.lists (user_id, name, color, created_utc, modified_utc) values (3, 'Test List 3', '#000000', '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 
insert into shoppinglist.lists (user_id, name, color, created_utc, modified_utc) values (4, 'Test List 4', '#000000', '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 

insert into shoppinglist.list_items (list_id, contents, priority, is_checked, created_utc, modified_utc) values (1, 'Hello there', 1, false, '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 
insert into shoppinglist.list_items (list_id, contents, priority, is_checked, created_utc, modified_utc) values (2, 'Hello there', 1, false, '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 
insert into shoppinglist.list_items (list_id, contents, priority, is_checked, created_utc, modified_utc) values (3, 'Hello there', 1, false, '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 
insert into shoppinglist.list_items (list_id, contents, priority, is_checked, created_utc, modified_utc) values (4, 'Hello there', 1, false, '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 

insert into shoppinglist.notes (item_id, body, created_utc, modified_utc) values ('1', 'this is where my paragraph would go', '2016-11-30 03:42:56', '2016-11-30 03:42:56'); 

,最後我的控制器

@Controller 
public class ListController { 

    @Autowired 
    private ListRepository listRepo; 
    @Autowired 
    private ListItemRepository listItemRepo; 

    @GetMapping("") 
    public String index(Model model, HttpServletRequest request) { 
     return "index"; 
    } 

    @GetMapping("/ListsofLists") 
    public String List(Model model) { 
     model.addAttribute("lists", listRepo.findAll()); 
     return "list_of_lists"; 
    } 

    @GetMapping("/ListsofLists/{id}") 
    public String listitems(Model model, @PathVariable(name = "id") int id) { 
     model.addAttribute("id", id); 
     // never forget to import the proper beans! 
     ListItem u = listItemRepo.findOne(id); 

     model.addAttribute("list_items", u); 
     // yes I am going with listing the lists, I thought it would be funny. 
     return "list_list"; 
    } 

    // GetMapping and PostMapping for editing items in lists. 
    @GetMapping("/ListsofLists/{id}/edit") 
    public String listEdit(Model model, @PathVariable(name = "id") int id) { 
     model.addAttribute("id", id); 
     List u = listRepo.findOne(id); 
     model.addAttribute("lists", u); 
     return "list_edit"; 
    } 

    @PostMapping("/ListsofLists/{userId}/edit") 
    public String listEditSave(@ModelAttribute @Valid List list, BindingResult result, Model model) { 
     listRepo.save(list); 
     return "redirect:/ListsofLists/" + list.getId(); 
    } 
} 

回答

0

我的搭檔已經找到了錯誤。今天早些時候我們在一系列重構之後,我們有一個Variable中的一個關閉了。

相關問題