3 changed files with 216 additions and 0 deletions
@ -0,0 +1,37 @@
|
||||
package demo.liaofeifei; |
||||
|
||||
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.util.List; |
||||
import java.util.Map; |
||||
|
||||
@RestController |
||||
public class cancel { |
||||
|
||||
@Autowired |
||||
private JdbcTemplate jdbcTemplate; |
||||
|
||||
|
||||
@RequestMapping("/cancel") |
||||
public int cancel(HttpServletRequest request){ |
||||
String staffNo=request.getParameter("staffNo"); |
||||
|
||||
String cancel="否"; |
||||
|
||||
String sql="UPDATE staff set cancel='"+cancel+"'where staffNo='"+staffNo+"'"; |
||||
|
||||
|
||||
int i=jdbcTemplate.update(sql); |
||||
return i; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
|
@ -0,0 +1,42 @@
|
||||
package demo.liaofeifei; |
||||
|
||||
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.util.List; |
||||
import java.util.Map; |
||||
|
||||
@RestController |
||||
public class login { |
||||
|
||||
@Autowired |
||||
private JdbcTemplate jdbcTemplate; |
||||
|
||||
@RequestMapping("/stafflogin") |
||||
public String getAllNewTableData(HttpServletRequest request) { |
||||
String staffNo=request.getParameter("staffNo"); |
||||
String password=request.getParameter("password");//前端送过来的密码
|
||||
|
||||
|
||||
String sql ="SELECT PASSWORD from staff WHERE staffNo='"+staffNo+"'"; |
||||
|
||||
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql); |
||||
|
||||
String result=""; |
||||
if (list==null||list.size()==0){ //查询不到用户返回0失败
|
||||
result="0"; |
||||
} |
||||
if (password.equals(list.get(0).get("password"))){//查询到用户且密码正确,返回1
|
||||
result="1"; |
||||
}else { |
||||
result="0";//查询到用户但是密码不正确,返回0
|
||||
} |
||||
|
||||
|
||||
return result; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,137 @@
|
||||
//package demo.pengbaohao.controller;
|
||||
|
||||
//public class register {
|
||||
//}
|
||||
package demo.liaofeifei; |
||||
|
||||
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; |
||||
import java.util.Date; |
||||
import java.text.SimpleDateFormat; |
||||
@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");
|
||||
|
||||
java.util.Date date = new Date(); |
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//获取系统时间
|
||||
String entryTime=sdf.format(date);//赋值
|
||||
|
||||
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 cancel=request.getParameter("cancel"); |
||||
|
||||
|
||||
String result = ""; |
||||
String staffNo = "";//定义工号变量用于获取数据库中最大的工号同时也是注册时插入表中的工号变量
|
||||
int staffNo1 =1;//新工号的初始值默认为1,防止出现数据库没有员工数据的情况出现
|
||||
|
||||
String sql2 = "SELECT staffNo from staff ORDER BY staffNo DESC LIMIT 1";//查看最后一条工号
|
||||
|
||||
|
||||
|
||||
//通过身份证判断这个人是否已经注册
|
||||
if (ID!=null)//判断浏览器输入的ID不为空
|
||||
{ |
||||
//看输入的ID是否跟表中重复
|
||||
String sql1 ="SELECT ID from staff WHERE ID='"+ID+"'";//拿浏览器输入的ID去对比数据库表中的ID
|
||||
List<Map<String,Object>> list1=jdbcTemplate.queryForList(sql1); |
||||
|
||||
if(list1.size() > 0)//判断上面sql语句的查询结果,是否存在(数据库是否存在有与浏览器输入的ID一样的结果,有则list1.size()大于0)
|
||||
{ |
||||
result="0";//查询到相同身份证不允许注册,返回0
|
||||
} |
||||
else |
||||
{ |
||||
//result="1查询不到相同身份正";
|
||||
List<Map<String, Object>> list= jdbcTemplate.queryForList(sql2);//当满足浏览器输入身份证不为空,且浏览器输入的身份证信息,在数据库中没有记录,则执行下一步,查询最后一条工号信息
|
||||
//查询表中是否有数据>0为有数据
|
||||
if(list.size()>0 && list.get(0).get("staffNo")!=null)//对获取到的数据库工号进行判断,list.size()>0,则说明数据库有工号数据,则将数据库最后一条记录的工号的值加1作为新工号的值,若数据库查询不到数据,则不执行下面if语句,默认使用上面int staffNo1 =1;的值
|
||||
{ |
||||
staffNo = (String) list.get(0).get("staffNo");//获取工号
|
||||
staffNo1 = Integer.parseInt(staffNo);//将工号转化为int型,便于+1
|
||||
staffNo1=staffNo1+1; |
||||
} else {//如果数据库没有信息则默认工号为001
|
||||
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,cancel) " + |
||||
"VALUES('"+staffNo+"','"+staffName+"','"+gender+"','"+birthday+"','"+ID+"','"+department+"','"+job+"','"+company+"','"+entryTime+"','"+contract+"','"+education+"','"+major+"','"+marriage+"','"+place+"','"+nation+"','"+politicalStatus+"','"+phone+"','"+address+"','"+password+"','"+cancel+"');"; |
||||
|
||||
|
||||
int i= jdbcTemplate.update(sql3);//执行
|
||||
//判断是否注册成功
|
||||
if (i> 0) |
||||
{ |
||||
|
||||
//System.out.println("注册成功!");//数据插入成功!
|
||||
result = "1"; |
||||
} else |
||||
{ |
||||
//System.out.println("注册失败!");//数据插入失败!
|
||||
result = "0"; |
||||
} |
||||
|
||||
} |
||||
} |
||||
//若身份证留空则注册失败
|
||||
else |
||||
{ |
||||
result="0";//身份证留空,注册失败,返回0
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
String sqln ="SELECT *from staff ";//查询数据库所有记录
|
||||
List<Map<String,Object>> listn=jdbcTemplate.queryForList(sqln); |
||||
|
||||
for (Map<String, Object> row : listn) { |
||||
// 打印每一行的数据
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) { |
||||
System.out.println(entry.getKey() + ": " + entry.getValue()); |
||||
} |
||||
System.out.println("-------------------------"); |
||||
} |
||||
|
||||
|
||||
|
||||
return result; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue