@TOC

SSM实现的家庭理财管理系统

本系统是实现了基于家庭收入支出的统计管理,通过普通用户和管理员的维度进行了系统的角色划分,提高了系统的易用性和合理性,同时管理员实现了对收入支出情况的可视化图表的统计,便于用户做出合理的财务决策。
管理员也可以扩展记账的收入支出字典模块(如日常、股票等)

实现功能截图

登录页面
在这里插入图片描述
普通用户主页
在这里插入图片描述

持股管理
在这里插入图片描述
管理员用户信息管理
在这里插入图片描述
角色管理
在这里插入图片描述
收入信息维护
在这里插入图片描述
数据字典管理
在这里插入图片描述
修改密码
在这里插入图片描述
支出信息维护
在这里插入图片描述

报表可视化统计
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

系统功能

本家庭理财管理系统实现了以下功能:
1、注册登录
2、普通用户收入、支出记录
管理员
1、角色管理
2、收入、支出信息维护
3、报表可视化统计
4、数据字典管理
5、修改密码
6、用户管理

使用技术

数据库:mysql
开发工具:Eclipse(Myeclispe、Idea也可以)
知识点:SSM

代码

实体类
DataDic.java

package com.finance.entity;

public class Datadic {
    private Integer id; // 编号
    private String datadicname; // 数据字典名称
    private String datadicvalue; // 数据字典值
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getDatadicname() {
        return datadicname;
    }
    public void setDatadicname(String datadicname) {
        this.datadicname = datadicname;
    }
    public String getDatadicvalue() {
        return datadicvalue;
    }
    public void setDatadicvalue(String datadicvalue) {
        this.datadicvalue = datadicvalue;
    }

}

Income.java

package com.finance.entity;

public class Income {
    private Integer id; // 编号
    private Integer userid; // 创建人ID
    private Integer roleid; // 创建人角色
    private String incomer; // 收入人
    private String source; // 来源
    private Integer money; // 金额
    private Integer dataid; // 类型
    private String content; // 备注
    private String incometime; // 收入时间
    private String createtime; // 创建时间
    private String updatetime; // 更新时间

    private String datadicname; // 数据字典名字
    private String datadicvalue; // 数据字典值
    private String username;// 记录人

    private String starttime;//搜索起始时间
    private String endtime;//搜索截止时间

    public String getStarttime() {
        return starttime;
    }
    public void setStarttime(String starttime) {
        this.starttime = starttime;
    }
    public String getEndtime() {
        return endtime;
    }
    public void setEndtime(String endtime) {
        this.endtime = endtime;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getUserid() {
        return userid;
    }
    public void setUserid(Integer userid) {
        this.userid = userid;
    }
    public Integer getRoleid() {
        return roleid;
    }
    public void setRoleid(Integer roleid) {
        this.roleid = roleid;
    }
    public String getIncomer() {
        return incomer;
    }
    public void setIncomer(String incomer) {
        this.incomer = incomer;
    }
    public String getSource() {
        return source;
    }
    public void setSource(String source) {
        this.source = source;
    }
    public Integer getMoney() {
        return money;
    }
    public void setMoney(Integer money) {
        this.money = money;
    }
    public Integer getDataid() {
        return dataid;
    }
    public void setDataid(Integer dataid) {
        this.dataid = dataid;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getIncometime() {
        return incometime;
    }
    public void setIncometime(String incometime) {
        this.incometime = incometime;
    }
    public String getCreatetime() {
        return createtime;
    }
    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }
    public String getUpdatetime() {
        return updatetime;
    }
    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }
    public String getDatadicname() {
        return datadicname;
    }
    public void setDatadicname(String datadicname) {
        this.datadicname = datadicname;
    }
    public String getDatadicvalue() {
        return datadicvalue;
    }
    public void setDatadicvalue(String datadicvalue) {
        this.datadicvalue = datadicvalue;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

}

user.java

package com.finance.entity;

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

/**
 * 用户实体
 * @author 
 *
 */
public class User {
    private Integer id; // 编号
    private String username; // 用户名
    private String password; // 密码
    private String truename; // 真实姓名
    private String email; // 邮件
    private String phone; // 电话
    private String address; // 住址
    private Integer sex; // 性别
    private Integer age; // 年龄
    private String appellation; // 家庭称谓
    private Integer salary; // 薪水工资
    private String card; // 银行卡号
    private Integer isvalid; // 是否有效
    private String createtime; // 创建时间
    private String updatetime; // 修改时间

    private Integer roleid; // 角色ID
    private String rolename; // 角色名称
    private List<Map<Object,Object>> roleIDsList=new ArrayList<Map<Object,Object>>(); // 对应的角色列表id

    private String roleIDs=""; // 对应的角色列表id
    private String roleNames=""; // 对应的角色列表名称

    public List<Map<Object, Object>> getRoleIDsList() {
        return roleIDsList;
    }
    public void setRoleIDsList(List<Map<Object, Object>> roleIDsList) {
        this.roleIDsList = roleIDsList;
        if(null!=roleIDsList && roleIDsList.size()>0){
            int size=roleIDsList.size();
            for(int i=0;i<size;i++){
                roleIDs+=roleIDsList.get(i).get("roleid");
                roleNames+=roleIDsList.get(i).get("rolename");
                if(i!=(size-1)){
                    roleIDs+=",";
                    roleNames+=",";
                }
            }
        }
    }

    public Integer getRoleid() {
        return roleid;
    }
    public void setRoleid(Integer roleid) {
        this.roleid = roleid;
    }
    public String getRolename() {
        return rolename;
    }
    public void setRolename(String rolename) {
        this.rolename = rolename;
    }
    public String getRoleIDs() {
        return roleIDs;
    }
    public void setRoleIDs(String roleIDs) {
        this.roleIDs = roleIDs;
    }
    public String getRoleNames() {
        return roleNames;
    }
    public void setRoleNames(String roleNames) {
        this.roleNames = roleNames;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getTruename() {
        return truename;
    }
    public void setTruename(String truename) {
        this.truename = truename;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public Integer getSex() {
        return sex;
    }
    public void setSex(Integer sex) {
        this.sex = sex;
    }
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
    public String getAppellation() {
        return appellation;
    }
    public void setAppellation(String appellation) {
        this.appellation = appellation;
    }
    public Integer getSalary() {
        return salary;
    }
    public void setSalary(Integer salary) {
        this.salary = salary;
    }
    public String getCard() {
        return card;
    }
    public void setCard(String card) {
        this.card = card;
    }
    public Integer getIsvalid() {
        return isvalid;
    }
    public void setIsvalid(Integer isvalid) {
        this.isvalid = isvalid;
    }
    public String getCreatetime() {
        return createtime;
    }
    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }
    public String getUpdatetime() {
        return updatetime;
    }
    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }

}

Dao层:
DatabaseDao.java

package com.finance.dao;

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

import org.apache.ibatis.annotations.Param;

import com.finance.entity.Database;

/**
 * 数据库管理层的dao
 * @author 
 *
 */

public interface DatabaseDao {
    /**
     * 查询数据库备份记录
     * @param map
     * @return
     */
    public List<Database> findDataBack(Map<String,Object> map);

    /**
     * 获取数据库备份记录数
     * @param map
     * @return
     */
    public Long getDataBackTotal(Map<String,Object> map);

    /**
     * 添加数据库操作记录
     * @param user
     * @return
     */
    public int addDatabase(Database database);

    /**
     * 删除数据库操作记录
     * @param id
     * @return
     */
    public int deleteDatabase(Integer id);

    /**
     * 清空数据库
     * @param
     * @return
     */
    public int truncateTable(@Param("tablename") String tablename);

    /**
     * 数据库整理
     * @param
     * @return
     */
    public int deleteOrderdata(@Param("tablename") String tablename,@Param("startid") Integer startid,@Param("endid") Integer endid);
}

DatadictDao.java

package com.finance.dao;

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

import com.finance.entity.Datadic;

/**
 * 数据字典dao层接口
 * @author 
 *
 */
public interface DatadicDao {
    public List<Datadic> getDatadicIncome();

    public List<Datadic> getDatadicPay();

    public List<Datadic> getDatadicSecurity();

    public List<Datadic> getDatadicTrade();

    public List<Datadic> getDatadicname();

    /**
     * 查询数据字典
     * @param map
     * @return
     */
    public List<Datadic> findDatadic(Map<String,Object> map);

    /**
     * 获取数据字典记录数
     * @param map
     * @return
     */
    public Long getTotalDatadic(Map<String,Object> map);

    /**
     * 更新数据字典
     * @param datadic
     * @return
     */
    public int updateDatadic(Datadic datadic);

    /**
     * 添加数据字典
     * @param datadic
     * @return
     */
    public int addDatadic(Datadic datadic);

    /**
     * 删除数据字典
     * @param id
     * @return
     */
    public int deleteDatadic(Integer id);

}

IncomeDao.java

package com.finance.dao;

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

import com.finance.entity.Income;

public interface IncomeDao {

    /**
     * 查询收入
     * @param map
     * @return
     */
    public List<Income> findIncome(Map<String,Object> map);

    /**
     * 报表生成获得收入图表数据
     * @param map
     * @return
     */
    public List<Income> getIncomeLine(Map<String,Object> map);

    /**
     * 获取收入记录数
     * @param map
     * @return
     */
    public Long getTotalIncome(Map<String,Object> map);

    /**
     * 更新收入
     * @param income
     * @return
     */
    public int updateIncome(Income  income);

    /**
     * 添加收入
     * @param income
     * @return
     */
    public int addIncome(Income  income);

    /**
     * 删除收入
     * @param id
     * @return
     */
    public int deleteIncome(Integer id);

    /**
     * 获得所有收入人
     * @return
     */
    public List<Income> getIncomer();

}

Service业务逻辑层:
DatabaseService.java

package com.finance.service;

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

import org.apache.ibatis.annotations.Param;

import com.finance.entity.Database;

/**
 * 数据库管理层的service
 * @author 
 *
 */
public interface DatabaseService {
    /**
     * 查询数据库备份记录
     * @param map
     * @return
     */
    public List<Database> findDataBack(Map<String,Object> map);

    /**
     * 获取数据库备份记录数
     * @param map
     * @return
     */
    public Long getDataBackTotal(Map<String,Object> map);

    /**
     * 添加数据库操作记录
     * @param user
     * @return
     */
    public int addDatabase(Database database);

    /**
     * 删除数据库操作记录
     * @param id
     * @return
     */
    public int deleteDatabase(Integer id);

    /**
     * 清空数据库
     * @param
     * @return
     */
    public int truncateTable(@Param("tablename") String tablename);

    /**
     * 数据库整理
     * @param
     * @return
     */
    public int deleteOrderdata(@Param("tablename") String tablename,@Param("startid") Integer startid,@Param("endid") Integer endid);
}

DatadicService.java

package com.finance.service;

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

import com.finance.entity.Datadic;
/**
 * 数据字典Service接口
 * @author 
 *
 */
public interface DatadicService {
    public List<Datadic> getDatadicIncome();

    public List<Datadic> getDatadicPay();

    public List<Datadic> getDatadicSecurity();

    public List<Datadic> getDatadicname();

    public List<Datadic> getDatadicTrade();

    /**
     * 查询数据字典
     * @param map
     * @return
     */
    public List<Datadic> findDatadic(Map<String,Object> map);

    /**
     * 获取数据字典记录数
     * @param map
     * @return
     */
    public Long getTotalDatadic(Map<String,Object> map);

    /**
     * 更新数据字典
     * @param datadic
     * @return
     */
    public int updateDatadic(Datadic datadic);

    /**
     * 添加数据字典
     * @param datadic
     * @return
     */
    public int addDatadic(Datadic datadic);

    /**
     * 删除数据字典
     * @param id
     * @return
     */
    public int deleteDatadic(Integer id);
}

IncomeService.java

package com.finance.service;

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

import com.finance.entity.Income;

public interface IncomeService {
    /**
     * 查询收入
     * @param map
     * @return
     */
    public List<Income> findIncome(Map<String,Object> map);

    /**
     * 报表生成获得收入图表数据
     * @param map
     * @return
     */
    public List<Income> getIncomeLine(Map<String,Object> map);

    /**
     * 获取收入记录数
     * @param map
     * @return
     */
    public Long getTotalIncome(Map<String,Object> map);

    /**
     * 更新用户
     * @param income
     * @return
     */
    public int updateIncome(Income  income);

    /**
     * 添加收入
     * @param income
     * @return
     */
    public int addIncome(Income  income);

    /**
     * 删除收入
     * @param id
     * @return
     */
    public int deleteIncome(Integer id);

    /**
     * 获得所有收入人
     * @return
     */
    public List<Income> getIncomer();

}

Controller控制层:
DatabaseController.java

package com.finance.controller;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.finance.core.des.DESUtils;
import com.finance.entity.Database;
import com.finance.entity.PageBean;
import com.finance.service.DatabaseService;
import com.finance.util.CurrentConn;
import com.finance.util.DateUtil;
import com.finance.util.ResponseUtil;
import com.finance.util.StringUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 数据库管理的Controller层
 * @author 
 *
 */
@Controller
public class DatabaseController {
    @Resource
    private DatabaseService databaseService;

    private static String username;
    private static String password;

    static{
        Properties prop = new Properties();
        try {
            InputStream is = CurrentConn.class.getResourceAsStream("/db.properties");
            prop.load(is);
            username = DESUtils.getDecryptString(prop.getProperty("username"));
            password = DESUtils.getDecryptString(prop.getProperty("password"));
            is.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * 数据库备份管理页面
     */
    @RequestMapping("/databackManage.do")
    public String databackManage() {
        return "databackManage";
    }

    /**
     * 数据库恢复管理页面
     */
    @RequestMapping("/datarecoverManage.do")
    public String datarecoverManage() {
        return "datarecoverManage";
    }

    /**
     * 数据库整理管理页面
     */
    @RequestMapping("/dataorderManage.do")
    public String dataorderManage() {
        return "dataorderManage";
    }

    /**
     * 数据库初始化管理页面
     */
    @RequestMapping("/datainitManage.do")
    public String datainitManage() {
        return "datainitManage";
    }

    /**
     * 添加数据库操作记录
     * 
     * @return
     * @throws Exception
     */
    private Boolean save(Database database) throws Exception {
        int resultTotal = 0;
        resultTotal = databaseService.addDatabase(database);
        boolean result = false;
        if (resultTotal > 0) { // 执行成功
            result = true;
        }
        return result;
    }

    /**
     * 删除数据库操作记录
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/databasedelete.do")
    public String delete(@RequestParam(value = "ids") String ids, HttpServletResponse response) throws Exception {
        JSONObject result = new JSONObject();
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            databaseService.deleteDatabase(Integer.parseInt(idsStr[i]));
        }
        result.put("errres", true);
        result.put("errmsg", "记录删除成功!");
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 查询数据库备份集合
     * 
     * @param page
     * @param rows
     * @param s_databack
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/databaselist.do")
    public String list(@RequestParam(value = "dataid", required = true) Integer dataid,
            @RequestParam(value = "page", required = false) String page,
            @RequestParam(value = "rows", required = false) String rows, Database s_databack, HttpServletResponse response)
            throws Exception {
        PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("username", StringUtil.formatLike(s_databack.getUsername()));
        map.put("starttime", s_databack.getStarttime());
        map.put("endtime", s_databack.getEndtime());
        map.put("dataid", dataid);
        map.put("start", pageBean.getStart());
        map.put("size", pageBean.getPageSize());
        List<Database> databacklist = databaseService.findDataBack(map);
        Long total = databaseService.getDataBackTotal(map);
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(databacklist);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 数据备份执行
     * 前台传入location以及userid
     * @param databack
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/databack.do")
    public String databack(@RequestParam(value = "location", required = true) String basepath,
            @RequestParam(value = "userid", required = true) Integer userid,
            Database databack, HttpServletResponse response, HttpSession session) {
        JSONObject result = new JSONObject();
        try{
            Runtime rt = Runtime.getRuntime();
            Process child = rt.exec("mysqldump -u" + username + " -p" + password + " ffms t_datadic t_income t_pay t_role t_security t_shares t_trade t_user t_user_role ");// 设置导出编码为utf8。这里必须是utf8
            InputStream in = child.getInputStream();// 控制台的输出信息作为输入流

            InputStreamReader xx = new InputStreamReader(in, "utf8");// 设置输出流编码为utf8。这里必须是utf8,否则从流中读入的是乱码 

            String inStr;
            StringBuffer sb = new StringBuffer("");
            String outStr;
            BufferedReader br = new BufferedReader(xx);
            while ((inStr = br.readLine()) != null) {
                sb.append(inStr + "\r\n");
            }
            outStr = sb.toString();
            String regex = "^[A-z]:\\\\(.+?)";
            String regex1 = "^[A-z]:\\\\";

            if(basepath.equals("")){
                result.put("errres", false);
                result.put("errmsg", "备份路径不能为空!");
            }else if(!basepath.matches(regex)&&!basepath.matches(regex1)) {
                result.put("errres", false);
                result.put("errmsg", "备份路径不正确!");
            }else{ 
                File file = new File(basepath);
                if(file.exists()==false){
                    file.mkdir();
                }

                String filepath = basepath + "\\" + DateUtil.getCurrentDateCustomFormat("yyyyMMddHHmmss") + ".sql";
                File files = new File(filepath);
                if(files.exists()==false){
                    file.createNewFile();
                }
                FileOutputStream fout = new FileOutputStream(filepath);

                OutputStreamWriter writer = new OutputStreamWriter(fout, "utf8");
                writer.write(outStr);      
                writer.flush();      
                in.close();      
                xx.close();      
                br.close();      
                writer.close();      
                fout.close();

                databack.setUserid(userid);
                databack.setFilename(DateUtil.getCurrentDateCustomFormat("yyyyMMddHHmmss")+".sql");
                databack.setTime(DateUtil.getCurrentDateCustomFormat("yyyy-MM-dd HH:mm:ss"));
                databack.setLocation(filepath);
                databack.setDataid(1);

                if (save(databack)) {
                    result.put("errres", true);
                    result.put("errmsg", "数据备份成功!");
                }else{
                    result.put("errres", false);
                    result.put("errmsg", "数据备份失败");
                }

            }
        }catch(Exception e){
            System.out.println("异常");
            e.printStackTrace();
            result.put("errres", false);
            result.put("errmsg", "数据备份失败");
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 数据恢复
     * 前台传入userid,filename,location
     * @param datarecover
     * @param response
     * @param session
     * @return
     */
    @RequestMapping("/datarecover.do")
    public String datarecover(@RequestParam(value = "location", required = true) String location,
            @RequestParam(value = "filename", required = true) String filename,
            @RequestParam(value = "userid", required = true) Integer userid,
            Database datarecover, HttpServletResponse response, HttpSession session) {
        JSONObject result = new JSONObject();
        try{
            Runtime rt = Runtime.getRuntime();
            Process child = rt.exec("mysql -u"+username+" -p"+password+" ffms");

            OutputStream out = child.getOutputStream();// 控制台的输入信息作为输出流
            String inStr;
            StringBuffer sb = new StringBuffer("");
            String outStr;
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(location), "utf-8"));
            while ((inStr = br.readLine()) != null) {
                sb.append(inStr + "\r\n");
            }
            outStr = sb.toString();
            OutputStreamWriter writer = new OutputStreamWriter(out, "utf-8");
            writer.write(outStr);
            writer.flush();
            out.close();
            br.close();
            writer.close();

            datarecover.setUserid(userid);
            datarecover.setFilename(filename);
            datarecover.setTime(DateUtil.getCurrentDateCustomFormat("yyyy-MM-dd HH:mm:ss"));
            datarecover.setLocation(location);
            datarecover.setDataid(2);

            if (save(datarecover)) {
                result.put("errres", true);
                result.put("errmsg", "数据恢复成功!");
            }else{
                result.put("errres", false);
                result.put("errmsg", "数据恢复失败");
            }

        }catch(Exception e){
            System.out.println("异常");
            e.printStackTrace();
            result.put("errres", false);
            result.put("errmsg", "数据恢复失败");
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 清空数据库操作记录
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/datainit.do")
    public String datainit(@RequestParam(value = "userid") Integer userid, Database datainit, HttpServletResponse response) throws Exception {
        JSONObject result = new JSONObject();
        String[] tables = {"t_income","t_pay","t_security","t_shares","t_trade"};
        for (int i = 0; i < tables.length; i++) {
            databaseService.truncateTable(tables[i]);
        }

        datainit.setUserid(userid);
        datainit.setTime(DateUtil.getCurrentDateCustomFormat("yyyy-MM-dd HH:mm:ss"));
        datainit.setDataid(3);

        if (save(datainit)) {
            result.put("errres", true);
            result.put("errmsg", "数据库初始化成功!");
        }else{
            result.put("errres", false);
            result.put("errmsg", "数据库初始化失败");
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 清空数据库操作记录
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/dataorder.do")
    public String dataorder(@RequestParam(value = "userid") Integer userid,
            @RequestParam(value = "tablename") String tablename,
            @RequestParam(value = "startid") Integer startid,
            @RequestParam(value = "endid") Integer endid,
            Database dataorder, HttpServletResponse response) throws Exception {
        int resultTotal = 0;
        JSONObject result = new JSONObject();
        resultTotal = databaseService.deleteOrderdata(tablename,startid,endid);
        if (resultTotal>0) {
            dataorder.setUserid(userid);
            dataorder.setTime(DateUtil.getCurrentDateCustomFormat("yyyy-MM-dd HH:mm:ss"));
            dataorder.setDataid(4);
            dataorder.setLocation("删除【"+tablename+"】表中第" + startid + "条到第" + endid + "条数据");
            if (save(dataorder)) {
                result.put("errres", true);
                result.put("errmsg", "数据整理完成!");
            }else{
                result.put("errres", true);
                result.put("errmsg", "数据整理失败");
            }
        }else{
            result.put("errres", true);
            result.put("errmsg", "所选数据不存在!");
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 打开文件资源管理器
     * @param response
     * @return
     */
    @RequestMapping("/openFileDialog.do")
    public String openFileDialog(HttpServletResponse response){
        JSONObject result = new JSONObject();
        try {
            java.awt.Desktop.getDesktop().open(new java.io.File("D:\\360Downloads\\apache-tomcat-8.0.44\\DBback"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        result.put("errres", true);
        result.put("errmsg", "文件资源管理器打开成功!");
        ResponseUtil.write(response, result);
        return null;
    }

}

DatadicController.java

package com.finance.controller;

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

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.finance.entity.Datadic;
import com.finance.entity.PageBean;
import com.finance.service.DatadicService;
import com.finance.util.ResponseUtil;
import com.finance.util.StringUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 数据字典Controller层
 * 
 * @author 
 *
 */
@Controller
public class DatadicController {

    @Resource
    private DatadicService datadicService;

    /**
     * 数据字典信息页面
     */
    @RequestMapping("/datadicManage.do")
    public String datadicManage(ModelMap map) {
        List<Datadic> list = datadicService.getDatadicname();
        map.addAttribute("datadicnames", list);
        return "datadicManage";
    }

    /**
     * 查询数据字典集合
     * 
     * @param page
     * @param rows
     * @param s_datadic
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/datadiclist.do")
    public String list(@RequestParam(value = "page", required = false) String page,
            @RequestParam(value = "rows", required = false) String rows, Datadic s_datadic, HttpServletResponse response)
            throws Exception {
        PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("datadicname", s_datadic.getDatadicname());
        map.put("datadicvalue", StringUtil.formatLike(s_datadic.getDatadicvalue()));
        map.put("start", pageBean.getStart());
        map.put("size", pageBean.getPageSize());
        List<Datadic> datadicList = datadicService.findDatadic(map);
        Long total = datadicService.getTotalDatadic(map);
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(datadicList);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 添加与修改数据字典
     * 
     * @param datadic
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/datadicsave.do")
    public String save(Datadic datadic, HttpServletResponse response) throws Exception {
        int resultTotal = 0; // 操作的记录条数
        JSONObject result = new JSONObject();
        if (datadic.getId() == null) {
            resultTotal = datadicService.addDatadic(datadic);
        } else {
            resultTotal = datadicService.updateDatadic(datadic);
        }

        if (resultTotal > 0) { // 执行成功
            result.put("errres", true);
            result.put("errmsg", "数据保存成功!");
        } else {
            result.put("errres", false);
            result.put("errmsg", "数据保存失败");
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 删除数据字典
     * 
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/datadicdelete.do")
    public String delete(@RequestParam(value = "ids") String ids, HttpServletResponse response) throws Exception {
        JSONObject result = new JSONObject();
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            datadicService.deleteDatadic(Integer.parseInt(idsStr[i]));
        }
        result.put("errres", true);
        result.put("errmsg", "数据删除成功!");
        ResponseUtil.write(response, result);
        return null;
    }
}

IncomeController.java

package com.finance.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.finance.entity.Datadic;
import com.finance.entity.Income;
import com.finance.entity.PageBean;
import com.finance.entity.User;
import com.finance.service.DatadicService;
import com.finance.service.IncomeService;
import com.finance.service.UserService;
import com.finance.util.Constants;
import com.finance.util.ResponseUtil;
import com.finance.util.StringUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 收入Controller层
 * 
 * @author
 *
 */
@Controller
public class IncomeController {
    @Resource
    private IncomeService incomeService;
    @Resource
    private DatadicService datadicService;
    @Resource
    private UserService userService;

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); // true:允许输入空值,false:不能为空值
    }

    /**
     * 收入信息管理页面
     */
    @RequestMapping("/incomeManage.do")
    public String incomeManage(ModelMap map, HttpServletRequest request) {
        List<Datadic> list = datadicService.getDatadicIncome();
        map.addAttribute("incomes", list);

        HttpSession session = request.getSession();
        User curuser = (User)session.getAttribute(Constants.currentUserSessionKey);
        Map<String, Object> userMap = new HashMap<String, Object>();
        userMap.put("userid", curuser.getId());
        userMap.put("roleid", curuser.getRoleid());
        List<User> userlist = userService.getAllUser(userMap);
        map.addAttribute("allUsers", userlist);
        return "incomeManage";
    }

    /**
     * 查询用户收入集合
     * 
     * @param page
     * @param rows
     * @param s_income
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/incomelist.do")
    public String list(@RequestParam(value = "page", required = false) String page,
            @RequestParam(value = "rows", required = false) String rows, Income s_income, HttpServletResponse response)
            throws Exception {
        PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("incomer", StringUtil.formatLike(s_income.getIncomer()));
        map.put("source", StringUtil.formatLike(s_income.getSource()));
        map.put("dataid", s_income.getDataid());
        map.put("starttime", s_income.getStarttime());
        map.put("endtime", s_income.getEndtime());
        map.put("roleid", s_income.getRoleid());
        map.put("userid", s_income.getUserid());
        map.put("start", pageBean.getStart());
        map.put("size", pageBean.getPageSize());
        List<Income> incomeList = incomeService.findIncome(map);
        Long total = incomeService.getTotalIncome(map);
        JSONObject result = new JSONObject();
        JSONArray jsonArray = JSONArray.fromObject(incomeList);
        result.put("rows", jsonArray);
        result.put("total", total);
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 添加与修改用户
     * 
     * @param income
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/incomesave.do")
    public String save(Income income, HttpServletResponse response) throws Exception {
        int resultTotal = 0; // 操作的记录条数
        JSONObject result = new JSONObject();

        if (income.getId() == null) {
            resultTotal = incomeService.addIncome(income);
        } else {
            resultTotal = incomeService.updateIncome(income);
        }

        if (resultTotal > 0) { // 执行成功
            result.put("errres", true);
            result.put("errmsg", "数据保存成功!");
        } else {
            result.put("errres", false);
            result.put("errmsg", "数据保存失败");
        }
        ResponseUtil.write(response, result);
        return null;
    }

    /**
     * 删除用户
     * 
     * @param ids
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/incomedelete.do")
    public String delete(@RequestParam(value = "ids") String ids, HttpServletResponse response) throws Exception {
        JSONObject result = new JSONObject();
        String[] idsStr = ids.split(",");
        for (int i = 0; i < idsStr.length; i++) {
            incomeService.deleteIncome(Integer.parseInt(idsStr[i]));
        }
        result.put("errres", true);
        result.put("errmsg", "数据删除成功!");
        ResponseUtil.write(response, result);
        return null;
    }

}

Session过滤器:
SessionFilter.java

package com.finance.filter;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.filter.OncePerRequestFilter;

import com.finance.entity.User;
import com.finance.util.Constants;

public class SessionFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
        // 不过滤的uri
        String[] notFilter = new String[] { "/sign.do","/index.do","/gosign.do","/login.do"};
        // 请求的uri
        String uri = request.getRequestURI();

        if(uri.indexOf(".do") == -1 && uri.indexOf(".jsp") == -1 ){
            //如果请求的资源不是.htm和.jsp则直接放行,不验证是否登录
            filterChain.doFilter(request, response);
            return;
        }     
        boolean doFilter = true;
        for (String s : notFilter) { 
            if (uri.indexOf(s) != -1) {
                 doFilter = false;
                break;
            }
        }
        if(doFilter==false){
            //针对特殊资源直接放行,不验证是否登录
            filterChain.doFilter(request, response);
            return;
        }
        User user=(User)request.getSession().getAttribute(Constants.currentUserSessionKey);
        String loginPage ="";
        if (null == user) {
            if(request.getServerPort()==80){
                loginPage=request.getScheme()+"://"+request.getServerName()+request.getContextPath()+"/index.do";
            }else{
                loginPage=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/index.do";
            }
            //loginPage = "http://"+request.getServerName()+request.getContextPath()+"/login.jsp"; 
            // 如果session中不存在登录者实体,则弹出框提示重新登录
            // 设置request和response的字符集,防止乱码
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            PrintWriter out = response.getWriter();
            StringBuilder builder = new StringBuilder();  
            builder.append("<!doctype html><html><head><meta charset=\"UTF-8\"><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /><meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\"/>"); 
            builder.append("<script type=\"text/javascript\">");  
            builder.append("alert('未登录,请登录后操作!');");  
            builder.append("window.top.location.href='");  
            builder.append(loginPage);  
            builder.append("';");  
            builder.append("</script>");  
            builder.append("</html>");
            out.print(builder.toString());
    }else{
        filterChain.doFilter(request, response);
    }
 }
}

工具类
base64Util.java

package com.finance.util;

import java.io.UnsupportedEncodingException;

public class Base64Util {

    public static void main(String[] args) {
        String ec = Base64Util.encode("123456", "UTF-8");
        System.out.println(ec);
        String dc = Base64Util.decodeStr(ec, "UTF-8");
        System.out.println(dc);

    }

    /**
     * 编码
     * 
     * @param bstr
     * @return String
     */
    public static String encode(byte[] bstr) {
        return new sun.misc.BASE64Encoder().encode(bstr);
    }

    /**
     * 编码
     * 
     * @param str
     * @return String
     */
    public static String encode(String str) {
        return encode(str.getBytes());
    }

    /**
     * 编码
     * 
     * @param str
     * @return String
     */
    public static String encode(String str, String charset) {
        String rs = "";
        try {
            rs = encode(str.getBytes(charset));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return rs;
    }

    /**
     * 解码
     * 
     * @param str
     * @return string
     */
    public static String decodeStr(String str) {
        byte[] bt = null;
        try {
            sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
            bt = decoder.decodeBuffer(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new String(bt);
    }

    /**
     * 解码
     * 
     * @param str
     * @return string
     */
    public static String decodeStr(String str, String charset) {
        String rs = "";
        try {
            sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
            byte[] bt = decoder.decodeBuffer(str);
            rs = new String(bt, charset);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rs;

    }

    /**
     * 解码
     * 
     * @param str
     * @return string
     */
    public static byte[] decode(String str) {
        byte[] bt = null;
        try {
            sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
            bt = decoder.decodeBuffer(str);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return bt;
    }

}

MD5Util.java


package com.finance.util;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {

    private static final String staticSalt = "ffms";

    public static void main(String[] args) {
        System.out.println("xx=" + MD5Util.encodePwd("123456"));
        System.out.println("yy=" + MD5Util.isPwdRight("123456", "cb323f94f7575f0c5cee65521507e1da"));
    }

    /**
     * 根据用户id和用户输入的原始密码,进行MD5加密
     * @param userId
     * @param userPwd
     * @return 加密后的字符串
     */
    public static String encodePwd(String userPwd) {
        return DigestUtils.md5Hex(userPwd + staticSalt);
    }

    /**
     * 判断用户输入的密码是否正确
     * @param userId:用户id
     * @param userPwd:当前输入的密码
     * @param dbPwd:数据库中存储的密码
     * @return true:输入正确 false:输入错误
     */
    public static boolean isPwdRight(String userPwd, String dbPwd) {
        boolean rs = false;
        if (encodePwd(userPwd).equals(dbPwd)) {
            rs = true;
        }
        return rs;
    }

}

如果角色有用,别忘了一键三连哈!