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> </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();
}
}