基于Spring MVC + Spring + MyBatis的【超市会员管理系统】

基于Spring MVC + Spring + MyBatis的【超市会员管理系统】文章目录一、**语言和环境**二、**实现功能**三、**数据库设计**四、**具体要求及推荐实现步骤**五、**实现代码**MySQL数据库:JAVA代码:一、语言和环境实现语言:JAVA语言。使用:MyEclipse/Eclipse+Tomcat+MySql。使用技术:Jsp+Servlet+JavaBean或SpringMVC+Spring+Mybatis。二、实现功能随着信息化时代系统管理的普及,城市中各个每一个超市的会员管理也需要与时.

大家好,又见面了,我是你们的朋友全栈君。

资源下载:
https://download.csdn.net/download/weixin_44893902/22035329

一、 语言和环境

  1. 实现语言:JAVA语言。

  2. 使用:MyEclipse/Eclipse + Tomcat + MySql。

  3. 使用技术:Jsp+Servlet+JavaBean 或SpringMVC + Spring + Mybatis。

二、 实现功能

随着信息化时代系统管理的普及,城市中各个每一个超市的会员管理也需要与时俱进,将超市的会员管理进行信息化登记和跟踪,开发一套BS结构的超市会员管理系统,主要功能如下:

  1. 首页默认显示所有已登记的会员信息,并且按“登记时间”降序排列,如图1所示。

(1)按登记时间降序排列。

(2)性别要求显示为“男”或“女”,不能为数据库表中的1和0显示。

(3)当鼠标移动到对应行时,需将对应行背景颜色高亮显示。

(4)底部左侧显示共XXX个会员。

(5)点击左侧的“搜索”按钮,通过姓名搜索,下方表格则显示对应搜索出来的会员信息。

(6)点击右侧“添加会员”则跳转到添加页面。

图1 首页显示所有登记会员信息

  1. 点击“添加会员”按钮,跳转至会员登记界面,如图2所示。

(1)姓名、出生日期不能为空。

(2)会员卡号后台按规则自动生成。

(3)会员性别在后台用1表示男,0表示女。

(4)会员等级默认为四级。

(5)会员积分默认为200分。

(6)会员登记时间为添加会员时间。

[图2 新增会员信息界面(img-qxHw9c7l-1630313966663)(file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml18292\wps8.jpg)]

  1. 用户输入会员基本信息后,点击“添加会员”按钮,要求对表单进行非空验证,其中包括姓名、出生日期,都必须填入信息后才能提交,如图3所示。

图3 提交录入提示信息述

  1. 输入完整信息提交以后,要求自动跳转至列表界面,此时列表界面显示新增的人员信息(按登记时间降序排列,应该在第一条),如图4所示。

在这里插入图片描述

  1. 用户点击“列表”界面中的删除超链接,弹出提示“您确认删除该人员登记信息?”点击确定后执行删除操作,然后列表进行自动刷新,如图5所示。
    在这里插入图片描述

三、 数据库设计

  1. 创建数据库(member_db)。

  2. 创建数据表(tb_member_info),结构如下。

字段名 说明 字段类型 长度 备注
id 编号 int 主键,自增,增量为1
card_no 卡号 varchar 50 不能为空
name 姓名 varchar 50 不能为空
sex 性别 int 不能为空,1和0,1代表男,0代表女
birthday 出生日期 date 不能为空
grade 会员等级 varchar 20 不能为空
integral 会员积分 int 不能为空,默认200
Write_time 登记日期 datetime 登记日期,录入时自动获取当前时间

四、 具体要求及推荐实现步骤

1.JSP版本的实现步骤如下:

(1)按以上数据库要求建库、建表,并添加测试数据(不少于5条,测试数据不需要和上图一致)。

(2)创建Web工程并创建各个包,导入工程所需的jar文件。

(3)创建MemberInfo实体类。

(4)创建Servlet获取用户不同的请求,并将这些请求转发至业务处理层相应的业务方法。

(5)创建业务处理层,在其中定义业务方法,实现系统需求,在这些业务方法中需要执行DAO方法。

(6)创建BaseDAO工具类,使用JDBC完成数据表数据的查询、删除、添加的功能方法代码。

(7)编写JSP页面展示数据的查询结果。

2.SSM版本的实现步骤如下:

(1)创建数据库,创建数据表,添加测试数据(不少于5条,测试数据不需要和上图一致)。

(2)创建Web工程并创建各个包,导入工程所需的jar文件。

(3)添加相关SSM框架支持。

(4)配置项目所需要的各种配置文件(mybatis配置文件、spring配置文件、springMVC配置文件)。

(5)创建实体类。

(6)创建MyBatis操作数据库所需的Mapper接口及其Xml映射数据库操作语句文件。

(7)创建业务逻辑相应的接口及其实现类,实现相应的业务,并在类中加入对DAO/Mapper的引用和注入。

(8)创建Controller控制器类,在Controller中添加对业务逻辑类的引用和注入,并配置springMVC配置文件。

(9)创建相关的操作页面,并使用CSS对页面进行美化。

(10)实现页面的各项操作功能,并在相关地方进行验证,操作要人性化。

(11)调试运行成功后导出相关的数据库文件并提交。

五、 实现代码

1、MySQL数据库:

member_db.sql
在这里插入图片描述

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `tb_member_info`
-- ----------------------------
DROP TABLE IF EXISTS `tb_member_info`;
CREATE TABLE `tb_member_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`card_no` varchar(50) NOT NULL,
`name` varchar(50) NOT NULL,
`sex` int(11) DEFAULT NULL,
`birthday` date NOT NULL,
`grade` varchar(20) NOT NULL,
`integral` int(11) NOT NULL DEFAULT '200',
`Write_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tb_member_info
-- ----------------------------
INSERT INTO `tb_member_info` VALUES ('1', 'CS0601202100146245', '杨过', '1', '2021-07-19', '一级', '200', '2021-07-19 18:00:44');
INSERT INTO `tb_member_info` VALUES ('2', 'CS0601202100245211', '杨明金', '1', '2021-07-19', '一级', '5000', '2021-07-19 18:02:35');
INSERT INTO `tb_member_info` VALUES ('3', 'CS0620210305236547', '黄静文', '0', '2021-07-19', '一级', '200', '2021-07-19 18:03:11');
INSERT INTO `tb_member_info` VALUES ('4', 'CS0620210712546895', '李三', '0', '2021-07-02', '四级', '200', '2021-07-19 20:18:01');
INSERT INTO `tb_member_info` VALUES ('5', 'CS0620212315568456', '王二麻子', '1', '2021-07-10', '四级', '200', '2021-07-19 20:21:10');
INSERT INTO `tb_member_info` VALUES ('10', 'CS0620210719319319', '杨明金', '1', '2021-07-10', '四级', '200', '2021-07-19 22:02:09');
INSERT INTO `tb_member_info` VALUES ('13', 'CS0620210720577265', '杨明金', '1', '2021-07-16', '四级', '200', '2021-07-20 10:20:06');

2、JAVA代码:

目录结构:
在这里插入图片描述

com.controller

MemberController.java

package com.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.TbMemberInfo;
import com.service.MemberService;
@Controller
public class MemberController { 

@Resource
private MemberService service;
@RequestMapping("selectAll")
public String selectAll(Model model ,String name) { 

if (name==null||name.equals("")) { 

name="";
}
List<TbMemberInfo> list=service.selectAll(name);
model.addAttribute("memberList", list);
return "/member";
}
//添加页面跳转
@RequestMapping("addPage")
public String addPage() { 

return "/addPage";
}
//自动生成卡号的方法
public static String getRandomString(int length){ 

String str="0123456789";
Random random=new Random();
StringBuffer sb=new StringBuffer();
for(int i=0;i<length;i++){ 

int number=random.nextInt(10);
sb.append(str.charAt(number));
}
SimpleDateFormat simple=new SimpleDateFormat("yyyyMMdd");
String dddString2=simple.format(new Date());
return "CS06"+dddString2+sb.toString();
}
//添加
@RequestMapping("addmember")
public String addmember(TbMemberInfo tbMemberInfo) { 

tbMemberInfo.setCardNo(getRandomString(6));
tbMemberInfo.setGrade("四级");
tbMemberInfo.setIntegral(200);
SimpleDateFormat simple=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
tbMemberInfo.setWriteTime(simple.format(new Date()));
int rows=service.addMember(tbMemberInfo);
return "redirect:/selectAll.do";
}
//删除
@RequestMapping("deletemember")
public String deletemember(int id) { 

int rows=service.deleteMember(id);
return "redirect:/selectAll.do";
}
}

com.dao

TbMemberInfoMapper.java

package com.dao;
import com.entity.TbMemberInfo;
import java.util.List;
public interface TbMemberInfoMapper { 

int deleteByPrimaryKey(Integer id);
int insert(TbMemberInfo record);
TbMemberInfo selectByPrimaryKey(Integer id);
List<TbMemberInfo> selectAll();
int updateByPrimaryKey(TbMemberInfo record);
//根据姓名查询
List<TbMemberInfo> selsceName(String name);
}

TbMemberInfoMapper.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.dao.TbMemberInfoMapper" >
<resultMap id="BaseResultMap" type="com.entity.TbMemberInfo" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="card_no" property="cardNo" jdbcType="VARCHAR" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="sex" property="sex" jdbcType="INTEGER" />
<result column="birthday" property="birthday" jdbcType="DATE" />
<result column="grade" property="grade" jdbcType="VARCHAR" />
<result column="integral" property="integral" jdbcType="INTEGER" />
<result column="Write_time" property="writeTime" jdbcType="TIMESTAMP" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from tb_member_info
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.entity.TbMemberInfo" >
insert into tb_member_info (id, card_no, name, 
sex, birthday, grade, 
integral, Write_time)
values (#{id,jdbcType=INTEGER}, #{cardNo,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
#{sex,jdbcType=INTEGER}, #{birthday,jdbcType=DATE}, #{grade,jdbcType=VARCHAR}, 
#{integral,jdbcType=INTEGER}, #{writeTime,jdbcType=TIMESTAMP})
</insert>
<update id="updateByPrimaryKey" parameterType="com.entity.TbMemberInfo" >
update tb_member_info
set card_no = #{cardNo,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
sex = #{sex,jdbcType=INTEGER},
birthday = #{birthday,jdbcType=DATE},
grade = #{grade,jdbcType=VARCHAR},
integral = #{integral,jdbcType=INTEGER},
Write_time = #{writeTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select id, card_no, name, sex, birthday, grade, integral, Write_time
from tb_member_info
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap" >
select id, card_no, name, sex, birthday, grade, integral, Write_time
from tb_member_info ORDER BY Write_time DESC
</select>
<select id="selsceName" resultMap="BaseResultMap" >
select id, card_no, name, sex, birthday, grade, integral, Write_time
from tb_member_info  where `name` LIKE "%"#{name}"%" ORDER BY Write_time DESC
</select>
</mapper>

com.entity

TbMemberInfo.java

package com.entity;
public class TbMemberInfo { 

private Integer id;
private String cardNo;
private String name;
private Integer sex;
private String birthday;
private String grade;
private Integer integral;
private String writeTime;
public Integer getId() { 

return id;
}
public void setId(Integer id) { 

this.id = id;
}
public String getCardNo() { 

return cardNo;
}
public void setCardNo(String cardNo) { 

this.cardNo = cardNo == null ? null : cardNo.trim();
}
public String getName() { 

return name;
}
public void setName(String name) { 

this.name = name == null ? null : name.trim();
}
public Integer getSex() { 

return sex;
}
public void setSex(Integer sex) { 

this.sex = sex;
}
public String getBirthday() { 

return birthday;
}
public void setBirthday(String birthday) { 

this.birthday = birthday;
}
public String getGrade() { 

return grade;
}
public void setGrade(String grade) { 

this.grade = grade == null ? null : grade.trim();
}
public Integer getIntegral() { 

return integral;
}
public void setIntegral(Integer integral) { 

this.integral = integral;
}
public String getWriteTime() { 

return writeTime;
}
public void setWriteTime(String writeTime) { 

this.writeTime = writeTime;
}
}

com.service

MemberService.java

package com.service;
import java.util.List;
import com.entity.TbMemberInfo;
public interface MemberService { 

//查询所有
List<TbMemberInfo> selectAll(String name);
//添加
int addMember(TbMemberInfo tbMemberInfo);
//删除
int deleteMember(int id);
}

com.service.impl

MemberServiceImpl.java

package com.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.dao.TbMemberInfoMapper;
import com.entity.TbMemberInfo;
import com.service.MemberService;
@Service
public class MemberServiceImpl implements MemberService { 

@Resource
private TbMemberInfoMapper mapper;
@Override
public List<TbMemberInfo> selectAll(String name) { 

// TODO Auto-generated method stub
if (name.equals("")||name==null) { 

List<TbMemberInfo> list=mapper.selectAll();
return list;
}else { 

List<TbMemberInfo> list=mapper.selsceName(name);
return list;
}
}
@Override
public int addMember(TbMemberInfo tbMemberInfo) { 

// TODO Auto-generated method stub
int rows=mapper.insert(tbMemberInfo);
return rows;
}
@Override
public int deleteMember(int id) { 

// TODO Auto-generated method stub
int rows=mapper.deleteByPrimaryKey(id);
return rows;
}
}

genter

Generator.java

package genter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
public class Generator { 

/* * targetRuntime="MyBatis3Simple", 不生成Example */
public void generateMyBatis() { 

//MBG执行过程中的警告信息
List<String> warnings = new ArrayList<String>();
//当生成的代码重复时,覆盖原代码
boolean overwrite = true ;
String generatorFile = "/generatorConfig.xml";
//String generatorFile = "/generator/generatorConfigExample.xml";
//读取MBG配置文件
InputStream is = Generator.class.getResourceAsStream(generatorFile);
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config;
try { 

config = cp.parseConfiguration(is);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
//创建MBG
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
//执行生成代码
myBatisGenerator.generate(null);
} catch (IOException e) { 

e.printStackTrace();
} catch (XMLParserException e) { 

e.printStackTrace();
} catch (InvalidConfigurationException e) { 

e.printStackTrace();
} catch (SQLException e) { 

e.printStackTrace();
} catch (InterruptedException e) { 

e.printStackTrace();
}
for (String warning : warnings) { 

System.out.println(warning);
}
}
public static void main(String[] args) { 

Generator generator = new Generator();
generator.generateMyBatis();
}
}

MyBatis

SqlMapConfig.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.entity"/>
</typeAliases>
</configuration>

spring

applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
<context:property-placeholder location="classpath:dataSource.properties"/>
<!-- 数据源配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${db.driverClass}"></property>
<property name="Url" value="${db.jdbcUrl}"></property>
<property name="username" value="${db.user}"></property>
<property name="password" value="${db.password}"></property>
</bean>
<!-- 配置SqlSessionFactory -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 设置MyBatis核心配置文件 -->
<property name="configLocation" value="classpath:MyBatis/SqlMapConfig.xml"></property>
<!-- 设置数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置Mapper扫描 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 设置Mapper扫描包 -->
<property name="basePackage" value="com.dao"></property>
</bean>	
</beans>

applicationContext-service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
<!-- 配置Service层扫描 -->
<context:component-scan base-package="com.service"></context:component-scan>	
<!-- 配置事务管理层 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 开启注解方式管理AOP事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">
<!-- 配置Controller层扫描包 -->	
<context:component-scan base-package="com.controller"></context:component-scan>
<!-- 配置注解驱动 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix" value="/WEB-INF/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>

dataSource.properties

db.driverClass=com.mysql.jdbc.Driver
db.jdbcUrl=jdbc:mysql://127.0.0.1:3306/member_db
db.user=root
db.password=123456

generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<!-- 配置生成器 -->
<generatorConfiguration>
<context id="MySQLContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<!-- 配置前置分隔符和后置分隔符 -->
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 配置注释信息 -->
<commentGenerator>
<!-- 不生成注释 -->
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
<property name="addRemarkComments" value="true"/>
</commentGenerator>
<!-- 数据库连接配置 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/member_db" userId="root" password="123456">
</jdbcConnection>
<!-- targetPackage:生成实体类存放的包名, targetProject:指定目标项目路径,可以使用相对路径或绝对路径 -->
<javaModelGenerator targetPackage="com.entity" targetProject="src">
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 配置SQL映射器Mapper.xml文件的属性 -->
<sqlMapGenerator targetPackage="com.dao" targetProject="src"/>
<!-- type="XMLMAPPER":所有的方法都在XML中,接口调用依赖XML文件 -->
<javaClientGenerator targetPackage="com.dao" type="XMLMAPPER" targetProject="src"/>
<!-- 生成所有表的映射 -->
<table tableName="%"></table>		
</context>
</generatorConfiguration>

3、JSP页面代码:

addPage.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<style type="text/css"> .boddy{ 
 border:1px solid black; width: 30%; margin: 0 auto; padding: 20px; } </style>
</head>
<body>
<div class="boddy">
<h1>添加会员</h1>
<form action="addmember.do">
<p>
<label>姓名:</label>
<input type="text" id="name" name="name"/>&nbsp&nbsp<span style="color: red">必填</span>
</p>
<p>
<label>性别:</label>
<input type="radio" value="1" name="sex" checked="checked"><input type="radio" value="0" name="sex"></p>
<p>
<label>出生日期:</label>
<input type="date" id="birthday" name="birthday"/>&nbsp&nbsp<span style="color: red">必填</span>
</p>
<p>
<input id="a" type="button" value="添加" onclick="jy()">
<input type="button" onclick="window.history.back();" value="取消">
</p>
</form>
</div>
<script src="../js/jquery-3.2.1.js"></script>
<script type="text/javascript"> function jy() { 
 var name=document.getElementById('name').value; var birthday=document.getElementById('birthday').value; if(name==""){ 
 alert('姓名不能为空'); return false; }else if (birthday=="") { 
 alert('生日不能为空'); return false; }else{ 
 document.getElementById('a').setAttribute('type','submit'); return true; } } </script>
</body>
</html>

member.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>超市会员管理系统</title>
</head>
<style> *{ 
 margin: 0;padding: 0; } table,td,th{ 
 border-collapse: collapse; border-spacing: 0; } table{ 
 text-align:center; width: 80%; margin: 0 auto; } td,th{ 
 padding: 5px 10px; border: 1px solid black; } th{ 
 background: #284bf8; font-size: 1.3rem; font-weight: 450; color: white; cursor: pointer; } .form{ 
 width:80%; padding:10px; margin: 0 auto; } .bottom{ 
 width:80%; padding:10px; margin: 0 auto; } h1{ 
 text-align:center; } tr:hover{ 
 background: #a1a4b5; } </style>
<body>
<div class="form">
<h1>超市会员管理系统</h1><br/>
<form action="selectAll.do">
<a href="addPage.do" >添加</a>
<input type="text" placeholder="请输入姓名搜索" name="name" />
<button type="submit">搜索</button>
</form>
</div>
<table>
<tr>
<th>序号</th>
<th>会员卡号</th>
<th>姓名</th>
<th>性别</th>
<th>出生日期</th>
<th>会员等级</th>
<th>会员积分</th>
<th>登记时间</th>
<th>操作</th>
</tr>
<c:forEach items="${memberList }" var="member" varStatus="item">
<tr>
<td>${item.index+1 }</td>
<td>${member.cardNo }</td>
<td>${member.name }</td>
<c:if test="${member.sex==1 }"><td></td></c:if>
<c:if test="${member.sex==0 }"><td></td></c:if>
<td>${member.birthday }</td>
<td>${member.grade }</td>
<td>${member.integral }</td>
<td>${member.writeTime }</td>
<td>
<a style="color: red" onclick="del(${member.id })">删除</a>
</td>
</tr>
</c:forEach>
</table>
<div class="bottom">
共${memberList.size() }个会员
</div>
<script type="text/javascript"> function del(id){ 
 if(confirm("确认要删除吗?")){ 
 return window.location.href="deletemember.do?id="+id; }else { 
 return false; } } </script>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<script> window.location.href = "selectAll.do"; </script>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>member_db</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
</web-app>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/149783.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • ideavim怎么用_idea常用快捷键图文

    ideavim怎么用_idea常用快捷键图文学了这么久的VIM,当然还是要用在开发上。下面来介绍一下ideavim这个插件。IdeaVim是用于基于IntelliJ平台的IDE的Vim仿真插件。IdeaVim支持许多Vim功能,包括普通/插入/可视模式,动作键,删除/更改,标记,寄存器,一些Ex命令,Vimregexp,通过〜/.ideavimrc配置,宏,窗口命令等。另外还可以自定义ideavim的快捷键,定制专属的快捷键。安装I…

  • 怎么git 自己建的服务器_如何搭建自己的git服务器「建议收藏」

    怎么git 自己建的服务器_如何搭建自己的git服务器「建议收藏」前几天在服务器亲自搭建git服务器,之前只是我自学了git的知识,在网上找了很多资料,重装了很多次,都不知道怎么使用,最后自己研究了好几遍,终于把git服务器搭建起来了。但是不知道我这种方法对不对,分享出来,希望大家指正。安装git$yuminstallcurl-develexpat-develgettext-developenssl-develzlib-develperl-dev…

  • 分布式CAP原理

    分布式CAP原理Consistentdata:    Operationscommitorfailintheirentirety(atomic)    操作的提交或者失败都是整体的(原子性)    Transactionsneverobserveorresultininconsistentdata(consistent)        事务不会导致不一致的数据  

  • JAVA中字符串常量池和缓冲池理解与作用「建议收藏」

    JAVA中字符串常量池和缓冲池理解与作用「建议收藏」字符串池与常量池是完全不同的两个东西,但是很多地方都喜欢把它们混为一谈,很容易让初学者产生误解,在这里我想好好讨论一下它们。字符串池也可以被称为字符串常量池,我认为这个名称就是产生误解的根源,有些人说着说着就把字符串三个字省略了,只剩下了常量池…所以为了避免误解,我建议在指代字符串对象的缓存池的时候,就直接称之为字符串池1常量池常量池分为两个类型,一是.class文件中静态的常量池,二是.class文件中的静态常量池被加载到JVM中而形成的运行时常量池。1.1静态常量池.cla

  • linux系统centos7安装nginx

    linux系统centos7安装nginxlinux系统centos7安装nginx,简单亲自测试成功

  • 手把手从零开始学习树莓派教程

    手把手从零开始学习树莓派教程项目开始时间:2021/4/1119:43树莓派4b文章目录1.树莓派系统下载2.操作系统移植3.树莓派联网1.树莓派系统下载这里使用raspbian-buster-full系统,官网速度太慢,使用清华镜像下载也很慢,官网下载种子,然后用迅雷下载比较快。解压后8个g,我用的32gsd卡2.操作系统移植用win32diskimager工具把操作系统写入SD卡,插入树莓派中,启动毫无响应,将sd卡从树莓派上拔下,用读卡器再次插入电脑usb口,显示类似这样:在网上找了很多办法,都不能解决,

    2022年10月14日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号