ssmbiuld整合-查询书籍功能
关于@Autowired @Qualifier的用法:
https://www.cnblogs.com/hjw-zq/p/10626347.html
https://www.cnblogs.com/kakafa/p/15771061.html
https://www.cnblogs.com/kakafa/p/15770792.html

BookController:
package com.kakafa.controller;
import com.kakafa.pojo.Books;
import com.kakafa.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
@RequestMapping("/book")
public class BookController {
@Autowired //在属性中使用 @Autowired 注解来除去 setter 方法
@Qualifier("bookServiceImpl")
private BookService bookService;
//查询所有书籍
@RequestMapping("/allbook")
public String list(Model model){
List<Books> books=bookService.queryAllBook();
model.addAttribute("list",books);
return "allBook";
}
}
index.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>首页</title>
</head>
<body>
<h3>
<a href="${pageContext.request.contextPath}/book/allbook">进入书籍展示页面</a>
</h3>
</body>
</html>
allBook.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>书籍展示</title>
</head>
<body>
<h1>书籍展示</h1>
<table>
<tr>
<th>书籍编号</th>
<th>书籍数量</th>
<th>书籍名称</th>
<th>书籍详情</th>
</tr>
<c:forEach var="book" items="${list}">
<tr>
<td>${book.bookID}</td>
<td>${book.bookCounts}</td>
<td>${book.bookName}</td>
<td>${book.detail}</td>
</tr>
</c:forEach>
</table>
</body>
</html>


报错:
Could not open ServletContext resource [/database.properties]

spring-mapper.xml修改如下:
<!--1.关联数据库文件-->
<context:property-placeholder location="classpath:database.properties"/>
浙公网安备 33010602011771号