gpt4 book ai didi

java - 尝试将 sql 数据库中的信息显示到 html 表中

转载 作者:行者123 更新时间:2023-11-29 19:46:46 26 4
gpt4 key购买 nike

我在将 SQL 数据库中的一些信息显示到 Spring 框架 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

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

最佳答案

我的伙伴发现了错误。今天早些时候经过一系列重构后,我们的一个 bean 中的一个变量被关闭了。

关于java - 尝试将 sql 数据库中的信息显示到 html 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40918446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com