先声明:
本人前端奇差无比,功能能实现,页面稀巴烂
项目要求:
利用servlet和jsp写一个简单的类似淘宝的东西
代码
项目结构
pom.xml文件
- 根 pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.lyl</groupId> <artifactId>taobao</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>taobao-api</module> <module>taobao-dao</module> <module>taobao-service</module> <module>taobao-controller</module> </modules> <repositories> <!--阿里云仓库--> <repository> <id>aliyun</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> <properties> <!-- jar包版本设置 --> <slf4j.version>1.7.21</slf4j.version> <log4j.version>2.8.2</log4j.version> </properties> <dependencies> <!-- 导入slf4j的接口包以及对应日志框架的驱动包 --> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <!--用于slf4j与log4j2保持桥接 --> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <scope>runtime</scope> <version>${log4j.version}</version> </dependency> <!-- 导入日志框架核心包与接口包 --> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <scope>runtime</scope> <version>${log4j.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>${log4j.version}</version> </dependency> <!--用于解决web环境下关闭服务器时可能出现的log4j线程无法及时关闭的warn,web工程需要包含log4j-web,非web工程不需要 --> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <scope>runtime</scope> <version>${log4j.version}</version> </dependency> <!--使用log4j2的AsyncLogger时需要包含disruptor --> <!-- https://mvnrepository.com/artifact/com.lmax/disruptor --> <dependency> <groupId>com.lmax</groupId> <artifactId>disruptor</artifactId> <scope>runtime</scope> <version>3.4.2</version> </dependency> </dependencies> </project>
- api pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>taobao</artifactId> <groupId>org.lyl</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taobao-api</artifactId> <dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.20</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.23</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> <scope>provided</scope> </dependency> </dependencies> </project>
- dao pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>taobao</artifactId> <groupId>org.lyl</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <artifactId>taobao-dao</artifactId> <dependencies> <dependency> <groupId>org.lyl</groupId> <artifactId>taobao-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
- service pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>taobao</artifactId> <groupId>org.lyl</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>taobao-service</artifactId> <dependencies> <dependency> <groupId>org.lyl</groupId> <artifactId>taobao-dao</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.lyl</groupId> <artifactId>taobao-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
controller pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.lyl</groupId> <artifactId>taobao-controller</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>taobao-controller Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.lyl</groupId> <artifactId>taobao-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-catalina</artifactId> <version>9.0.11</version> <scope>provided</scope> </dependency> <!-- 文件上传用的包commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.7</version> </dependency> <!--文件上传用的包commons-fileupload --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>org.jetbrains</groupId> <artifactId>annotations-java5</artifactId> <version>RELEASE</version> <scope>compile</scope> </dependency> </dependencies> <build> <finalName>taobao-controller</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <path>/</path> <port>81</port> <uriEncoding>UTF-8</uriEncoding> <server>tomcat7</server> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
api层
- config
1.DbPoolConnection
package org.lyl.taobao.api.config; import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSource; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; /** * @Author: Re * @Date: 2021/3/26 14:10 */ public class DbPoolConnection { private static DbPoolConnection databasePool = null; private static DataSource dataSource = null; static { Properties properties = new Properties(); try { InputStream inputStream=DbPoolConnection.class.getClassLoader().getResourceAsStream("druid.properties"); properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); } try { dataSource = DruidDataSourceFactory.createDataSource(properties); } catch (Exception e) { e.printStackTrace(); } } private DbPoolConnection() { } public static synchronized DbPoolConnection getInstance() { if (null == databasePool) { databasePool = new DbPoolConnection(); } return databasePool; } public Connection getConnection() throws SQLException { return dataSource.getConnection(); } }
- entity
1.Commodity
package org.lyl.taobao.api.entity; import lombok.Data; import java.io.Serializable; /** * @Author: Re * @Date: 2021/3/29 12:51 */ @Data public class Commodity { private int commodityId; private String commodityName; private String commodityKind; private float commodityPrice; private Integer commodityUserId; public Commodity() { } public Commodity(String commodityName, String commodityKind, float commodityPrice) { this.commodityName = commodityName; this.commodityKind = commodityKind; this.commodityPrice = commodityPrice; } public Commodity(String commodityName, String commodityKind, float commodityPrice, Integer commodityUserId) { this.commodityName = commodityName; this.commodityKind = commodityKind; this.commodityPrice = commodityPrice; this.commodityUserId = commodityUserId; } public Commodity(int commodityId, String commodityName, String commodityKind, float commodityPrice) { this.commodityId = commodityId; this.commodityName = commodityName; this.commodityKind = commodityKind; this.commodityPrice = commodityPrice; } public Commodity(int commodityId, String commodityName, String commodityKind, float commodityPrice, Integer commodityUserId) { this.commodityId = commodityId; this.commodityName = commodityName; this.commodityKind = commodityKind; this.commodityPrice = commodityPrice; this.commodityUserId = commodityUserId; } @Override public String toString() { return "商品名为:" + commodityName + ",商品分类:" + commodityKind + ",商品价格:" + commodityPrice ; } }
2.Order
package org.lyl.taobao.api.entity; import lombok.Data; /** * @Author: Re * @Date: 2021/3/29 12:59 */ @Data public class Order { private Integer orderId; private Integer orderUserId; private Integer orderCommodityId; private Integer orderMerchantId; public Order() { } public Order(Integer orderUserId, Integer orderCommodityId, Integer orderMerchantId) { this.orderUserId = orderUserId; this.orderCommodityId = orderCommodityId; this.orderMerchantId = orderMerchantId; } public Order(Integer orderId, Integer orderUserId, Integer orderCommodityId, Integer orderMerchantId) { this.orderId = orderId; this.orderUserId = orderUserId; this.orderCommodityId = orderCommodityId; this.orderMerchantId = orderMerchantId; } @Override public String toString() { return "订单:\n" + "用户id" + orderUserId + ", 商品id" + orderCommodityId ; } }
3.ShopCart
package org.lyl.taobao.api.entity; import lombok.Data; /** * @Author: Re * @Date: 2021/3/29 13:03 */ @Data public class ShopCart { private Integer shopCartId; private Integer shopCartUserId; private Integer shopCartCommodityId; private Integer shopCartMerchantId; public ShopCart() { } public ShopCart(Integer shopCartUserId, Integer shopCartCommodityId, Integer shopCartMerchantId) { this.shopCartUserId = shopCartUserId; this.shopCartCommodityId = shopCartCommodityId; this.shopCartMerchantId = shopCartMerchantId; } @Override public String toString() { return "用户id:" + shopCartUserId + ",商品id:" + shopCartCommodityId + ",店家id:" + shopCartMerchantId; } }
4.User
package org.lyl.taobao.api.entity; import lombok.Data; /** * @Author: Re * @Date: 2021/3/26 14:05 */ @Data public class User { private int userId; private String img; private String userName; private String userPassword; private float balance; private String userGrade; public User() { } public User(String userName, String userPassword, float balance, String userGrade) { this.userName = userName; this.userPassword = userPassword; this.balance = balance; this.userGrade = userGrade; } public User(int userId, String img, String userName, String userPassword, float balance, String userGrade) { this.userId = userId; this.img = img; this.userName = userName; this.userPassword = userPassword; this.balance = balance; this.userGrade = userGrade; } public User(int userId, String userName, String userPassword, float balance, String userGrade) { this.userId = userId; this.userName = userName; this.userPassword = userPassword; this.balance = balance; this.userGrade = userGrade; } public User(String userName, String userPassword, String userGrade) { this.userName = userName; this.userPassword = userPassword; this.userGrade = userGrade; } @Override public String toString() { String grade = this.userGrade == "1" ? "用户" : "管理员"; return "User{" + "userName='" + userName + '\'' + ", userPassword='" + userPassword + '\'' + ", userGrade='" + + '\'' + '}'; } }
- utils
1.DruidConnectionUtils
package org.lyl.taobao.api.utils; import org.lyl.taobao.api.config.DbPoolConnection; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * @Author: Re * @Date: 2021/3/26 14:12 */ public class DruidConnectionUtils { public Connection getConnection() { DbPoolConnection dbPoolConnection = DbPoolConnection.getInstance(); Connection connection=null; try{ connection = dbPoolConnection.getConnection(); }catch (Exception e){ e.printStackTrace(); } return connection; } /** * 关闭Connection PreparedStatement * @param connection * @param preparedStatement */ public void closeConnection(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){ if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } } if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
下面的四个service接口
1.ICommodityService
package org.lyl.taobao.api; import org.lyl.taobao.api.entity.Commodity; import java.util.List; /** * @Author: Re * @Date: 2021/4/2 17:21 */ public interface ICommodityService { /** * 增加商品接口 * @param commodity * @return */ boolean addCommodity(Commodity commodity); /** * 查看所有商品 * @return */ List<Commodity> checkAllCommodity(); /** * 根据商品id查询商品 * @param c_Id * @return */ Commodity checkCommodityByC_Id(Integer c_Id); /** * 根据商家名查看商品 * @param UserId * @return */ List<Commodity> checkCommodityById(Integer UserId); /** * 删除商品 * @param c_Id * @return */ boolean deleteCommodity(int c_Id); /** * 更改商品信息 * @param c_Id * @param c_Name * @param c_Price * @return */ boolean updateCommodity(int c_Id,String c_Name,float c_Price); /** * 查看商品的价格 * @param c_Id * @return */ float getCommodityPriceByC_Id(Integer c_Id); }
2.IOrderService
package org.lyl.taobao.api; import org.lyl.taobao.api.entity.Order; import java.util.List; /** * @Author: Re * @Date: 2021/4/9 20:47 */ public interface IOrderService { /** * 添加订单 * @param order * @return */ boolean addOrder(Order order); /** * 查看用户所有订单 * @param userId * @return */ List<Order> checkOrder(Integer userId); /** * 取消订单 * @param orderId * @return * */ boolean deleteOrder(Integer orderId); }
3.IShopCartService
package org.lyl.taobao.api; import org.lyl.taobao.api.entity.ShopCart; import java.util.List; /** * @Author: Re * @Date: 2021/4/7 17:31 */ public interface IShopCartService { /** * 将商品到添加购物车 * @param shopCart * @return */ boolean addShopCart(ShopCart shopCart); /** * 根据用户id查询商品id * @param userId * @return */ List<Integer> checkC_IdByUserId(Integer userId); /** * 删除购物车中的商品 * @param userId * @param c_Id * @return */ boolean deleteShopCart(Integer userId,Integer c_Id); }
4.IUserService
package org.lyl.taobao.api; import org.lyl.taobao.api.entity.User; import java.util.List; /** * @Author: Re * @Date: 2021/3/26 14:06 */ public interface IUserService { /** * 增加用户的接口 * @param user * @return */ boolean insertUser(User user); /** * 用户登录接口 * @param user * @return */ User registerUser(User user); /** * 管理员所有查看用户接口 * @return */ List<User> checkAllUser(); /** * 管理员查看用户接口(个人主页) * @param userName * @return */ List<User> checkUser(String userName); /** * 管理员删除用户接口 * @param userName * @return */ boolean deleteUser(String userName); /** * 用户更改密码接口 * @param user * @return */ boolean updateUser(User user); /** * 根据商品id查找用户id * @param c_Id * @return */ Integer userIdByC_Id(Integer c_Id); /** * 查看用户余额 * @param userId * @return */ float getUserBalanceByUserId(Integer userId); /** * 减少用户余额 * @param price * @param userId * @return */ boolean reduceBalanceByUserId(float price,Integer userId); /** * 增加用户余额 * @param price * @param userId * @return */ boolean addBalanceByUserId(float price,Integer userId); /** * 添加图片 * @param imgPath * @param user * @return */ boolean addPhoto(String imgPath,User user); }
resources里的配置文件
- applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- 阿里 druid 数据库连接池 --> <bean id = "dataSource" class = "com.alibaba.druid.pool.DruidDataSource" destroy-method = "close" > <!-- 数据库基本信息配置 --> <property name = "url" value = "${url}" /> <property name = "username" value = "${username}" /> <property name = "password" value = "${password}" /> <property name = "driverClassName" value = "${driverClassName}" /> <property name = "filters" value = "${filters}" /> <!-- 最大并发连接数 --> <property name = "maxActive" value = "${maxActive}" /> <!-- 初始化连接数量 --> <property name = "initialSize" value = "${initialSize}" /> <!-- 配置获取连接等待超时的时间 --> <property name = "maxWait" value = "${maxWait}" /> <!-- 最小空闲连接数 --> <property name = "minIdle" value = "${minIdle}" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name = "timeBetweenEvictionRunsMillis" value ="${timeBetweenEvictionRunsMillis}" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name = "minEvictableIdleTimeMillis" value ="${minEvictableIdleTimeMillis}" /> <property name = "validationQuery" value = "${validationQuery}" /> <property name = "testWhileIdle" value = "${testWhileIdle}" /> <property name = "testOnBorrow" value = "${testOnBorrow}" /> <property name = "testOnReturn" value = "${testOnReturn}" /> <property name = "maxOpenPreparedStatements" value ="${maxOpenPreparedStatements}" /> <!-- 打开 removeAbandoned 功能 --> <property name = "removeAbandoned" value = "${removeAbandoned}" /> <!-- 1800 秒,也就是 30 分钟 --> <property name = "removeAbandonedTimeout" value ="${removeAbandonedTimeout}" /> <!-- 关闭 abanded 连接时输出错误日志 --> <property name = "logAbandoned" value = "${logAbandoned}" /> </ bean >
- druid.properties
driverClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/taobao?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true username=root password=root filters=stat initialSize=2 maxActive=300 maxWait=60000 timeBetweenEvictionRunsMillis=60000 minEvictableIdleTimeMillis=300000 validationQuery=SELECT 1 testWhileIdle=true testOnBorrow=false testOnReturn=false poolPreparedStatements=false maxPoolPreparedStatementPerConnectionSize=200
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?> <!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL--> <!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出--> <!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数--> <configuration status="INFO" monitorInterval="30"> <!--先定义所有的appender--> <appenders> <!--这个输出控制台的配置--> <console name="Console" target="SYSTEM_OUT"> <!--输出日志的格式--> <PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/> </console> <!--文件会打印出所有信息,这个log每次运行程序会自动清空,由append属性决定,这个也挺有用的,适合临时测试用--> <File name="log" fileName="${sys:user.home}/logs/test.log" append="false"> <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/> </File> <!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档--> <RollingFile name="RollingFileInfo" fileName="${sys:user.home}/logs/info.log" filePattern="${sys:user.home}/logs/$${date:yyyy-MM}/info-%d{yyyy-MM-dd}-%i.log"> <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)--> <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicy size="100 MB"/> </Policies> </RollingFile> <RollingFile name="RollingFileWarn" fileName="${sys:user.home}/logs/warn.log" filePattern="${sys:user.home}/logs/$${date:yyyy-MM}/warn-%d{yyyy-MM-dd}-%i.log"> <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicy size="100 MB"/> </Policies> <!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件,这里设置了20 --> <DefaultRolloverStrategy max="20"/> </RollingFile> <RollingFile name="RollingFileError" fileName="${sys:user.home}/logs/error.log" filePattern="${sys:user.home}/logs/$${date:yyyy-MM}/error-%d{yyyy-MM-dd}-%i.log"> <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicy size="100 MB"/> </Policies> </RollingFile> </appenders> <!--然后定义logger,只有定义了logger并引入的appender,appender才会生效--> <loggers> <!-- <!–过滤掉spring和mybatis的一些无用的DEBUG信息–>--> <!-- <logger name="org.springframework" level="INFO"></logger>--> <!-- <logger name="org.mybatis" level="INFO"></logger>--> <root level="INFO"> <appender-ref ref="Console"/> <appender-ref ref="RollingFileInfo"/> <appender-ref ref="RollingFileWarn"/> <appender-ref ref="RollingFileError"/> </root> </loggers> </configuration>
dao层
- 接口
1.ICommodityDao
package org.lyl.taobao.dao; import org.lyl.taobao.api.entity.Commodity; import java.sql.Connection; import java.util.List; /** * @Author: Re * @Date: 2021/4/2 16:17 */ public interface ICommodityDao { /** * 增加商品接口 * @param connection * @param commodity * @return */ boolean insertCommodity(Connection connection, Commodity commodity); /** * 查看所有商品 * @param connection * @return */ List<Commodity> checkAllCommodity(Connection connection); /** * 根据商品id查询商品 * @param connection * @param c_Id * @return */ Commodity checkCommodityByC_Id(Connection connection,Integer c_Id); /** * 根据商家名查看商品 * @param connection * @param UserId * @return */ List<Commodity> checkCommodityById(Connection connection,Integer UserId); /** * 根据商品id * @param connection * @param c_id * @return */ boolean deleteCommodity(Connection connection,int c_id); /** * 更改商品信息 * @param connection * @param c_Id * @param c_Name * @param c_Price * @return */ boolean updateCommodity(Connection connection,int c_Id,String c_Name,float c_Price); /** * 查看商品价格 * @param connection * @param c_Id * @return */ float getCommodityPriceByC_Id(Connection connection,Integer c_Id); }
2.IOrderDao
package org.lyl.taobao.dao; import org.lyl.taobao.api.entity.Order; import java.sql.Connection; import java.util.List; /** * @Author: Re * @Date: 2021/4/9 20:46 */ public interface IOrderDao { /** * 添加订单 * @param connection * @param order * @return */ boolean addOrder(Connection connection, Order order); /** * 查看用户的订单 * @param connection * @param userId * @return */ List<Order> checkOrder(Connection connection,Integer userId); /** * 取消订单 * @param connection * @param orderId * @return */ boolean deleteOrder(Connection connection,Integer orderId); }
3.IShopCartDao
package org.lyl.taobao.dao; import org.lyl.taobao.api.entity.Commodity; import org.lyl.taobao.api.entity.ShopCart; import java.sql.Connection; import java.util.List; /** * @Author: Re * @Date: 2021/4/7 17:32 */ public interface IShopCartDao { /** * 添加购物车信息 * @param connection * @param shopCart * @return */ boolean addShopCart(Connection connection, ShopCart shopCart); /** * 根据用户id查询 * @param connection * @param userId * @return */ List<Integer> checkC_IdByUserId(Connection connection, Integer userId); /** * 删除购物车中的商品 * @param connection * @param userId * @param c_Id * @return */ boolean deleteShopCart(Connection connection,Integer userId,Integer c_Id); }
4.IUserDao
package org.lyl.taobao.dao; import org.lyl.taobao.api.entity.User; import java.sql.Connection; import java.util.List; /** * @Author: Re * @Date: 2021/3/26 14:14 */ public interface IUserDao { /** * 用户注册接口 * @param connection * @param user * @return */ boolean insertUser(Connection connection, User user); /** * 用户登录接口 * @param connection * @param user * @return */ User registerUser(Connection connection,User user); /** * 管理员查看所有用户接口 * @param connection * @return */ List<User> checkAllUser(Connection connection); /** * 管理员查看单个用户接口(个人主页) * @param connection * @param userName * @return */ List<User> checkUser(Connection connection,String userName); /** * 管理员删除用户接口 * @param connection * @param userName * @return */ boolean deleteUser(Connection connection,String userName); /** * 用户更改密码接口 * @param connection * @param user * @return */ boolean updateUser(Connection connection,User user); /** * 根据商品id获取用户id * @param connection * @param c_Id * @return */ Integer getUserIdByC_Id(Connection connection,Integer c_Id); /** * 查看用户的余额 * @param connection * @param userId * @return */ float getUserBalanceByUserId(Connection connection,Integer userId); /** * 减少用户余额 * @param connection * @param price * @param userId * @return */ boolean reduceBalanceByUserId(Connection connection,float price,Integer userId); /** * 增加用户余额 * @param connection * @param price * @param userId * @return */ boolean addBalanceByUserId(Connection connection,float price,Integer userId); /** * 传入图片路径 * @param connection * @param imgPath * @return */ boolean addPhoto(Connection connection,String imgPath,User user); }