Invalid bound statement (not found): com.kuang.dao.bookMapper.queryAllbook
生活随笔
收集整理的這篇文章主要介紹了
Invalid bound statement (not found): com.kuang.dao.bookMapper.queryAllbook
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
學狂神的ssm,照抄出現錯誤,修改寫法。
之前錯誤的寫法
正確的寫法
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><typeAliases><package name="com.kuang.pojo"/></typeAliases><mappers><mapper resource="mappers/BookMapper.xml"></mapper></mappers> </configuration>
具體項目
database.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/my?useSSL=false&characterEncoding=utf8 jdbc.username=root jdbc.password=rootBooks
package com.kuang.pojo;import com.oracle.webservices.internal.api.databinding.DatabindingMode; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor;@NoArgsConstructor @AllArgsConstructor @Data public class Books {private int bookID;private String bookName;private int bookCounts;private String detail; }bookMapper
package com.kuang.dao;import com.kuang.pojo.Books;import java.util.List;public interface bookMapper {int addBook(Books books);int deleteBook(int id);int updateBook(Books books);Books queryBookById(int id);List<Books> queryAllbook(); }BookMapper.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.kuang.dao.bookMapper"><insert id="addBook" parameterType="Books">insert into books(bookName,bookCounts,detail) values (#{bookName},#{bookCounts},#{detail});</insert><delete id="deleteBook" parameterType="int">delete from books where bookID=#{bookID};</delete><update id="updateBook" parameterType="Books">update books set bookName=#{bookName},bookCounts=#{bookCounts},detail=#{detail} where bookID=#{bookID}</update><select id="queryBookById" resultType="Books">select * from books where bookID=#{bookID}</select><select id="queryAllbook" resultType="Books">select * from books;</select> </mapper>mybatis-config.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration><typeAliases><package name="com.kuang.pojo"/></typeAliases><mappers><mapper resource="mappers/BookMapper.xml"></mapper></mappers> </configuration>bookService
package com.kuang.service;import com.kuang.pojo.Books;import java.util.List;public interface bookService {int addBook(Books books);int deleteBook(int id);int updateBook(Books books);Books queryBookById(int id);List<Books> queryAllbook(); }bookServiceImpl
package com.kuang.service;import com.kuang.dao.bookMapper; import com.kuang.pojo.Books;import java.util.List;public class bookServiceImpl implements bookService{private bookMapper bookMapper;public void setBookMapper(com.kuang.dao.bookMapper bookMapper) {this.bookMapper = bookMapper;}@Overridepublic int addBook(Books books) {return bookMapper.addBook(books);}@Overridepublic int deleteBook(int id) {return bookMapper.deleteBook(id);}@Overridepublic int updateBook(Books books) {return bookMapper.updateBook(books);}@Overridepublic Books queryBookById(int id) {return bookMapper.queryBookById(id);}@Overridepublic List<Books> queryAllbook() {return bookMapper.queryAllbook();} }spring-dao.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><context:property-placeholder location="classpath:database.properties"></context:property-placeholder><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/><property name="password" value="${jdbc.password}"/><property name="user" value="${jdbc.username}"/><property name="maxPoolSize" value="30"/><property name="minPoolSize" value="10"/><property name="autoCommitOnClose" value="false"/><property name="checkoutTimeout" value="10000"/><property name="acquireRetryAttempts" value="2"/></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="configLocation" value="classpath:mybatis-config.xml"/></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.kuang.dao"/><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/></bean> </beans>spring-service.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><context:component-scan base-package="com.kuang.service"/><bean id="bookServiceImpl" class="com.kuang.service.bookServiceImpl"><property name="bookMapper" ref="bookMapper"/></bean><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean></beans>spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scan base-package="com.kuang.controller"/><mvc:annotation-driven/><mvc:default-servlet-handler/><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean> </beans> package com.kuang.controller;import com.kuang.pojo.Books; import com.kuang.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@Qualifier("bookServiceImpl")private com.kuang.service.bookService bookService;@RequestMapping("/allBook")public String list(Model model){List<Books> list=bookService.queryAllbook();model.addAttribute("list",list);return "allBook";}@RequestMapping("/toAddBook")public String toAddPaper(){return "addBook";}@RequestMapping("/addBook")public String addBook(Books books){bookService.addBook(books);return "redirect:/book/allBook";}public String toUpdatePaper(){return "updateBook";} }index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html><head><title>首頁</title><style>a{text-decoration: none;color:black;font-size:18px}h3{width:180px;height:38px;margin:100px auto;text-align:center;line-height: 38px;background: deepskyblue;border-radius: 6px;}</style></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" %> <%--Created by IntelliJ IDEA.User: cllDate: 2021/12/25Time: 15:16To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html><head><title>書籍展示</title><link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head><body><div class="container"><div class="row clearfix"><div class="col-md-12 colum"><div class="page-header"><h1><small>書籍列表-----顯示所有書籍</small></h1></div></div><div class="row"><div class="col-md-4 colum"><a href="${pageContext.request.contextPath}/book/toAddBook">新增書籍</a></div></div></div><div class="row clearfix"><div class="col-md-12 colum"><table class="table table-hover table-striped"><thead><tr><th>書籍編號</th><th>書籍名稱</th><th>書籍數量</th><th>書籍詳情</th></tr></thead><tbody><c:forEach var="book" items="${list}"><tr><td>${book.bookID}</td><td>${book.bookName}</td><td>${book.bookCounts}</td><td>${book.detail}</td><td><a href="">修改</a> | <a href="">刪除</a></td></tr></c:forEach></tbody></table></div></div></div></body> </html>總結
以上是生活随笔為你收集整理的Invalid bound statement (not found): com.kuang.dao.bookMapper.queryAllbook的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面向对象思想学习
- 下一篇: php html转换成word,php如