一 实体类
1 Job
package com.lyq.bean;
public class Job {
private int jID; //存储岗位编号字段
private String jName; //存储岗位名称字段
private String educationReq; //存储岗位学历要求字段
private String titleReq; //存储岗位职称要求字段
private String jType; //存储岗位工种限制字段
private int yearsReq; //存储岗位工龄限制字段
//岗位编号字段的get方法
public int getjID() {
return jID;
}
//岗位编号字段的set方法
public void setjID(int jID) {
this.jID = jID;
}
//其余get与set方法请自行补充
public String getjName() {
return jName;
}
public void setjName(String jName) {
this.jName = jName;
}
public String getEducationReq() {
return educationReq;
}
public void setEducationReq(String educationReq) {
this.educationReq = educationReq;
}
public String getTitleReq() {
return titleReq;
}
public void setTitleReq(String titleReq) {
this.titleReq = titleReq;
}
public String getjType() {
return jType;
}
public void setjType(String jType) {
this.jType = jType;
}
public int getYearsReq() {
return yearsReq;
}
public void setYearsReq(int yearsReq) {
this.yearsReq = yearsReq;
}
}
2 Need
package com.lyq.bean;
import java.util.Date;
public class Need {
private int jID; //存储岗位编号字段
private int cID; //存储企业编号字段
private String jName; //存储岗位名称字段
private String cName; //存储企业名称字段
private String educationReq; //存储岗位学历要求字段
private String titleReq; //存储岗位职称要求字段
private String jType; //存储岗位工种限制字段
private int yearsReq; //存储岗位工龄限制字段
private Date putDate; //存储需求发布日期字段
private int people; //存储需求人数字段
private int payment; //存储最低薪酬字段
private String leader; //存储企业负责人姓名字段
private String tel; //存储企业联系电话字段
//岗位编号的get方法
public int getjID() {
return jID;
}
//岗位编号的set方法
public void setjID(int jID) {
this.jID = jID;
}
//其余get与set方法请自行补充
public Date getPutDate() {
return putDate;
}
public void setPutDate(Date putDate) {
this.putDate = putDate;
}
public int getPeople() {
return people;
}
public void setPeople(int people) {
this.people = people;
}
public int getPayment() {
return payment;
}
public void setPayment(int payment) {
this.payment = payment;
}
public String getjName() {
return jName;
}
public void setjName(String jName) {
this.jName = jName;
}
public String getcName() {
return cName;
}
public void setcName(String cName) {
this.cName = cName;
}
public String getEducationReq() {
return educationReq;
}
public void setEducationReq(String educationReq) {
this.educationReq = educationReq;
}
public String getTitleReq() {
return titleReq;
}
public void setTitleReq(String titleReq) {
this.titleReq = titleReq;
}
public String getjType() {
return jType;
}
public void setjType(String jType) {
this.jType = jType;
}
public int getYearsReq() {
return yearsReq;
}
public void setYearsReq(int yearsReq) {
this.yearsReq = yearsReq;
}
public String getLeader() {
return leader;
}
public void setLeader(String leader) {
this.leader = leader;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getcID() {
return cID;
}
public void setcID(int cID) {
this.cID = cID;
}
}
二 DAO层
1 JobDAO
package com.lyq.bean;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
public class JobDAO {
/**
* 获取数据库连接
* @return
*/
//获取数据库连接
public Connection getConnection(){
Connection connection = null; //声明Connection对象的实例
try {
Class.forName("org.gjt.mm.mysql.Driver");
//装载数据库驱动,若连接报错,可尝试将参数替换为"com.mysql.jdbc.Driver"
String url = "jdbc:mysql://localhost:3306/work?characterEncoding=gbk";
//"characterEncoding=gbk为指定数据库连接的编码格式,防止写入数据库时中文乱码
String username = "root";
String password = ""; //账号密码信息根据自己MySQL系统的设定填写
connection = DriverManager.getConnection(url, username, password);
//建立与数据库的连接
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection; //返回Connection对象实例
}
/**
* 查询所有岗位信息
* @return
* @throws IOException
*/
//查询所有岗位信息
public List<Need> findAllJob() throws IOException{
List<Need> list = new ArrayList<Need>();
//用来存储查询结果
Connection connection = getConnection();
//获取数据库连接
try {
CallableStatement cStatement =
connection.prepareCall("{call findAllJob()}");
//调用数据库存储过程findAllJob
ResultSet resultSet = cStatement.executeQuery();
while(resultSet.next()){
Need need = new Need();
need.setjID(resultSet.getInt("jID"));
need.setjName(resultSet.getString("jName"));
need.setcName(resultSet.getString("cName"));
need.setEducationReq(resultSet.getString("educationReq"));
need.setTitleReq(resultSet.getString("titleReq"));
need.setjType(resultSet.getString("jType"));
need.setYearsReq(resultSet.getInt("yearsReq"));
need.setPutDate(resultSet.getDate("putDate"));
need.setPeople(resultSet.getInt("people"));
need.setPayment(resultSet.getInt("payment"));
need.setLeader(resultSet.getString("leader"));
need.setTel(resultSet.getString("tel"));
list.add(need);
//将结果添加到list中
}
connection.close(); //释放数据库连接
cStatement.close();
resultSet.close();
} catch (Exception e) {
e.printStackTrace();
}
return list; //返回查询结果
}
/**
* 通过最低工资查询所有工作岗位
* @param min
* @return
* @throws IOException
*/
//通过最低工资查询所有工作岗位
public List<Need> findAllJobByPay(int min) throws IOException{
List<Need> list = new ArrayList<Need>();
Connection connection = getConnection();
//获取数据库连接
try {
CallableStatement cStatement =
connection.prepareCall("{call findAllJobByPay(?)}");
//调用数据库存储过程findAllJobByPay
cStatement.setInt(1, min); //添加查询参数
ResultSet resultSet = cStatement.executeQuery();
while(resultSet.next()){
Need need = new Need();
need.setjID(resultSet.getInt("jID"));
need.setjName(resultSet.getString("jName"));
need.setcName(resultSet.getString("cName"));
need.setEducationReq(resultSet.getString("educationReq"));
need.setTitleReq(resultSet.getString("titleReq"));
need.setjType(resultSet.getString("jType"));
need.setYearsReq(resultSet.getInt("yearsReq"));
need.setPutDate(resultSet.getDate("putDate"));
need.setPeople(resultSet.getInt("people"));
need.setPayment(resultSet.getInt("payment"));
need.setLeader(resultSet.getString("leader"));
need.setTel(resultSet.getString("tel"));
list.add(need); //将查询结果添加到list中
}
connection.close(); //释放数据库连接
cStatement.close();
resultSet.close();
} catch (Exception e) {
e.printStackTrace();
}
return list; //返回查询结果
}
/**
* 添加一条岗位记录
* @param job
* @return
*/
public boolean insertJob(Job job){
Connection connection = getConnection();
boolean flag = false;
try {
String sql = "insert into job(jName, educationReq, titleReq, jType, yearsReq) value(?, ?, ?, ?, ?)";
PreparedStatement pStatement = connection.prepareStatement(sql);
pStatement.setString(1, job.getjName());
pStatement.setString(2, job.getEducationReq());
pStatement.setString(3, job.getTitleReq());
pStatement.setString(4, job.getjType());
pStatement.setInt(5, job.getYearsReq());
int row = pStatement.executeUpdate();
if(row > 0){
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
/**
* 添加一条岗位需求记录
* @param need
* @return
*/
public boolean insertNeed(Need need){
Connection connection = getConnection();
boolean flag = false;
try {
String sql = "insert into need(jID, cID, putDate, people, payment) value(?, ?, ?, ?, ?)";
PreparedStatement pStatement = connection.prepareStatement(sql);
pStatement.setInt(1, need.getjID());
pStatement.setInt(2, need.getcID());
java.util.Date date = need.getPutDate();
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
pStatement.setDate(3, sqlDate);
pStatement.setInt(4, need.getPeople());
pStatement.setInt(5, need.getPayment());
int row = pStatement.executeUpdate();
if(row > 0){
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
/**
* 通过详细信息查找岗位记录
* @param job
* @return
*/
public Job findJobID(Job job){
List<Job> list = new ArrayList<Job>();
Connection connection = getConnection();
boolean flag = false;
try {
String sql = "select * from job where job.jName = ? and job.educationReq = ? and job.titleReq = ? and "
+ "job.jType = ? and job.yearsReq = ?;";
PreparedStatement pStatement = connection.prepareStatement(sql);
pStatement.setString(1, job.getjName());
pStatement.setString(2, job.getEducationReq());
pStatement.setString(3, job.getTitleReq());
pStatement.setString(4, job.getjType());
pStatement.setInt(5, job.getYearsReq());
ResultSet resultSet = pStatement.executeQuery();
while(resultSet.next()){
Job newJob = new Job();
newJob.setjID(resultSet.getInt("jID"));
newJob.setjName(job.getjName());
newJob.setEducationReq(job.getEducationReq());
newJob.setTitleReq(job.getTitleReq());
newJob.setjType(job.getjType());
newJob.setYearsReq(job.getYearsReq());
list.add(newJob);
}
} catch (Exception e) {
e.printStackTrace();
}
if(list == null || list.size() < 1){
return null;
} else {
return list.get(0);
}
}
public List<Need> findAllJobBycID(int id) throws IOException{
List<Need> list = new ArrayList<Need>();
Connection connection = getConnection();
try {
CallableStatement cStatement = connection.prepareCall("{call findAllJobBycID(?)}");
cStatement.setInt(1, id);
ResultSet resultSet = cStatement.executeQuery();
while(resultSet.next()){
Need need = new Need();
need.setjID(resultSet.getInt("jID"));
need.setjName(resultSet.getString("jName"));
need.setcName(resultSet.getString("cName"));
need.setEducationReq(resultSet.getString("educationReq"));
need.setTitleReq(resultSet.getString("titleReq"));
need.setjType(resultSet.getString("jType"));
need.setYearsReq(resultSet.getInt("yearsReq"));
need.setPutDate(resultSet.getDate("putDate"));
need.setPeople(resultSet.getInt("people"));
need.setPayment(resultSet.getInt("payment"));
need.setLeader(resultSet.getString("leader"));
need.setTel(resultSet.getString("tel"));
list.add(need);
}
connection.close();
cStatement.close();
resultSet.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
三 用户主页面
<%@page import="com.lyq.bean.Worker"%>
<%@page import="java.util.List"%>
<%@page import="com.lyq.bean.WorkerDAO"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.SQLException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>饭票网-找工作</title>
<style type="text/css">
#content {
width: 1200px;
height: 620px;
text-align: center;
}
#tab_bar {
width: 1200px;
height: 70px;
float: left;
color: white;
}
#tab_bar ul {
padding: 0px;
margin: 0px;
height: 20px;
text-align: center;
}
#tab_bar li {
list-style-type: none;
float: left;
width: 400px;
height: 70px;
background-color: orange;
}
.tab_css {
width: 1200px;
height: 620px;
display: none;
float: left;
}
</style>
<script type="text/javascript">
var myclick = function(v) {
var llis = document.getElementsByTagName("li");
for (var i = 0; i < llis.length; i++) {
var lli = llis[i];
if (lli == document.getElementById("tab" + v)) {
lli.style.backgroundColor = "#FF0099";
} else {
lli.style.backgroundColor = "orange";
}
}
var divs = document.getElementsByClassName("tab_css");
for (var i = 0; i < divs.length; i++) {
var divv = divs[i];
if (divv == document.getElementById("tab" + v + "_content")) {
divv.style.display = "block";
} else {
divv.style.display = "none";
}
}
}
</script>
</head>
<body>
<div
style="background-image: url('images/backmm.jpg');
width: 100%; height: 100%;">
<%
String idStr = request.getParameter("workerPage1");
int id = Integer.parseInt(idStr);
Worker worker = new WorkerDAO().findWorkerByID(id);
%>
<div style="color: orange;">
<table style="width: 95%; margin-left: 30px;">
<tr>
<td align="left"><h3>
<b>Hello: <%=worker.getwName()%></b></h3></td>
<td align="right">
<a href="index.jsp"><h3><b>退出登录</b></h3></a></td>
</tr>
</table>
</div>
<div align="center" style="margin-top: 20px">
<div id="content">
<div id="tab_bar">
<ul>
<li id="tab1" onclick="myclick(1)"
style="background-color: #FF0099;"><h2>岗位信息</h2></li>
<li id="tab2" onclick="myclick(2)"><h2>企业信息</h2></li>
<li id="tab3" onclick="myclick(3)"><h2>岗位申请</h2></li>
</ul>
</div>
<div class="tab_css" id="tab1_content" style="display: block"
align="center">
<div><%@include file="allJob.jsp"%></div>
</div>
<div class="tab_css" id="tab2_content" align="center">
<div><%@include file="allCompany.jsp"%></div>
</div>
<div class="tab_css" id="tab3_content" align="center">
<div><%@include file="newApply.jsp"%></div>
</div>
</div>
</div>
</div>
</body>
</html>
四 运行