5 changed files with 159 additions and 219 deletions
@ -1,25 +1,25 @@
|
||||
package demo.liaofeifei; |
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
@RestController |
||||
public class makeUserNo { |
||||
|
||||
@RequestMapping("/makeUserNo") |
||||
public String makeUserNo(HttpServletRequest request){ |
||||
String orgNo=request.getParameter("orgNo"); |
||||
String seq="9";//挡板
|
||||
for(int i=0;i<4;i++){ |
||||
if(seq.length()>=4){ |
||||
break; |
||||
}else { |
||||
seq="0"+seq; |
||||
} |
||||
} |
||||
return orgNo+seq; |
||||
} |
||||
|
||||
} |
||||
package demo.liaofeifei; |
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
@RestController |
||||
public class makeUserNo { |
||||
|
||||
@RequestMapping("/makeUserNo") |
||||
public String makeUserNo(HttpServletRequest request){ |
||||
String orgNo=request.getParameter("orgNo"); |
||||
String seq="9";//挡板
|
||||
for(int i=0;i<4;i++){ |
||||
if(seq.length()>=4){ |
||||
break; |
||||
}else { |
||||
seq="0"+seq; |
||||
} |
||||
} |
||||
return orgNo+seq; |
||||
} |
||||
|
||||
} |
||||
|
@ -1,115 +1,120 @@
|
||||
package demo.liaofeifei; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
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.RestController; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.text.DecimalFormat; |
||||
import java.util.List; |
||||
//import java.util.list;
|
||||
import java.util.Map; |
||||
|
||||
@RestController |
||||
public class staffController{ |
||||
|
||||
@Autowired |
||||
private JdbcTemplate jdbcTemplate; |
||||
|
||||
@RequestMapping("/qryStaff") |
||||
public List<Map<String,Object>> QryStaff(HttpServletRequest request){ |
||||
|
||||
|
||||
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); |
||||
|
||||
System.out.println("测试:"+list.toString()); |
||||
|
||||
return list; |
||||
} |
||||
|
||||
@RequestMapping("/addStaff") |
||||
public int addStaff(HttpServletRequest request){ |
||||
String staffNo = request.getParameter("staffNo"); |
||||
String staffName = request.getParameter("staffName"); |
||||
String gender = request.getParameter("gender"); |
||||
String birthday = request.getParameter("birthday"); |
||||
|
||||
String department = request.getParameter("department"); |
||||
String position = request.getParameter("position"); |
||||
String company = request.getParameter("company"); |
||||
String contractType = request.getParameter("contractType"); |
||||
String phone = request.getParameter("phone"); |
||||
String password = request.getParameter("password"); |
||||
String address = request.getParameter("address"); |
||||
|
||||
|
||||
int staffNo1 =1;//新工号的初始值默认为1,防止出现数据库没有员工数据的情况出现
|
||||
String sql2 = "SELECT staffNo from staff ORDER BY staffNo DESC LIMIT 1";//查看最后一条工号
|
||||
|
||||
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql2); |
||||
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) + 1;//将工号转化为int型,便于+
|
||||
|
||||
//定义一个规则用来规范工号的位数为三位
|
||||
DecimalFormat df = new DecimalFormat("000"); // 创建一个DecimalFormat对象,模式为000
|
||||
staffNo = df.format(staffNo1);//将整形型的staffN1,规范化并转化为String字符串型
|
||||
} |
||||
|
||||
String sql = "INSERT INTO staff (staffNo, staffName, gender, birthday, department, job, company, contract, phone, password,address) " + |
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)"; |
||||
int i = jdbcTemplate.update(sql, staffNo, staffName, gender, birthday, department, position, company, contractType, phone, password,address); |
||||
return i; |
||||
} |
||||
|
||||
|
||||
|
||||
@RequestMapping("/updateStaff") |
||||
public int updateStaff(HttpServletRequest request){ |
||||
String staffNo = request.getParameter("staffNo"); |
||||
String staffName = request.getParameter("staffName"); |
||||
String gender = request.getParameter("gender"); |
||||
String birthday = request.getParameter("birthday"); |
||||
String department = request.getParameter("department"); |
||||
String position = request.getParameter("position"); |
||||
String company = request.getParameter("company"); |
||||
String contractType = 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 idCard = request.getParameter("ID"); |
||||
|
||||
String sql = "UPDATE staff SET staffName=?, gender=?, birthday=?, department=?, job=?, company=?, contract=?, education=?, major=?, marriage=?, place=?, nation=?, politicalStatus=?, phone=?, address=?, ID=? WHERE staffNo=?"; |
||||
int i = jdbcTemplate.update(sql, staffName, gender, birthday, department, position, company, contractType, education, major, marriage, place, nation, politicalStatus, phone, address, idCard, staffNo); |
||||
return i; |
||||
} |
||||
|
||||
|
||||
|
||||
@RequestMapping("/delStaff") |
||||
public int delStaff(HttpServletRequest request) { |
||||
String staffNo = request.getParameter("staffNo"); |
||||
|
||||
String sql="DELETE FROM staff WHERE staffNo='"+staffNo+"'"; |
||||
|
||||
|
||||
int i=jdbcTemplate.update(sql); |
||||
return i; |
||||
} |
||||
} |
||||
|
||||
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.SimpleDateFormat; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
//import java.util.list;
|
||||
import java.util.Map; |
||||
|
||||
@RestController |
||||
public class staffController{ |
||||
|
||||
@Autowired |
||||
private JdbcTemplate jdbcTemplate; |
||||
|
||||
@RequestMapping("/qryStaff") |
||||
public List<Map<String,Object>> QryStaff(HttpServletRequest request){ |
||||
String staffNo=request.getParameter("staffNo"); |
||||
|
||||
String sql="select * from staff s where staffNo ='"+staffNo+"'"; |
||||
|
||||
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql); |
||||
|
||||
System.out.println("测试:"+list.toString()); |
||||
|
||||
return list; |
||||
} |
||||
|
||||
@RequestMapping("/addStaffwww") |
||||
public int addStaff(HttpServletRequest request){ |
||||
String staffNo=request.getParameter("staffNo"); |
||||
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 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+"');"; |
||||
|
||||
int i=jdbcTemplate.update(sql); |
||||
return i; |
||||
} |
||||
|
||||
|
||||
@RequestMapping("/updateStaff") |
||||
public int updateStaff(HttpServletRequest request){ |
||||
String staffNo=request.getParameter("staffNo"); |
||||
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 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; |
||||
} |
||||
|
||||
@RequestMapping("/delStaff") |
||||
public int delStaff(HttpServletRequest request) { |
||||
String staffNo = request.getParameter("staffNo"); |
||||
|
||||
String sql="DELETE FROM staff WHERE staffNo='"+staffNo+"'"; |
||||
|
||||
|
||||
int i=jdbcTemplate.update(sql); |
||||
return i; |
||||
} |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue