我需要打印到表的人谁超过55岁,但它打印每个人从数据库。我不知道怎么了。
刀
@Override
@SuppressWarnings("unchecked")
public List<Book> old1() {
Session session = this.sessionFactory.getCurrentSession();
// List<Book> bookListt = session.createQuery("SELECT BOOK_TITLE, BOOK_AUTHOR, birthday FROM bookmanager.books WHERE birthday <= DATE_SUB(CURDATE(), INTERVAL 15 year)").list();
List<Book> bookList1 = session.createSQLQuery("SELECT ID, BOOK_TITLE, BOOK_AUTHOR, born FROM bookmanager.book WHERE born <= DATE_SUB(CURDATE(), INTERVAL 10 year))").list();
return bookList1;
}
控制器:
@RequestMapping(value = "books", method = RequestMethod.GET)
public String old(Model model){
model.addAttribute("book", new Book());
model.addAttribute("old", this.bookService.listBooks());
return "books";
}
我试着把那个人印出来,但这是错的。从db打印所有peson
我该怎么修?
<c:if test="${!empty old1}">
<table class="tg">
<tr>
<th width="80">ID</th>
<th width="120">Title</th>
<th width="120">Author</th>
<th width="120">Price</th>
<th width="120">born</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${old1}" var="book1">
<tr>
<td>${book1.id}</td>
<td><a href="/bookdata/${book1.id}" target="_blank">${book.bookTitle}</a></td>
<td>${book1.bookAuthor}</td>
<td>${book1.price}</td>
<td>${book1.born}</td>
<td><a href="<c:url value='/edit/${book1.id}'/>">Edit</a></td>
<td><a href="<c:url value='/remove/${book1.id}'/>">Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
2条答案
按热度按时间yfwxisqw1#
我不确定您的hibernate/java代码是否完全正确,但是您的mysql查询看起来不正确。如果你想把所有
born
字段从当前日期起超过55年,则使用此字段:6jygbczu2#
将查询更改为条件。本机sql查询未工作。