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

一、 语言和环境
实现语言: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;

-- ----------------------------
-- 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');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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";
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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);

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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;
    }
    
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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();
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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>
1
2
3
4
5
6
7
8
9
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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
1
2
3
4
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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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="添加" οnclick="jy()">
                <input type="button" οnclick="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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值