SSH整合开发的小Demo--网上银行系统之管理员模块开发

    花了半天时间,把管理员模块写完了,模块功能结构如下:

              


先看看结果怎样,一睹为快!











示例功能代码:

账户管理模块部分功能代码:

#数据模型层:

User.java

package com.sunline.entity;

/**
 * User entity. @author MyEclipse Persistence Tools
 */

public class User  implements java.io.Serializable {

    // Fields    

     private Integer userId;
     private String userName;
     private String userPassword;
     private String userKind;
     private Double userBalance;
     private String userStatus;


    // Constructors

    /** default constructor */
    public User() {
    }

	/** minimal constructor */
    public User(String userName, String userPassword, String userKind, Double userBalance) {
        this.userName = userName;
        this.userPassword = userPassword;
        this.userKind = userKind;
        this.userBalance = userBalance;
    }
    
    /** full constructor */
    public User(String userName, String userPassword, String userKind, Double userBalance, String userStatus) {
        this.userName = userName;
        this.userPassword = userPassword;
        this.userKind = userKind;
        this.userBalance = userBalance;
        this.userStatus = userStatus;
    }

   
    // Property accessors

    public Integer getUserId() {
        return this.userId;
    }
    
    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return this.userName;
    }
    
    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return this.userPassword;
    }
    
    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserKind() {
        return this.userKind;
    }
    
    public void setUserKind(String userKind) {
        this.userKind = userKind;
    }

    public Double getUserBalance() {
        return this.userBalance;
    }
    
    public void setUserBalance(Double userBalance) {
        this.userBalance = userBalance;
    }

    public String getUserStatus() {
        return this.userStatus;
    }
    
    public void setUserStatus(String userStatus) {
        this.userStatus = userStatus;
    }
}

User.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.sunline.entity.User" table="user" catalog="bank">
        <id name="userId" type="java.lang.Integer">
            <column name="user_id" />
            <generator class="native"></generator>
        </id>
        <property name="userName" type="java.lang.String">
            <column name="user_name" length="50" not-null="true" />
        </property>
        <property name="userPassword" type="java.lang.String">
            <column name="user_password" length="50" not-null="true" />
        </property>
        <property name="userKind" type="java.lang.String">
            <column name="user_kind" length="50" not-null="true" />
        </property>
        <property name="userBalance" type="java.lang.Double">
            <column name="user_balance" precision="15" not-null="true" />
        </property>
        <property name="userStatus" type="java.lang.String">
            <column name="user_status" length="4" />
        </property>
    </class>
</hibernate-mapping>

#数据访问层

UserDao.java

package com.sunline.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.sunline.entity.TransactionLog;
import com.sunline.entity.User;
import com.sunline.entity.UserInfo;
@Repository("UserDao")
public class UserDao extends HibernateDaoSupport {
	/*
	 * 查找某种状态的客户
	 */
	@SuppressWarnings("unchecked")
	public List<User> GetUserStatus(User user){
		String hsql= "from User where userKind= :userKind and userStatus = :userStatus";
		String paramNames[] = {"userKind" , "userStatus"};
		String paramValues[] = {user.getUserKind(),user.getUserStatus()};  
		//findByNamedParam方法提供hql方法参数查询,避免Sql注入漏洞  
		List<User> result = (List<User>) this.getHibernateTemplate().findByNamedParam(hsql, paramNames, paramValues);
		return result;
	}
	
	/*
	 * 根据userId删除用户信息
	 */
	public void DeleteUser(int userId){
		System.out.println("成功删除数据!");
		this.getHibernateTemplate().delete(findById(userId));
	}
	
	/*
	 * 修改用户状态
	 */
	public void UpdateUserStatus(String userStatus, int userId){
		this.getHibernateTemplate().bulkUpdate("update User set userStatus = ? where userId = ?",new Object[]{userStatus,userId}) ;
	}
	
	/*
	 * 添加用户
	 */
    public void AddUser(User user){
	    System.out.println("成功添加用户");
		this.getHibernateTemplate().save(user);
    }
    
	/*
	 * 获取所有用户信息
	 */
	@SuppressWarnings("unchecked")
	public List<User> findAll(){
		String sql="from User";
		List<User> list=this.getHibernateTemplate().find(sql);
		return list;
	}
}

#业务逻辑层

UserBiz.java

package com.sunline.biz;

import java.util.List;

import com.sunline.dao.UserDao;
import com.sunline.entity.User;

public class UserBiz {
	UserDao userDao;

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	/*
	 * 查找某种状态的客户
	 */
	@SuppressWarnings("unchecked")
	public List<User> GetUserStatus(User user){
		return userDao.GetUserStatus(user);
	}
	
	/*
	 * 根据用户id删除用户信息
	 */
	public void deleteUser(int userId) {
		userDao.DeleteUser(userId);
     }
	
	/*
	 * 修改用户状态
	 */
	public void UpdateUserStatus(String userStatus, int userId){
		userDao.UpdateUserStatus(userStatus, userId);
	}
	
	/*
	 * 添加用户
	 */
    public void AddUser(User user){
        userDao.AddUser(user);
    }
    
	/*
	 * 获取所有账户信息
	 */
	@SuppressWarnings("unchecked")
	public User getLast(){
		List<User> result=userDao.findAll();
		int length = result.size();
        if(result.size() > 0) {  
            return result.get(length-1);  
        }  
		return null;
	}
}

#控制层

UserAction.java

package com.sunline.action;

import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sunline.biz.UserBiz;
import com.sunline.biz.UserInfoBiz;
import com.sunline.entity.User;
import com.sunline.entity.UserInfo;

public class UserAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private Integer id;
    private Integer userId;
    private String userName;
    private String userPassword;
    private String userKind;
    private Double userBalance;
    private String userStatus;
    
	private String oldpwd;
	private String newpwd;
	private String confirmpwd;
	
	ActionContext contextq = ActionContext.getContext();
	Map<String, Object> session = contextq.getSession();
    ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); 
    UserBiz userBiz = (UserBiz) context.getBean("UserBiz");
    UserInfoBiz userInfoBiz = (UserInfoBiz)context.getBean("UserInfoBiz");
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getUserPassword() {
		return userPassword;
	}
	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}
	public String getUserKind() {
		return userKind;
	}
	public void setUserKind(String userKind) {
		this.userKind = userKind;
	}
	public Double getUserBalance() {
		return userBalance;
	}
	public void setUserBalance(Double userBalance) {
		this.userBalance = userBalance;
	}
	public String getUserStatus() {
		return userStatus;
	}
	public void setUserStatus(String userStatus) {
		this.userStatus = userStatus;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	
	public String getOldpwd() {
		return oldpwd;
	}
	public void setOldpwd(String oldpwd) {
		this.oldpwd = oldpwd;
	}
	public String getNewpwd() {
		return newpwd;
	}
	public void setNewpwd(String newpwd) {
		this.newpwd = newpwd;
	}
	public String getConfirmpwd() {
		return confirmpwd;
	}
	public void setConfirmpwd(String confirmpwd) {
		this.confirmpwd = confirmpwd;
	}
	
	/*
	 * 修改密码
	 */
	public String UpdatePassword() throws Exception{
		User user = userBiz.findByName(this.userName);   //查询该对象
		String id = user.getUserId().toString();
	    int user_id = Integer.parseInt(id);
		String password = user.getUserPassword();
		if(this.oldpwd.equals(password)){
			userBiz.UpdatePassword(this.newpwd, user_id);
			return SUCCESS;
		}
		else{
			session.put("UpdateError", "你输入的密码有误!");
			return INPUT;
		}
	}
	
	/*
	 * 删除用户及用户信息
	 */
	public String deleteUser() throws Exception{
		userInfoBiz.deleteUserInfo(this.id);              //删除用户信息
		userBiz.deleteUser(this.userId);             //删除该用户
		return SUCCESS;
	}
	
	/*
	 * 冻结账户
	 */
	public String Freeze() throws Exception{
		String status = "冻结";
		userBiz.UpdateUserStatus(status, this.userId);
		return SUCCESS;
	}
	
	/*
	 * 启用账户
	 */
	public String Enable() throws Exception{
		String status = "正常";
		userBiz.UpdateUserStatus(status, this.userId);
		return SUCCESS;
	}
}

#视图层(部分代码)

AllAccount.jsp

<%@page import="com.sunline.entity.UserInfo"%>
<%@page import="com.sunline.entity.User"%>
<%@page import="com.sunline.biz.UserBiz"%>
<%@page import="com.sunline.biz.UserInfoBiz"%>
<%@page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>所有账户</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  <link rel="stylesheet" href="bootstrap-3.3.7/css/bootstrap.min.css">  
  <script src="js/jquery-3.2.1.min.js"></script>    
  <script src="js/bootstrap.min.js"></script>  
  <script type="text/javascript">
//查询
function doQuery() {
	var hide=document.getElementById("result");   
	$("#queryform_1").submit();
}

//重置
function doReset() {
	$("input[name='realname']").val("");
}
</script>
  </head>
  
 <body>
 <div class="container-fluid row form-group">
  <div class="panel panel-primary"> 
     <div class="panel-heading">
          <strong>查询区域</strong>
          <div style="float: right;overflow:hidden;">
             <span class="input-group-addon" id="sizing-addon1">
                 <a οnclick="doQuery()" href="#"><i class="glyphicon glyphicon-search" aria-hidden="true">查询</i></a>
             </span>
          </div>
     </div>
   <!-- 导入工具弹出框 -->

   <div class="panel-body">
   <form action="${pageContext.request.contextPath }/QueryDimension" method="post" id="queryform_1">
       <table>
        <tr>
           <td style="padding-right: 15px"><label>输入要查询用户的真实姓名:</label></td>
           <td style="padding-right: 70px;"><input type="text" name="realname"/></td>       
      </table>
    </form>
   </div>
  </div>
</div>

<div class="container-fluid row form-group">
  <div class="panel panel-primary"> 
     <div class="panel-heading">
          <strong>查询结果</strong>
     </div>
     
     <div class="panel-body">
     <div id="result">
      <table class="table table-hover" border="1">
         <tr class="success">
            <td>序列</td>
            <td>账户</td>
            <td>姓名</td>
            <td>账户余额</td>
            <td>家庭地址</td>
            <td>证件号码</td>
            <td>电话</td>
            <td>状态</td>
            <td>操作</td>
         </tr>
         <%
            //加载applicationContext.xml配置  
	        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
	        //获取配置中的实例  
	        UserInfoBiz userInfoBiz = (UserInfoBiz) context.getBean("UserInfoBiz");
	        UserBiz userBiz = (UserBiz) context.getBean("UserBiz");
	        List<User> li = userBiz.findByUserKind("客户");
            List<UserInfo> list = userInfoBiz.findAll();
            for(int i=0; i<list.size(); i++){
          %>
           <tr>
              <td><%=i+1%></td>
              <td><%=list.get(i).getUserId() %></td>
              <td><%=list.get(i).getRealname() %></td>
              <td><%=li.get(i).getUserBalance() %></td>
              <td><%=list.get(i).getAddress() %></td>
              <td><%=list.get(i).getCardId() %></td>
              <td><%=list.get(i).getTelephone() %></td>
              <td><%=li.get(i).getUserStatus() %></td>
              <td>
                  <a href="javascript:if(confirm('确认是否冻结该账户?')) location='<%=request.getContextPath() %>/freeze?userId=<%=li.get(i).getUserId()%>'"/>
                  <i class="glyphicon glyphicon-tint" aria-hidden="true">冻结</i></a>
                  <label>|</label>
                  <a href="javascript:if(confirm('确认是否删除该账户?')) location='<%=request.getContextPath() %>/deleteUser?userId=<%=li.get(i).getUserId()%>&&id=<%=list.get(i).getId()%>'"/>
                  <i class="glyphicon glyphicon-remove-circle" aria-hidden="true">删除</i></a>
              </td>
           </tr>
       <%
          }
        %>
      </table>
     </div>	
    </div>
  </div>
</div>
 </body>
</html>

OpenAccount.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>我要开户</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  <link rel="stylesheet" href="bootstrap-3.3.7/css/bootstrap.min.css">  
  <script src="js/jquery-3.2.1.min.js"></script>    
  <script src="js/bootstrap.min.js"></script> 
  </head>
  
 <body>
 <div class="container-fluid row form-group">
  <div class="panel panel-info"> 
     <div class="panel-heading">
          <strong class="glyphicon glyphicon-plus-sign" style="text-align: left;">我要开户</strong>
     </div>
     <div class="panel-body">
     <form action="${pageContext.request.contextPath }/AddUser" method="post">
      <table class="table table-hover" border="1">
        <tr style="height: 40px;">
            <td class="success">
               <label style="width: 100px;text-align: right;padding-right: 15px;">用户名:</label>
               <input type="text" name="userName" id="userName"  style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">密码:</label>
               <input type="password" name="userPassword" id="userPassword"  style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">确认密码:</label>
               <input type="password" name="Password" id="Password"  style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">开户金额:</label>
               <input type="text" name="userBalance" id="userBalance"  style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">姓名 :</label>
               <input type="text" name="realname" id="realname"  style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">年龄:</label>
               <input type="text" name="age" id="age" aria-describedby="sizing-addon1" style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">性别:</label>
               <input type="text" name="sex" id="sex" style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">家庭地址:</label>
               <input type="text" name="address" id="address"  style="height: 32px;" />
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">联系电话:</label>
               <input type="text" name="telephone" id="telephone" style="height: 32px;"/>
            </td>
        </tr>
        <tr style="height: 40px;">
            <td>
               <label style="width: 100px;text-align: right;padding-right: 15px;">证件号码:</label>
               <input type="text" name="cardId" id="cardId"  style="height: 32px;" />
            </td>
        </tr>
        <tr style="height: 40px;">
           <td>
              <label style="width: 100px;text-align: right;padding-right: 15px;"></label>
              <button type="submit" class="btn btn-success">
                 <span class="glyphicon glyphicon-saved"></span>开户
              </button>
           </td>
        </tr>
     </table>
     </form>
    </div>
  </div>
</div>
</body>
</html>


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潇潇雨歇_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值