资源下载: https://download.csdn.net/download/weixin_44893902/22035329
一、 语言和环境
-
实现语言:JAVA语言。 -
使用:MyEclipse/Eclipse + Tomcat + MySql。 -
使用技术:Jsp+Servlet+JavaBean 或SpringMVC + Spring + Mybatis。
二、 实现功能
随着信息化时代系统管理的普及,城市中各个每一个超市的会员管理也需要与时俱进,将超市的会员管理进行信息化登记和跟踪,开发一套BS结构的超市会员管理系统,主要功能如下:
- 首页默认显示所有已登记的会员信息,并且按“登记时间”降序排列,如图1所示。
(1)按登记时间降序排列。
(2)性别要求显示为“男”或“女”,不能为数据库表中的1和0显示。
(3)当鼠标移动到对应行时,需将对应行背景颜色高亮显示。
(4)底部左侧显示共XXX个会员。
(5)点击左侧的“搜索”按钮,通过姓名搜索,下方表格则显示对应搜索出来的会员信息。
(6)点击右侧“添加会员”则跳转到添加页面。
- 点击“添加会员”按钮,跳转至会员登记界面,如图2所示。
(1)姓名、出生日期不能为空。
(2)会员卡号后台按规则自动生成。
(3)会员性别在后台用1表示男,0表示女。
(4)会员等级默认为四级。
(5)会员积分默认为200分。
(6)会员登记时间为添加会员时间。
- 用户输入会员基本信息后,点击“添加会员”按钮,要求对表单进行非空验证,其中包括姓名、出生日期,都必须填入信息后才能提交,如图3所示。
- 输入完整信息提交以后,要求自动跳转至列表界面,此时列表界面显示新增的人员信息(按登记时间降序排列,应该在第一条),如图4所示。
- 用户点击“列表”界面中的删除超链接,弹出提示“您确认删除该人员登记信息?”点击确定后执行删除操作,然后列表进行自动刷新,如图5所示。
三、 数据库设
-
创建数据库(member_db)。 -
创建数据表(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;
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;
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) {
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) {
int rows=mapper.insert(tbMemberInfo);
return rows;
}
@Override
public int deleteMember(int id) {
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 {
public void generateMyBatis() {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true ;
String generatorFile = "/generatorConfig.xml";
InputStream is = Generator.class.getResourceAsStream(generatorFile);
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config;
try {
config = cp.parseConfiguration(is);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
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>
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:MyBatis/SqlMapConfig.xml"></property>
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<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 ">
<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>
<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 ">
<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>
<javaModelGenerator targetPackage="com.entity" targetProject="src">
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.dao" targetProject="src"/>
<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"/>  <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"/>  <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>
|