读书人

javaweb mvc 的demo

发布时间: 2012-12-23 11:28:15 作者: rapoo

求一个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;
}

}


dao

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);

}

daoimpl

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;
}
}


server


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);

}

ServiceImpl

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;
}



jsp页面怎么调用这些方法呢?
需要action吗?
还是需要servlet!!!
求个demo!!!!!
最好能有个登录的demo
[解决办法]
M model也就是bean V 视图也就是jsp C 控制器,就是Servlet,你么有Servlet,Servlet调用前后台,做关联的,你再定义一个Servlet调用你的JobServiceImpl 这个类,然后根据这个类的返回信息请求转发到前台页面就是了。
[解决办法]
你还有没有呀,么有发个邮箱,我给你发个
[解决办法]
在servlet里调用service就可以了,调用方法后得到数据转发到页面,用request那几个对象传就可以了吧。
[解决办法]
http://download.csdn.net/detail/zuxianghuang/3442207

http://blog.csdn.net/zuxianghuang/article/details/6525432

读书人网 >Java Web开发

热点推荐