求一个javaweb mvc 的demo
本帖最后由 l848347 于 2012-12-04 16:40:38 编辑 DBHelper.java 、DBCommand.java和属性文件jdbcInfo.properties。
表建立对应的DTO,就是bean了。
表建立数据操作抽象对象DAO,,以及实现类DAOImpl。
service ServiceImpl 业务类
有个demo也好啊 !!
需要stucts吗???
不要ssh框架!!
dto
package zp.bean;
public class Job {
private Integer id;
private String jobname;
private String idate;
private Integer number;
private String location ;
private String decription;
private String requirement ;
private Integer cid ;
public String getJobname() {
return jobname;
}
public void setJobname(String jobname) {
this.jobname = jobname;
}
public String getIdate() {
return idate;
}
public void setIdate(String idate) {
this.idate = idate;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDecription() {
return decription;
}
public void setDecription(String decription) {
this.decription = decription;
}
public String getRequirement() {
return requirement;
}
public void setRequirement(String requirement) {
this.requirement = requirement;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
}
package zp.dao;
import java.util.List;
import zp.bean.Job;
public abstract class JobDAO extends BaseDAO{
public abstract List<Job> getAllJobs();
public abstract Job getJobByID(Integer id);
public abstract int updateJob(Job job);
public abstract int insertJob(Job job) ;
public abstract int deleteJobByID(Integer id);
}
public class JobDAOImpl extends JobDAO {
private PreparedStatement pstm;
/**
* 根据ID获取JOB详细
*/
public Job getJobByID(Integer id) {
Job job = null ;
try {
pstm = this.getConn()
.prepareStatement("select * from job where id = ? ");
Map<Object,Object> paramsMap = new LinkedHashMap<Object,Object>();
paramsMap.put("id", id.intValue());
List<Map<String,Object>> jobList = DBCommand.execQuery(pstm, paramsMap);
if(jobList.size() != 0){
job = new Job();
Map<String,Object> row = jobList.get(0);
job.setId(new Integer(row.get("id").toString()));
job.setJobname(row.get("jobname").toString());
job.setIdate(row.get("idate").toString());
job.setNumber(new Integer(row.get("number").toString()));
job.setLocation(row.get("location").toString());
job.setDecription(row.get("decription").toString());
job.setRequirement(row.get("requirement").toString());
job.setCid(new Integer(row.get("cid").toString()));
}
} catch (Exception e) {
e.printStackTrace();
}
return job;
}
}
import java.util.List;
import zp.bean.Job;
public interface JobService {
public List<Job> getAllJobs();
public Job getJobByID(Integer id);
public boolean updateJob(Job job);
public boolean insertJob(Job job) ;
public boolean deleteJobByID(Integer id);
}
public class JobServiceImpl implements JobService {
private JobDAO dao = new JobDAOImpl();
public Job getJobByID(Integer id) {
dao.setConn(DBHelper.getConn());
Job job = null;
try {
job = dao.getJobByID(id);
} catch (RuntimeException e) {
e.printStackTrace();
}finally{
DBHelper.closeConn();
}
return job;
}