Browse Source

上传文件至 'code/springboot/newBank/src/main/java/demo/liaofeifei'

master
liaofeifei 10 hours ago
parent
commit
126f9af669
  1. 72
      code/springboot/newBank/src/main/java/demo/liaofeifei/login.java
  2. 19
      code/springboot/newBank/src/main/java/demo/liaofeifei/register.java
  3. 131
      code/springboot/newBank/src/main/java/demo/liaofeifei/staffController.java

72
code/springboot/newBank/src/main/java/demo/liaofeifei/login.java

@ -2,10 +2,10 @@ package demo.liaofeifei;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -26,9 +26,6 @@ public class login {
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql); List<Map<String,Object>> list=jdbcTemplate.queryForList(sql);
List<Map<String,Object>> list_zt=jdbcTemplate.queryForList(sql_zt); List<Map<String,Object>> list_zt=jdbcTemplate.queryForList(sql_zt);
if(list_zt.isEmpty()){
return "0";
}
String re= (String) list_zt.get(0).get("cancel"); String re= (String) list_zt.get(0).get("cancel");
String result=""; String result="";
@ -59,69 +56,4 @@ public class login {
return result; return result;
} }
@PostMapping("/userlogin")
public Map<String, Object> userlogin(@RequestBody HashMap<String, Object> params) {
HashMap<String, Object> hashMap = new HashMap<>();
String username = (String) params.get("username");
String password = (String) params.get("password");
if (username == null || password == null){
hashMap.put("code", 500);
hashMap.put("msg", "用户名或密码不能为空");
return hashMap;
}
String sql = "SELECT userNo, userName, tel, addr,gender FROM user_info WHERE userNo = ? AND passwd = ?";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, username, password);
if (list == null || list.size() == 0) { // 查询不到用户返回空Map
hashMap.put("code", 500);
hashMap.put("msg", "用户名或密码错误");
return new HashMap<>();
} else {
hashMap.put("code", 200);
hashMap.put("msg", "登录成功");
hashMap.put("data", list.get(0));
return hashMap; // 返回用户信息,不包含密码
}
}
@PostMapping("/userRegister")
public Map<String, Object> userRegister(@RequestBody HashMap<String, Object> params) {
HashMap<String, Object> hashMap = new HashMap<>();
String username = (String) params.get("username");
String password = (String) params.get("password");
if (username == null || password == null) {
hashMap.put("code", 500);
hashMap.put("msg", "用户名或密码不能为空");
return hashMap;
}
// 检查用户名是否已经存在
String checkSql = "SELECT COUNT(*) FROM user_info WHERE userNo = ?";
Integer count = jdbcTemplate.queryForObject(checkSql, new Object[]{username}, Integer.class);
if (count != null && count > 0) {
hashMap.put("code", 500);
hashMap.put("msg", "用户名已存在");
return hashMap;
}
// 进行注册
String insertSql = "INSERT INTO user_info (userNo, passwd) VALUES (?, ?)";
int rowsAffected = jdbcTemplate.update(insertSql, username, password);
if (rowsAffected > 0) {
hashMap.put("code", 200);
hashMap.put("msg", "注册成功");
} else {
hashMap.put("code", 500);
hashMap.put("msg", "注册失败");
}
return hashMap;
}
} }

19
code/springboot/newBank/src/main/java/demo/liaofeifei/register.java

@ -22,7 +22,7 @@ public class register {
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@RequestMapping("/staffregister") @RequestMapping("/staffregister")
public Object getAllNewTableData1(HttpServletRequest request) { public String getAllNewTableData1(HttpServletRequest request) {
// String staffNo=request.getParameter("staffNo"); // String staffNo=request.getParameter("staffNo");
// String password=request.getParameter("password");//前端送过来的密码 // String password=request.getParameter("password");//前端送过来的密码
@ -51,6 +51,9 @@ public class register {
String password=request.getParameter("password"); String password=request.getParameter("password");
String cancel=request.getParameter("cancel"); String cancel=request.getParameter("cancel");
// 新增字段问题及答案
String question=request.getParameter("question");
String answer=request.getParameter("answer");
String result = ""; String result = "";
String staffNo = "";//定义工号变量用于获取数据库中最大的工号同时也是注册时插入表中的工号变量 String staffNo = "";//定义工号变量用于获取数据库中最大的工号同时也是注册时插入表中的工号变量
@ -69,7 +72,7 @@ public class register {
if(list1.size() > 0)//判断上面sql语句的查询结果,是否存在(数据库是否存在有与浏览器输入的ID一样的结果,有则list1.size()大于0) if(list1.size() > 0)//判断上面sql语句的查询结果,是否存在(数据库是否存在有与浏览器输入的ID一样的结果,有则list1.size()大于0)
{ {
result="0";//查询到相同身份证不允许注册,返回0 result="0同身份证";//查询到相同身份证不允许注册,返回0
} }
else else
{ {
@ -90,21 +93,21 @@ public class register {
DecimalFormat df = new DecimalFormat("000"); // 创建一个DecimalFormat对象,模式为000 DecimalFormat df = new DecimalFormat("000"); // 创建一个DecimalFormat对象,模式为000
staffNo = df.format(staffNo1);//将整形型的staffN1,规范化并转化为String字符串型 staffNo = df.format(staffNo1);//将整形型的staffN1,规范化并转化为String字符串型
String sql3 = "INSERT INTO staff(staffNo,staffName,gender,birthday,ID,department,job,company,entryTime,contract,education,major,marriage,place,nation,politicalStatus,phone,address,password,cancel) " + String sql3 = "INSERT INTO staff(staffNo,staffName,gender,birthday,ID,department,job,company,entryTime,contract,education,major,marriage,place,nation,politicalStatus,phone,address,password,cancel,question,answer) " +
"VALUES('"+staffNo+"','"+staffName+"','"+gender+"','"+birthday+"','"+ID+"','"+department+"','"+job+"','"+company+"','"+entryTime+"','"+contract+"','"+education+"','"+major+"','"+marriage+"','"+place+"','"+nation+"','"+politicalStatus+"','"+phone+"','"+address+"','"+password+"','"+cancel+"');"; "VALUES('"+staffNo+"','"+staffName+"','"+gender+"','"+birthday+"','"+ID+"','"+department+"','"+job+"','"+company+"','"+entryTime+"','"+contract+"','"+education+"','"+major+"','"+marriage+"','"+place+"','"+nation+"','"+politicalStatus+"','"+phone+"','"+address+"','"+password+"','"+cancel+"','"+question+"','"+answer+"');";
System.out.println("注册语句: " + sql3);
int i= jdbcTemplate.update(sql3);//执行 int i= jdbcTemplate.update(sql3);//执行
//判断是否注册成功 //判断是否注册成功
if (i> 0) if (i> 0)
{ {
//System.out.println("注册成功!");//数据插入成功! //System.out.println("注册成功!");//数据插入成功!
result = staffNo; result = "1";
} else } else
{ {
//System.out.println("注册失败!");//数据插入失败! //System.out.println("注册失败!");//数据插入失败!
result = "0"; result = "0语句失败";
} }
} }
@ -112,7 +115,7 @@ public class register {
//若身份证留空则注册失败 //若身份证留空则注册失败
else else
{ {
result="0";//身份证留空,注册失败,返回0 result="0身份证空";//身份证留空,注册失败,返回0
} }

131
code/springboot/newBank/src/main/java/demo/liaofeifei/staffController.java

@ -2,12 +2,12 @@ package demo.liaofeifei;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat; import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
//import java.util.list; //import java.util.list;
import java.util.Map; import java.util.Map;
@ -20,14 +20,9 @@ public class staffController{
@RequestMapping("/qryStaff") @RequestMapping("/qryStaff")
public List<Map<String,Object>> QryStaff(HttpServletRequest request){ public List<Map<String,Object>> QryStaff(HttpServletRequest request){
String staffNo=request.getParameter("staffNo");
String sql="select * from staff s where staffNo ='"+staffNo+"'";
String staffNo=request.getParameter("staffNo");//员工号
if (staffNo == null) {
staffNo = ""; // 如果 ins_id 为 null,则使用空字符串
}
String sql = "select * from staff where staffNo like '%" + staffNo + "%'";// 编辑查询数据库语句
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql); List<Map<String,Object>> list=jdbcTemplate.queryForList(sql);
@ -36,71 +31,81 @@ public class staffController{
return list; return list;
} }
@RequestMapping("/addStaff") @RequestMapping("/addStaffwww")
public int addStaff(HttpServletRequest request){ public int addStaff(HttpServletRequest request){
String staffNo = request.getParameter("staffNo"); String staffNo=request.getParameter("staffNo");
String staffName = request.getParameter("staffName"); String staffName=request.getParameter("staffName");
String gender = request.getParameter("gender"); String gender=request.getParameter("gender");
String birthday = request.getParameter("birthday"); String birthday=request.getParameter("birthday");
String ID=request.getParameter("ID");
String department = request.getParameter("department"); String department=request.getParameter("department");
String position = request.getParameter("position"); String job=request.getParameter("job");
String company = request.getParameter("company"); String company=request.getParameter("company");
String contractType = request.getParameter("contractType"); //String entryTime=request.getParameter("entryTime");
String phone = request.getParameter("phone");
String password = request.getParameter("password"); java.util.Date date = new Date();
String address = request.getParameter("address"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//获取系统时间
String entryTime=sdf.format(date);//赋值
int staffNo1 =1;//新工号的初始值默认为1,防止出现数据库没有员工数据的情况出现 String contract=request.getParameter("contract");
String sql2 = "SELECT staffNo from staff ORDER BY staffNo DESC LIMIT 1";//查看最后一条工号 String education=request.getParameter("education");
String major=request.getParameter("major");
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql2); String marriage=request.getParameter("marriage");
if(list.size()>0 && list.get(0).get("staffNo")!=null)//对获取到的数据库工号进行判断,list.size()>0,则说明数据库有工号数据,则将数据库最后一条记录的工号的值加1作为新工号的值,若数据库查询不到数据,则不执行下面if语句,默认使用上面int staffNo1 =1;的值 String place=request.getParameter("place");
{ String nation=request.getParameter("nation");
staffNo = (String) list.get(0).get("staffNo");//获取工号 String politicalStatus=request.getParameter("politicalStatus");
staffNo1 = Integer.parseInt(staffNo) + 1;//将工号转化为int型,便于+ String phone=request.getParameter("phone");
String address=request.getParameter("address");
//定义一个规则用来规范工号的位数为三位 String password=request.getParameter("password");
DecimalFormat df = new DecimalFormat("000"); // 创建一个DecimalFormat对象,模式为000 String cancel=request.getParameter("cancel");
staffNo = df.format(staffNo1);//将整形型的staffN1,规范化并转化为String字符串型
} // String sql="INSERT INTO staff (staffNo,staffName,gender,birthday) VALUES"+
// "('"+staffNo+"','"+staffName+"','"+gender+"','"+birthday+"')";
String sql = "INSERT INTO staff(staffNo,staffName,gender,birthday,ID,department,job,company,entryTime,contract,education,major,marriage,place,nation,politicalStatus,phone,address,password,cancel) " +
"VALUES('"+staffNo+"','"+staffName+"','"+gender+"','"+birthday+"','"+ID+"','"+department+"','"+job+"','"+company+"','"+entryTime+"','"+contract+"','"+education+"','"+major+"','"+marriage+"','"+place+"','"+nation+"','"+politicalStatus+"','"+phone+"','"+address+"','"+password+"','"+cancel+"');";
String sql = "INSERT INTO staff (staffNo, staffName, gender, birthday, department, job, company, contract, phone, password,address) " + int i=jdbcTemplate.update(sql);
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
int i = jdbcTemplate.update(sql, staffNo, staffName, gender, birthday, department, position, company, contractType, phone, password,address);
return i; return i;
} }
@RequestMapping("/updateStaff") @RequestMapping("/updateStaff")
public int updateStaff(HttpServletRequest request){ public int updateStaff(HttpServletRequest request){
String staffNo = request.getParameter("staffNo"); String staffNo=request.getParameter("staffNo");
String staffName = request.getParameter("staffName"); String staffName=request.getParameter("staffName");
String gender = request.getParameter("gender"); String gender=request.getParameter("gender");
String birthday = request.getParameter("birthday"); String birthday=request.getParameter("birthday");
String department = request.getParameter("department"); String ID=request.getParameter("ID");
String position = request.getParameter("position"); String department=request.getParameter("department");
String company = request.getParameter("company"); String job=request.getParameter("job");
String contractType = request.getParameter("contract"); String company=request.getParameter("company");
String education = request.getParameter("education"); //String entryTime=request.getParameter("entryTime");
String major = request.getParameter("major");
String marriage = request.getParameter("marriage"); java.util.Date date = new Date();
String place = request.getParameter("place"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//获取系统时间
String nation = request.getParameter("nation"); String entryTime=sdf.format(date);//赋值
String politicalStatus = request.getParameter("politicalStatus");
String phone = request.getParameter("phone"); String contract=request.getParameter("contract");
String address = request.getParameter("address"); String education=request.getParameter("education");
String idCard = request.getParameter("ID"); String major=request.getParameter("major");
String marriage=request.getParameter("marriage");
String sql = "UPDATE staff SET staffName=?, gender=?, birthday=?, department=?, job=?, company=?, contract=?, education=?, major=?, marriage=?, place=?, nation=?, politicalStatus=?, phone=?, address=?, ID=? WHERE staffNo=?"; String place=request.getParameter("place");
int i = jdbcTemplate.update(sql, staffName, gender, birthday, department, position, company, contractType, education, major, marriage, place, nation, politicalStatus, phone, address, idCard, staffNo); String nation=request.getParameter("nation");
String politicalStatus=request.getParameter("politicalStatus");
String phone=request.getParameter("phone");
String address=request.getParameter("address");
String password=request.getParameter("password");
String cancel=request.getParameter("cancel");
// String sql="UPDATE staff set staffName='"+staffName+"',gender='"+gender+"',"+
// "birthday='"+birthday+"'where staffNo='"+staffNo+"'";
String sql="UPDATE staf SETstaffName = '"+staffName+"',gender = '"+gender+"',birthday = '"+birthday+"',ID = '"+ID+"',department = '"+department+"',job = '"+job+"',company = '"+company+"',entryTime = '"+entryTime+"',contract = '"+contract+"',education = '"+education+"',major = '"+major+"',marriage = '"+marriage+"',place = '"+place+"',nation = '"+nation+"',politicalStatus = '"+politicalStatus+"',phone = '"+phone+"',address = '"+address+"',password = '"+password+"',cancel = '"+cancel+"' WHERE staffNo = '"+staffNo+"';";
int i=jdbcTemplate.update(sql);
return i; return i;
} }
@RequestMapping("/delStaff") @RequestMapping("/delStaff")
public int delStaff(HttpServletRequest request) { public int delStaff(HttpServletRequest request) {
String staffNo = request.getParameter("staffNo"); String staffNo = request.getParameter("staffNo");

Loading…
Cancel
Save