图书管理系统模块,通过模糊查询实现查找图书的功能
在数据库中建库建表
建立相关外键,画出er图。
使用代码实现过程(重点)
配置tomcat,导入相关jar包资源,配置resources环境,配置测试用的log4jproperties
### 设置###
log4j.rootLogger = debug,stdout,D,E
输出信息到控制抬
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{
yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
输出DEBUG 级别以上的日志到=E://logs/error.log
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = E://logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{
yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
输出ERROR 级别以上的日志到=E://logs/error.log
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{
yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
配置database和mybatis-cfg.xml
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.56.101:3306/library
user=kb07
pwd=ok
<?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>
<properties resource="database.properties"/>
<typeAliases>
<typeAlias type="cn.kgc.kb07.entity.User" alias="user"/>
<typeAlias type="cn.kgc.kb07.entity.Books" alias="books"/>
</typeAliases>
<environments default="dev">
<environment id="dev">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${user}"/>
<property name="password" value="${pwd}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper class="cn.kgc.kb07.dao.UserDao"/>
<mapper class="cn.kgc.kb07.dao.BooksDao"/>
</mappers>
</configuration>
在src中分层处理,创建和数据库对应的实体类:
package cn.kgc.kb07.entity;
/**
* @Author yanglitian
* @Date 2020/6/15
* @Description
*/
public class Books {
private int book_id;
private String book_name;
private double price;
private int store;
private String des;
private int book_type;
private String type_name;
public String getType_name() {
return type_name;
}
public void setType_name(String type_name) {
this.type_name = type_name;
}
public int getBook_id() {
return book_id;
}
public void setBook_id(int book_id) {
this.book_id = book_id;
}
public String getBoo