diff --git a/code/springboot/newBank/src/main/java/demo/liaofeifei/register.java b/code/springboot/newBank/src/main/java/demo/liaofeifei/register.java new file mode 100644 index 000000000..205a67159 --- /dev/null +++ b/code/springboot/newBank/src/main/java/demo/liaofeifei/register.java @@ -0,0 +1,109 @@ +//package demo.pengbaohao.controller; + +//public class register { +//} +package demo.pengbaohao.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.text.DecimalFormat; +import java.util.List; +import java.util.Map; + +@RestController +public class register { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @RequestMapping("/staffregister") + public String getAllNewTableData1(HttpServletRequest request) { + // String staffNo=request.getParameter("staffNo"); + // String password=request.getParameter("password");//前端送过来的密码 + + String staffName=request.getParameter("staffName"); + String gender=request.getParameter("gender"); + String birthday=request.getParameter("birthday"); + String ID=request.getParameter("ID"); + String department=request.getParameter("department"); + String job=request.getParameter("job"); + String company=request.getParameter("company"); + String entryTime=request.getParameter("entryTime"); + String contract=request.getParameter("contract"); + String education=request.getParameter("education"); + String major=request.getParameter("major"); + String marriage=request.getParameter("marriage"); + String place=request.getParameter("place"); + 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 result=""; + + String sql2 = "SELECT staffNo from staff ORDER BY staffNo DESC LIMIT 1";//查看最后一条工号 + List> list= jdbcTemplate.queryForList(sql2);//sql执行 + + String staffNo = (String) list.get(0).get("staffNo");//获取工号 + int staffNo1 = Integer.parseInt(staffNo);//将工号转化为int型,便于+1 + staffNo1=staffNo1+1; + + //定义一个规则用来规范工号的位数为三位 + DecimalFormat df = new DecimalFormat("000"); // 创建一个DecimalFormat对象,模式为000 + 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) " + + "VALUES('"+staffNo+"','"+staffName+"','"+gender+"','"+birthday+"','"+ID+"','"+department+"','"+job+"','"+company+"','"+entryTime+"','"+contract+"','"+education+"','"+major+"','"+marriage+"','"+place+"','"+nation+"','"+politicalStatus+"','"+phone+"','"+address+"','"+password+"');"; + + + + //通过身份证判断这个人是否已经注册 + if (ID!=null)//判断浏览器输入的ID不为空 + { + String sql1 ="SELECT ID from staff WHERE ID='"+ID+"'";//拿输入的ID去对比表中的ID + List> list1=jdbcTemplate.queryForList(sql1); + + if(list1.size() > 0)//判断上面sql语句的查询结果,是否存在(数据库是否存在有与浏览器输入的ID一样的结果,有则list1.size()大于0) + { + result="0";//查询到相同身份证不允许注册,返回0 + } + else + { + //result="1查询不到相同身份正"; + int i= jdbcTemplate.update(sql3); + //判断是否注册成功 + if (i> 0) + { + + //System.out.println("注册成功!");//数据插入成功! + result = "1"; + } else + { + //System.out.println("注册失败!");//数据插入失败! + result = "0"; + } + + + + } + } + //若身份证留空则注册失败 + else + { + result="0";//身份证留空,注册失败,返回0 + } + + + + return result; + } + +}