<!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>    }
&lt;/style&gt;
</code></pre>
</head>
<body>
<div>
    <form action="addemp.do" method="post">
        empno:<input id="1" type="text" name="empno" placeholder="请输入员工编号"/><br/>
<pre><code>    ename:&lt;input id=&quot;2&quot; type=&quot;text&quot; name=&quot;ename&quot; placeholder=&quot;请输入员工姓名&quot;/&gt;&lt;br/&gt;

    job:&lt;input id=&quot;3&quot; type=&quot;text&quot; name=&quot;job&quot; placeholder=&quot;请输入员工职位&quot;/&gt;&lt;br/&gt;

    mgr:&lt;input id=&quot;4&quot; type=&quot;text&quot; name=&quot;mgr&quot; placeholder=&quot;请输入员工上级编号&quot;/&gt;&lt;br/&gt;

    hiredate:&lt;input id=&quot;5&quot; type=&quot;date&quot; name=&quot;hiredate&quot; /&gt;&lt;br/&gt;

    sal:&lt;input id=&quot;6&quot; type=&quot;text&quot; name=&quot;sal&quot; placeholder=&quot;请输入员工工资&quot;/&gt;&lt;br/&gt;

    comm:&lt;input id=&quot;7&quot; type=&quot;text&quot; name=&quot;comm&quot; placeholder=&quot;请输入员工奖金&quot;/&gt;&lt;br/&gt;

    deptno:&lt;input id=&quot;8&quot; type=&quot;text&quot; name=&quot;deptno&quot; placeholder=&quot;请输入员工部门编号&quot;/&gt;&lt;br/&gt;

    &lt;input type=&quot;submit&quot; value=&quot;提交&quot;&gt;
&lt;/form&gt;
</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(&quot;datasutil.properties&quot;));

    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(&quot;123456789&quot;);
    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(&quot;执行的语句&quot; + ps);

    return ps.executeUpdate();

}

private void bingder(PreparedStatement ps,Object...params)throws Exception {
    if (params != null &amp;&amp; params.length &gt; 0) {
        for (int i = 0; i &lt; 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 &quot;employee{&quot; +
            &quot;empno=&quot; + empno +
            &quot;, ename='&quot; + ename + &quot;'&quot; +
            &quot;, job='&quot; + job + &quot;'&quot; +
            &quot;, mgr=&quot; + mgr +
            &quot;, hiredate=&quot; + hiredate +
            &quot;, sal=&quot; + sal +
            &quot;, comm=&quot; + comm +
            &quot;, deptno=&quot; + 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(&quot;*.do&quot;)
public class mesActionServlet extends HttpServlet {
private emsdao ed=new emsdaoimpl();</p>
<pre><code>protected void service(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
        request.setCharacterEncoding(&quot;UTF-8&quot;);
        response.setContentType(&quot;text/html;charset=utf-8&quot;);

        String requestURI = request.getRequestURI();

        String path = requestURI.substring(requestURI.lastIndexOf('/')+1,requestURI.lastIndexOf('.'));

        if (path.equals(&quot;addemp&quot;)) {
            this.saveEmployee(request, response);
        }
}
private void saveEmployee(HttpServletRequest request, HttpServletResponse response) {

    //??????????????
    String empno = request.getParameter(&quot;empno&quot;);
    String ename = request.getParameter(&quot;ename&quot;);
    String job = request.getParameter(&quot;job&quot;);
    String mgr = request.getParameter(&quot;mgr&quot;);
    String hiredate = request.getParameter(&quot;hiredate&quot;);
    String sal = request.getParameter(&quot;sal&quot;);
    String comm = request.getParameter(&quot;comm&quot;);
    String deptno = request.getParameter(&quot;deptno&quot;);


    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(&quot;e = &quot; + e);

    try {
        boolean flag =ed.addemp(e);
        if (flag) {
            response.getWriter().println(&quot;&lt;h1&gt;正在路上&lt;h1&gt;&quot;);
        } else {
            response.getWriter().println(&quot;&lt;h1&gt;反方向的钟&lt;h1&gt;&quot;);
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}
</code></pre>
<p>}</p>
员工信息管理系统 - 添加员工

原文地址: https://www.cveoy.top/t/topic/qtBv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录