员工信息管理系统 - 添加员工
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>员工信息管理系统 - 添加员工</title>
<style>
div{
width: 600px;
height: 400px;
background-color: antiquewhite;
line-height: 25px;
<pre><code> }
</style>
</code></pre>
</head>
<body>
<div>
<form action="addemp.do" method="post">
empno:<input id="1" type="text" name="empno" placeholder="请输入员工编号"/><br/>
<pre><code> ename:<input id="2" type="text" name="ename" placeholder="请输入员工姓名"/><br/>
job:<input id="3" type="text" name="job" placeholder="请输入员工职位"/><br/>
mgr:<input id="4" type="text" name="mgr" placeholder="请输入员工上级编号"/><br/>
hiredate:<input id="5" type="date" name="hiredate" /><br/>
sal:<input id="6" type="text" name="sal" placeholder="请输入员工工资"/><br/>
comm:<input id="7" type="text" name="comm" placeholder="请输入员工奖金"/><br/>
deptno:<input id="8" type="text" name="deptno" placeholder="请输入员工部门编号"/><br/>
<input type="submit" value="提交">
</form>
</code></pre>
</div>
</body>
</html>
<p>package com.scq.ems.util;</p>
<p>import com.alibaba.druid.pool.DruidDataSourceFactory;</p>
<p>import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;</p>
<p>public class DataSUtil {
public static Connection getConnection() throws Exception{
Properties ps=new Properties();</p>
<pre><code> ps.load(DataSUtil.class.getClassLoader().getResourceAsStream("datasutil.properties"));
DataSource dataSource = DruidDataSourceFactory.createDataSource(ps);
Connection connection = dataSource.getConnection();
return connection;
}
</code></pre>
<p>}</p>
<p>package com.scq.ems.util;</p>
<p>import java.sql.Connection;
import java.sql.PreparedStatement;</p>
<p>public class jdbce {
private Connection conn;</p>
<pre><code>private PreparedStatement ps;
private static jdbce e;
public jdbce() {
System.out.println("123456789");
try {
conn=DataSUtil.getConnection();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public static jdbce gete(){
if (e==null){
e =new jdbce();
}
return e;
}
//开始封装
public int executorUpdate(String sql,Object...params)throws Exception{
ps=conn.prepareStatement(sql);
bingder(ps,params);
System.out.println("执行的语句" + ps);
return ps.executeUpdate();
}
private void bingder(PreparedStatement ps,Object...params)throws Exception {
if (params != null && params.length > 0) {
for (int i = 0; i < ps.getParameterMetaData().getParameterCount(); i++) {
ps.setObject(i + 1, params[i]);
}
}
}
</code></pre>
<p>}</p>
<p>package com.scq.ems.domain;</p>
<p>import java.util.Date;</p>
<p>public class employee {
private int empno;
private String ename;
private String job;
private int mgr;
private Date hiredate;
private double sal;
private int comm;
private int deptno;</p>
<pre><code>public employee() {
}
public employee(int empno, String ename, String job, int mgr, Date hiredate, double sal, int comm, int deptno) {
this.empno = empno;
this.ename = ename;
this.job = job;
this.mgr = mgr;
this.hiredate = hiredate;
this.sal = sal;
this.comm = comm;
this.deptno = deptno;
}
public int getEmpno() {
return empno;
}
public void setEmpno(int empno) {
this.empno = empno;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public int getMgr() {
return mgr;
}
public void setMgr(int mgr) {
this.mgr = mgr;
}
public Date getHiredate() {
return hiredate;
}
public void setHiredate(Date hiredate) {
this.hiredate = hiredate;
}
public double getSal() {
return sal;
}
public void setSal(double sal) {
this.sal = sal;
}
public int getComm() {
return comm;
}
public void setComm(int comm) {
this.comm = comm;
}
public int getDeptno() {
return deptno;
}
public void setDeptno(int deptno) {
this.deptno = deptno;
}
@Override
public String toString() {
return "employee{" +
"empno=" + empno +
", ename='" + ename + "'" +
", job='" + job + "'" +
", mgr=" + mgr +
", hiredate=" + hiredate +
", sal=" + sal +
", comm=" + comm +
", deptno=" + deptno +
'}';
}
</code></pre>
<p>}</p>
<p>package com.scq.ems.dao;</p>
<p>import com.scq.ems.domain.employee;</p>
<p>public interface emsdao {
boolean addemp(employee e);
}</p>
<p>package com.scq.ems.dao.impl;</p>
<p>import com.scq.ems.dao.emsdao;
import com.scq.ems.domain.employee;</p>
<p>public class emsdaoimpl implements emsdao {</p>
<pre><code>@Override
public boolean addemp(employee e) {
return false;
}
</code></pre>
<p>}</p>
<p>package com.scq.ems.SERVLET;</p>
<p>import com.scq.ems.dao.emsdao;
import com.scq.ems.dao.impl.emsdaoimpl;
import com.scq.ems.domain.employee;</p>
<p>import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.sql.Date;</p>
<p>@WebServlet("*.do")
public class mesActionServlet extends HttpServlet {
private emsdao ed=new emsdaoimpl();</p>
<pre><code>protected void service(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
String requestURI = request.getRequestURI();
String path = requestURI.substring(requestURI.lastIndexOf('/')+1,requestURI.lastIndexOf('.'));
if (path.equals("addemp")) {
this.saveEmployee(request, response);
}
}
private void saveEmployee(HttpServletRequest request, HttpServletResponse response) {
//??????????????
String empno = request.getParameter("empno");
String ename = request.getParameter("ename");
String job = request.getParameter("job");
String mgr = request.getParameter("mgr");
String hiredate = request.getParameter("hiredate");
String sal = request.getParameter("sal");
String comm = request.getParameter("comm");
String deptno = request.getParameter("deptno");
employee e = new employee(
Integer.parseInt(empno),
ename,
job,
Integer.parseInt(mgr),
Date.valueOf(hiredate),
Double.parseDouble(sal),
Integer.parseInt(comm),
Integer.parseInt(deptno));
System.out.println("e = " + e);
try {
boolean flag =ed.addemp(e);
if (flag) {
response.getWriter().println("<h1>正在路上<h1>");
} else {
response.getWriter().println("<h1>反方向的钟<h1>");
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
</code></pre>
<p>}</p>
原文地址: https://www.cveoy.top/t/topic/qtBv 著作权归作者所有。请勿转载和采集!