基于SSM实现超市会员管理系统

书史足自悦,安用勤与劬。这篇文章主要讲述基于SSM实现超市会员管理系统相关的知识,希望能为你提供帮助。
基于SSM实现超市会员管理系统

大家好,本周为大家带来一个基于SSM的超市会员管理系统,干货满满,内容详细哦~
项目简介超市会员管理系统
  1. *查询会员信息,能够根据多条件进行查询,并将查询的结果进行分页展示,展示效果按照前5后4的样式进行展示*
细节:
(1) 点击多条件搜索后,在表单中回显搜索的内容
(2) 点击分页码时,要把多条件搜索框中的条件传递到控制器
(3) 点击分页码时,如果当前是第一页,上一页要禁用,如果当前是最后一页,下一页要禁用
(4) 分页导航显示当前页的前5页和当前页的后4页
  1. *修改会员信息,点击修改按钮后先展示编辑表单,并在编辑表单中回显要修改的内容,点击提交后,进行更新操作*
细节
(1) 在编辑表单中,如果该会员有头像要把头像回显
(2) 如果上传了新的头像,则使用新的替换旧的头像,如果没有上传新的头像,则使用旧的头像
  1. *删除会员信息,点击删除按钮后删除对应的会员信息并将上传的会员头像删除*
  2. *新增会员信息,点击新增按钮后,新增页需要有会员头像上传,上传完毕头像后将头像存储在硬盘,数据库存储对应的图片名称*
效果图
基于SSM实现超市会员管理系统

文章图片

数据表准备t_vip_info
CREATE TABLE `t_vip_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`vip_name` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 会员名称,
`vip_level` int(11) DEFAULT NULL COMMENT 会员所属级别,关联t_vip_level表,
`head_pic` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 会员头像,
`vip_phone` varchar(11) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 会员电话,
`vip_email` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 会员邮箱,
`vip_status` int(11) DEFAULT 1 COMMENT 会员状态,0:已注销,1:未注销,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 办理日期,
PRIMARY KEY (`id`)
)

t_vip_level
CREATE TABLE `t_vip_level` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`level_name` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 会员级别:1:普通,2:白金会员,3:钻石会员,4:金牌会员,
PRIMARY KEY (`id`)
)

项目结构【基于SSM实现超市会员管理系统】
基于SSM实现超市会员管理系统

文章图片

后端结构
基于SSM实现超市会员管理系统

文章图片

前端结构
基于SSM实现超市会员管理系统

文章图片

配置文件结构
基于SSM实现超市会员管理系统

文章图片

POM文件
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.0modelVersion>

< groupId> org.examplegroupId>
< artifactId> SSM-SupermarketVIPManagerSystemartifactId>
< version> 1.0-SNAPSHOTversion>

< dependencies>

< dependency>
< groupId> org.springframeworkgroupId>
< artifactId> spring-aopartifactId>
< version> 5.2.4.RELEASEversion>
dependency>


< dependency>
< groupId> org.aspectjgroupId>
< artifactId> aspectjweaverartifactId>
< version> 1.9.4version>
dependency>


< dependency>
< groupId> org.springframeworkgroupId>
< artifactId> spring-contextartifactId>
< version> 5.2.4.RELEASEversion>
dependency>


< dependency>
< groupId> org.mybatisgroupId>
< artifactId> mybatisartifactId>
< version> 3.5.4version>
dependency>



< dependency>
< groupId> mysqlgroupId>
< artifactId> mysql-connector-javaartifactId>
< version> 5.1.47version>
dependency>


< dependency>
< groupId> com.mchangegroupId>
< artifactId> c3p0artifactId>
< version> 0.9.5.2version>
dependency>


< dependency>
< groupId> org.springframeworkgroupId>
< artifactId> spring-jdbcartifactId>
< version> 5.2.4.RELEASEversion>
dependency>


< dependency>
< groupId> org.mybatisgroupId>
< artifactId> mybatis-springartifactId>
< version> 2.0.4version>
dependency>


< dependency>
< groupId> org.springframeworkgroupId>
< artifactId> spring-webmvcartifactId>
< version> 5.1.9.RELEASEversion>
dependency>

< dependency>
< groupId> javax.servletgroupId>
< artifactId> jstlartifactId>
< version> 1.2version>
dependency>

< dependency>
< groupId> commons-fileuploadgroupId>
< artifactId> commons-fileuploadartifactId>
< version> 1.3.1version>
dependency>
< dependency>
< groupId> commons-iogroupId>
< artifactId> commons-ioartifactId>
< version> 2.4version>
dependency>


< dependency>
< groupId> javax.servletgroupId>
< artifactId> javax.servlet-apiartifactId>
< version> 3.1.0version>
< scope> providedscope>
dependency>

< dependency>
< groupId> org.projectlombokgroupId>
< artifactId> lombokartifactId>
< version> 1.18.20version>
dependency>
< dependency>
< groupId> commons-langgroupId>
< artifactId> commons-langartifactId>
< version> 2.6version>
dependency>
< dependency>
< groupId> junitgroupId>
< artifactId> junitartifactId>
< version> 4.13version>
< scope> testscope>
dependency>
dependencies>

< build>
< resources>
< resource>
< directory> src/main/javadirectory>
< includes>
< include> **/*.propertiesinclude>
< include> **/*.xmlinclude>
includes>
< filtering> truefiltering>
resource>
resources>
build>

project>

整合SSMmybatis-config.xml
MyBatis配置文件,配置数据库信息及实体类别名,绑定**Mapperxml文件,打印日志
version="1.0" encoding="UTF-8"?>
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
< configuration>
< settings>

< setting name="logImpl" value="https://www.songbingjia.com/android/STDOUT_LOGGING"> setting>
settings>

< typeAliases>
< package name="com.wanshi.bean"/>
typeAliases>

< mappers>
< mapper resource="com/wanshi/mapper/VipInfoMapper.xml"/>
mappers>
configuration>

applicationContext.xml
Spring配置文件,注册bean,整合mybatis,注册接口,配置事务,切面
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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">


< context:component-scan base-package="com.wanshi"> context:component-scan>


< aop:aspectj-autoproxy> aop:aspectj-autoproxy>


< context:property-placeholder location="classpath:db.properties"/>


< bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
< property name="driverClass" value="https://www.songbingjia.com/android/$driverClass"> property>
< property name="jdbcUrl" value="https://www.songbingjia.com/android/$jdbcUrl"> property>
< property name="user" value="https://www.songbingjia.com/android/$user"> property>
< property name="password" value="https://www.songbingjia.com/android/$password"> property>
bean>


< bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
< property name="dataSource" ref="dataSource"> property>



< property name="configLocation" value="https://www.songbingjia.com/android/classpath:mybatis-config.xml"> property>
bean>

< bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
< property name="sqlSessionFactoryBeanName" value="https://www.songbingjia.com/android/sqlSessionFactory"/>

< property name="basePackage" value="https://www.songbingjia.com/android/com.wanshi.mapper"> property>
bean>

< bean id="VipInfoServiceImpl" class="com.wanshi.service.impl.VipInfoServiceImpl">
< property name="vipInfoMapper" ref="vipInfoMapper"/>
bean>
< bean id="VipLevelServiceImpl" class="com.wanshi.service.impl.VipLevelServiceImpl">
< property name="vipLevelMapper" ref="vipLevelMapper"/>
bean>


< bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
< property name="dataSource" ref="dataSource"> property>
bean>


< tx:advice id="txAdvice" transaction-manager="transactionManager">

< tx:attributes>

< tx:method name="*" propagation="REQUIRED"/>

< tx:method name="get*" read-only="true"/>
tx:attributes>
tx:advice>


< aop:config>

< aop:pointcut expression="execution(* com.wanshi.service..*.*(..))" id="pc1"/>


< aop:advisor advice-ref="txAdvice" pointcut-ref="pc1"/>
aop:config>
beans>

spring-mvc.xml
SpringMVC配置文件,配置视图解析器,文件上传,开启注解开发
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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">


< context:component-scan base-package="com.wanshi.controller"> context:component-scan>


< mvc:annotation-driven/>


< bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

< property name="prefix" value="https://www.songbingjia.com/WEB-INF/pages/"> property>

< property name="suffix" value="https://www.songbingjia.com/android/.jsp"> property>
bean>


< bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

< property name="maxUploadSize" value="https://www.songbingjia.com/android/5000000"> property>
< property name="defaultEncoding" value="https://www.songbingjia.com/android/UTF-8" />
< property name="resolveLazily" value="https://www.songbingjia.com/android/true" />
bean>



beans>

配置web.xml
拦截用户的所有请求,初始化spring容器,过滤,编码
version="1.0" encoding="UTF-8"?>
< web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
< display-name> SSM-SupermarketVIPManagerSystemdisplay-name>


< context-param>
< param-name> contextConfigLocationparam-name>
< param-value> classpath:applicationContext.xmlparam-value>
context-param>
< listener>
< listener-class> org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>


< servlet>
< servlet-name> springmvcservlet-name>
< servlet-class> org.springframework.web.servlet.DispatcherServletservlet-class>


< init-param>
< param-name> contextConfigLocationparam-name>
< param-value> classpath:springmvc.xmlparam-value>
init-param>


< load-on-startup> 1load-on-startup>
servlet>


< servlet-mapping>
< servlet-name> springmvcservlet-name>

< url-pattern> /url-pattern>
servlet-mapping>


< servlet-mapping>
< servlet-name> defaultservlet-name>
< url-pattern> *.cssurl-pattern>
< url-pattern> *.jsurl-pattern>
< url-pattern> *.jpgurl-pattern>
< url-pattern> *.pngurl-pattern>
< url-pattern> *.jpegurl-pattern>
< url-pattern> /fonts/**url-pattern>
servlet-mapping>




< filter>
< filter-name> CharacterEncodingFilterfilter-name>
< filter-class> org.springframework.web.filter.CharacterEncodingFilterfilter-class>
< init-param>
< param-name> encodingparam-name>
< param-value> utf-8param-value>
init-param>
< init-param>
< param-name> forceRequestEncodingparam-name>
< param-value> trueparam-value>
init-param>
< init-param>
< param-name> forceResponseEncodingparam-name>
< param-value> trueparam-value>
init-param>
filter>
< filter-mapping>
< filter-name> CharacterEncodingFilterfilter-name>
< url-pattern> /*url-pattern>
filter-mapping>
web-app>

SSM整合完毕!
其他配置文件db.properties
连接数据库
driverClass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost:3306/ssmbuild?characterEncoding=utf-8
user=root
password=111111

log4j.properties
日志输出定义
log4j.rootLogger= DEBUG,Console

#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n

log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

核心代码RouteController
路由跳转,携带数据跳转到指定页面并加载
package com.wanshi.controller;

import com.wanshi.bean.VipInfo;
import com.wanshi.bean.VipLevel;
import com.wanshi.service.VipInfoService;
import com.wanshi.service.VipLevelService;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.logging.Level;

@Controller
@RequestMapping("/route")
public class RouteController

@Autowired
@Qualifier("VipLevelServiceImpl")
private VipLevelService vipLevelService;
@Autowired
private VipInfoService vipInfoService;

@RequestMapping("/add")
public String add(Model model)
List< VipLevel> list = vipLevelService.list();
model.addAttribute("levelList", list);
return "add";


@RequestMapping("/update/id")
private String update(@PathVariable("id") Integer id, Model model)
VipInfo vipInfo = vipInfoService.getByVip(id);
List< VipLevel> list = vipLevelService.list();
model.addAttribute("vip", vipInfo);
model.addAttribute("levelList", list);
return "edit";


VipInfoController
package com.wanshi.controller;

import com.wanshi.bean.Page;
import com.wanshi.bean.VipInfo;
import com.wanshi.service.VipInfoService;
import com.wanshi.utils.FileUtil;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/vip")
public class VipInfoController

@Autowired
@Qualifier("VipInfoServiceImpl")
private VipInfoService vipInfoService;

private static final Integer PAGE_SIZE = 2;

@RequestMapping("/vip_list")
public String list(String pageNumb, VipInfo vipInfo, Model model)
Integer currentNumb = 1;
if (pageNumb != null & & !pageNumb.equals(""))
currentNumb = Integer.valueOf(pageNumb);

Page< VipInfo> pager = vipInfoService.list(currentNumb, PAGE_SIZE, vipInfo.getVip_name(), vipInfo.getVip_phone(), vipInfo.getVip_email());
model.addAttribute("pager", pager);
model.addAttribute("vipName", vipInfo.getVip_name());
model.addAttribute("vipPhone", vipInfo.getVip_phone());
model.addAttribute("vipEmail", vipInfo.getVip_email());
return "list";


@RequestMapping("/addHandle")
public String addHandle(MultipartFile head_pic, HttpServletRequest request)
try
String vipName = request.getParameter("vip_name");
String vipLevel

    推荐阅读