今日思考,完成一个工资管理系统项目,需要实现哪些功能?
此类项目常见描述如下:
随着经济的发展,企业正向着大型化、规模化发展,而对于大中型企业,员工、职称等跟工资管理有关的信息随之急剧增加。在这种情况下单靠人工来处理员工的工资不但显得力不从心,而且极容易出错。如何设计一个小型企业工资的数据库管理系统,由计算机代替人工执行一系列诸如增加新员工,删除旧员工,工资查询,统计等操作。这样就使办公人员可以轻松快捷地完成工资管理的任务。
SSM(MYECLIPSE)框架及其适合本类项目,使用MVC的思想可以极大程度减少重复工作量。和SSM(MYECLIPSE)框架最配的开发工具是MYECLIPSE。MYECLIPSE集成了大量插件,可以更好的使用SSM(MYECLIPSE)进行项目的开发,使得项目开发时事半功倍。
通过对工资管理系统系统的仔细分析,可以得出工资管理系统系统是一个 后台项目。
在这样一个项目中,系统的登录角色是必不可少的,对每个登录角色设置账号、密码。以确保系统可以正常登录使用。SSM(MYECLIPSE)项目中包含的登录角色有管理员、用户。
总结得出该系统所有数据为:管理员(admin)、用户(yonghu)、员工增加(yuangongzengjia)、工资清单(gongziqingdan)
管理员表
字段名 | 类型 | 属性 |描述
id| INT(11) | PRIMARY KEY |管理员id
username| VARCHAR(255) | |账号
password| VARCHAR(255) | | 密码
用户表
字段名 | 类型 | 属性 |描述
id| INT(11) | PRIMARY KEY |用户id
xingming| VARCHAR(255) | |姓名
zhiwu| VARCHAR(255) | |职务
nianling| VARCHAR(255) | |年龄
xingbie| VARCHAR(255) | |性别
quanxian| VARCHAR(255) | |权限
username| VARCHAR(255) | |账号
password| VARCHAR(255) | | 密码
员工增加表
字段名 | 类型 | 属性 |描述
id| INT(11) | PRIMARY KEY |员工增加id
xingming| VARCHAR(255) | |姓名
nianling| VARCHAR(255) | |年龄
xingbie| VARCHAR(255) | |性别
xueli| VARCHAR(255) | | 学历
工资清单表
字段名 | 类型 | 属性 |描述
id| INT(11) | PRIMARY KEY |工资清单id
jibengongzi| VARCHAR(255) | |基本工资
yejiticheng| VARCHAR(255) | |业绩提成
jiangligongzi| VARCHAR(255) | | 奖励工资
package org.mypro.front;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.jms.Session;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mypro.dao.GongziqingdanMapper;
import org.mypro.entity.Gongziqingdan;
import org.mypro.entity.GongziqingdanExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;@Controller
@RequestMapping(VALUE = "/")publicclass GongziqingdanController {
private static finalLog logger =LogFactory.getLog(GongziqingdanController.class);@Autowiredprivate GongziqingdanMapper gongziqingdandao;//定义方法tianjiagongziqingdan,响应页面tianjiagongziqingdan请求@RequestMapping(VALUE ="tianjiagongziqingdan")publicString tianjiagongziqingdan(HttpServletRequest request, HttpServletResponse response,HttpSession SESSION,String backurl) {
logger.debug("GongziqingdanController.tianjiagongziqingdan ......");IF(backurl != NULL && backurl.indexOf("tianjiagongziqingdan.action") == -1){RETURN "forward:/" +backurl; }RETURN"tianjiagongziqingdan";
}@RequestMapping(VALUE ="tianjiagongziqingdanact")publicString tianjiagongziqingdanact(HttpServletRequest request,HttpSession SESSION, HttpServletResponse response,Gongziqingdan gongziqingdan,String backurl) throws IOException {
logger.debug("GongziqingdanController.tianjiagongziqingdanact ......");
gongziqingdandao.insert(gongziqingdan);
request.setAttribute("message", "添加工资清单成功");IF(backurl != NULL && backurl.indexOf("tianjiagongziqingdanact.action") == -1){RETURN "forward:/" +backurl; }//返回tianjiagongziqingdan方法RETURN "forward:/tianjiagongziqingdan.action";
}//定义gongziqingdanguanli方法响应页面请求@RequestMapping(VALUE ="gongziqingdanguanli")publicString gongziqingdanguanli(HttpServletRequest request,HttpSession SESSION, HttpServletResponse response,String backurl) {
logger.debug("GongziqingdanController.gongziqingdanguanli ......");
GongziqingdanExample example=NEW GongziqingdanExample();
List gongziqingdanall=gongziqingdandao.selectByExample(example);
request.setAttribute("gongziqingdanall", gongziqingdanall);IF(backurl != NULL && backurl.indexOf("gongziqingdanguanli.action") == -1){RETURN "forward:/" +backurl; }RETURN"gongziqingdanguanli";
}//定义 gongziqingdanchakan方法@RequestMapping(VALUE ="gongziqingdanchakan")publicString gongziqingdanchakan(HttpServletRequest request,HttpSession SESSION, HttpServletResponse response,String backurl) {
logger.debug("GongziqingdanController.gongziqingdanchakan ......");
GongziqingdanExample example=NEW GongziqingdanExample();
List gongziqingdanall=gongziqingdandao.selectByExample(example);
request.setAttribute("gongziqingdanall", gongziqingdanall);IF(backurl != NULL && backurl.indexOf("gongziqingdanchakan.action") == -1){RETURN "forward:/" +backurl; }RETURN"gongziqingdanchakan";
}//定义 xiugaigongziqingdan方法@RequestMapping(VALUE ="xiugaigongziqingdan")public String xiugaigongziqingdan(HttpServletRequest request, HttpServletResponse response,HttpSession SESSION,INTid,String backurl){
logger.debug("GongziqingdanController.xiugaigongziqingdan ......");
Gongziqingdan gongziqingdan=gongziqingdandao.selectByPrimaryKey(id);
request.setAttribute("gongziqingdan", gongziqingdan);IF(backurl != NULL && backurl.indexOf("xiugaigongziqingdan.action") == -1){RETURN "forward:/" +backurl; }RETURN"xiugaigongziqingdan";
}//定义xiugaigongziqingdanact处理工资清单修改@RequestMapping(VALUE ="xiugaigongziqingdanact")publicString xiugaigongziqingdanact(HttpServletRequest request, HttpServletResponse response,Gongziqingdan gongziqingdan,HttpSession SESSION,String backurl) throws IOException {
logger.debug("GongziqingdanController.xiugaigongziqingdanact ......");
gongziqingdandao.updateByPrimaryKeySelective(gongziqingdan);
request.setAttribute("message", "修改工资清单信息成功");IF(backurl != NULL && backurl.indexOf("xiugaigongziqingdanact.action") == -1){RETURN "forward:/" +backurl; }RETURN "forward:/gongziqingdanguanli.action";
}//定义shanchugongziqingdan,处理删除工资清单@RequestMapping(VALUE ="shanchugongziqingdan")public String shanchugongziqingdan(HttpServletRequest request, HttpServletResponse response,HttpSession SESSION,INTid,String backurl){
logger.debug("GongziqingdanController.shanchugongziqingdan ......");
gongziqingdandao.deleteByPrimaryKey(id);
request.setAttribute("message", "删除工资清单成功");IF(backurl != NULL && backurl.indexOf("shanchugongziqingdan.action") == -1){RETURN "forward:/" +backurl; }RETURN "forward:/gongziqingdanguanli.action";
}//定义sousuogongziqingdan方法,处理搜索操作@RequestMapping(VALUE ="sousuogongziqingdan")publicString sousuogongziqingdan(HttpServletRequest request, HttpServletResponse response,HttpSession SESSION,String SEARCH,String backurl) {
logger.debug("GongziqingdanController.sousuogongziqingdan ......");
GongziqingdanExample example=NEW GongziqingdanExample();
GongziqingdanExample.Criteria criteria=example.createCriteria();IF(SEARCH != NULL){
criteria.andJibengongziLike("%" + SEARCH + "%");
}
List gongziqingdanall=gongziqingdandao.selectByExample(example);
request.setAttribute("gongziqingdanall", gongziqingdanall);IF(backurl != NULL && backurl.indexOf("sousuogongziqingdan.action") == -1){RETURN "forward:/" +backurl; }RETURN"sousuogongziqingdan";
}//定义GongziqingdanpinglunMapper@RequestMapping(VALUE ="gongziqingdanxiangqing")public String gongziqingdanxiangqing(HttpServletRequest request,HttpSession SESSION, HttpServletResponse response,INTid,String backurl) {
logger.debug("GongziqingdanController.gongziqingdanxiangqing ......");
Gongziqingdan gongziqingdan=gongziqingdandao.selectByPrimaryKey(id);request
.setAttribute("gongziqingdan", gongziqingdan);IF(backurl != NULL && backurl.indexOf("gongziqingdanxiangqing.action") == -1){RETURN "forward:/" +backurl; }RETURN"gongziqingdanxiangqing";
}//上传文件图片等public String uploadUtile
(MultipartFilefile, HttpServletRequest request) throws IOException {//根据当前时间生成时间字符串SimpleDateFormat sdf=NEW SimpleDateFormat("yyyyMMddHHmmssSS");String res=sdf.format(NEW DATE());//uploads文件夹位置String rootPath= request.getSession().getServletContext().getRealPath("resource/uploads/");//原始名称String originalFileName= file.getOriginalFilename();//新文件名String newFileName= "sliver" + res + originalFileName.substring(originalFileName.lastIndexOf("."));//创建年月文件夹Calendar
DATE= Calendar.getInstance();FiledateDirs= NEW File(DATE.get(Calendar.YEAR) + File.separator + (DATE.get(Calendar.MONTH)+1));//新文件File newFile= NEW File(rootPath + File.separator + dateDirs + File.separator +newFileName);//判断目标文件所在目录是否存在IF( !newFile.getParentFile().exists()) {//如果目标文件所在的目录不存在,则创建父目录newFile
.getParentFile().mkdirs();
}System
.out.println(newFile);//将内存中的数据写入磁盘file
.transferTo(newFile);//完整的urlString fileUrl= DATE.get(Calendar.YEAR) + "/" + (DATE.get(Calendar.MONTH)+1) + "/" +newFileName;RETURNfileUrl;
}}
添加工资清单模块:
在gongziqingdanController中定义tianjiagongziqingdanact接收页面传入的工资清单参数,定义为gongziqingdan。其中gongziqingdan包含字段:基本工资,业绩提成,奖励工资,使用tianjiagongziqingdanact将该工资清单对象存入数据库中,在gongziqingdanMapper中定义了insert方法,匹配数据库中的insert into gongziqingdan语句实现将工资清单数据存入数据库的操作。该部分核心代码如下:
通过gongziqingdandao的insert方法将页面传输的工资清单添加到数据库中 gongziqingdandao.insert(gongziqingdan);
将添加工资清单成功信息,保存到request的message中,在页面中给出用户提示 request.setAttribute("message", "添加工资清单成功");
返回工资清单管理界面
return "forward:/tianjiagongziqingdan.action";
查询工资清单模块:
在后台gongziqingdanguanli方法中,通过selectByexample方法获取所有的数据信息。将其保存到request中,在页面中通过foreach方法
进行循环展示到table中。完成工资清单查询操作。具体代码如下:
生成工资清单样例类,通过example定义查询条件 GongziqingdanExample example = new GongziqingdanExample();
通过gongziqingdandao的selectByExample方法查询出所有的工资清单信息 List gongziqingdanall = gongziqingdandao.selectByExample(example);
将工资清单信息,保存到request中,在页面通过foreach方法进行展示 request.setAttribute("gongziqingdanall", gongziqingdanall);
返回工资清单管理界面
return "forward:/gongziqingdanguanli.action";
修改工资清单模块:
点击修改按钮,可以跳转到工资清单修改页面。在工资清单修改页面中,将初始化该工资清单的所有信息,并将信息一一对应填充到对应编辑栏中。编辑完工资清单信息后,页面通过post方法将数据封装为一个工资清单实体,传入到gongziqingdanController中。在xiugaigongziqingdan中进行接收,接收完毕后,调用gongziqingdanMapper中的updateByPrimaryKeySelective方法进行修改。该部分代码如下:
通过gongziqingdandao的修改方法根据id修改对应的工资清单 gongziqingdandao.updateByPrimaryKeySelective(gongziqingdan);
将修改工资清单成功信息,保存到request的message中,在页面中给出用户提示 request.setAttribute("message", "修改工资清单信息成功");
返回工资清单管理界面
return "forward:/gongziqingdanguanli.action";
删除工资清单模块:
在页面中通过a标签,shanchugongziqingdan?id=将id传入到后台中,通过shanchugongziqingdan接收工资清单id。使用deleteByid的方法
删除该工资清单,完成删除操作。定义删除成功提示信息,删除工资清单成功,并保存到request中,该部分代码如下:
通过gongziqingdandao的删除方法根据id删除对应的工资清单 gongziqingdandao.deleteByPrimaryKey(id);
将删除工资清单成功信息,保存到request的message中,在页面中给出用户提示 request.setAttribute("message", "删除工资清单成功");
返回工资清单管理界面
return "forward:/gongziqingdanguanli.action";