首页 > 代码库 > JavaWeb网上图书商城完整项目--21.用户模块各层相关类的创建

JavaWeb网上图书商城完整项目--21.用户模块各层相关类的创建

1、现在要为user用户模块创建类

用户模块功能包括:注册、激活、登录、退出、修改密码。

User类对照着t_user表来写即可。我们要保证User类的属性名称与t_user表的列名称完全相同。

技术分享

 

我们来创建User类

package com.weiyuan.goods.user.domian;

public class User {

    private String uid; //主键
    private String loginname;// 登陆名称
    private String loginpass;//  登陆密码
    private String email;//注册的邮箱
    private String verifyCode; //验证码
    private boolean status;//是否激活
    private String activationCode;//激活码
    public String getUid() {
        return uid;
    }
    public void setUid(String uid) {
        this.uid = uid;
    }
    public String getLoginname() {
        return loginname;
    }
    public void setLoginname(String loginname) {
        this.loginname = loginname;
    }
    public String getLoginpass() {
        return loginpass;
    }
    public void setLoginpass(String loginpass) {
        this.loginpass = loginpass;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getVerifyCode() {
        return verifyCode;
    }
    public void setVerifyCode(String verifyCode) {
        this.verifyCode = verifyCode;
    }
    public boolean isStatus() {
        return status;
    }
    public void setStatus(boolean status) {
        this.status = status;
    }
    public String getActivationCode() {
        return activationCode;
    }
    public void setActivationCode(String activationCode) {
        this.activationCode = activationCode;
    }
    @Override
    public String toString() {
        return "User [uid=" + uid + ", loginname=" + loginname + ", loginpass="
                + loginpass + ", email=" + email + ", verifyCode=" + verifyCode
                + ", status=" + status + ", activationCode=" + activationCode
                + "]";
    }

}

数据库接口类:

UserDao封装了对数据库的基本操作。UserDao需要使用TxQueryRunner来完成对数据库的操作。

package com.weiyuan.goods.user.dao;

import cn.itcast.jdbc.TxQueryRunner;

public class UserDao {

     //操作数据库
    private TxQueryRunner qr = new TxQueryRunner();
}

业务层操作类:

UserService封装了业务功能,在UserService中每个方法对应一个业务功能,例如:注册方法、登录方法等等。一个业务方法可能需要多次调用DAO中的方法!所以,Service依赖Dao,我们需要在UserService中给出一个UserDao类型的成员。

package com.weiyuan.goods.user.service;

import com.weiyuan.goods.user.dao.UserDao;

public class UserService {

 private UserDao dao = new UserDao();    
    
}

控制层servlet,该servlet继承小工具类中BaseServlet,

UserServlet用来接收客户端请求,处理与WEB相关的问题。例如获取客户端的请求参数,然后转发或重定向等。在UserServlet中完成业务功能需要使用UserService,所以我们需要在UserServlet中给出一个UserService的成员。

因为可以让一个Servlet中有多个请求处理方法,我们让UserServlet继承BaseServlet!

UserServlet.java

package com.weiyuan.goods.user.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.itcast.servlet.BaseServlet;

/**
 * Servlet implementation class UserServlet
 */
@WebServlet("/UserServlet")
public class UserServlet extends BaseServlet{
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

 

JavaWeb网上图书商城完整项目--21.用户模块各层相关类的创建