master
dida 6 years ago
commit dfb8cc9aa6

@ -0,0 +1,354 @@
package action;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import model.Classify;
import model.PageBean;
import model.Goods;
import model.User;
//import model.UserAdmin;
import org.apache.struts2.ServletActionContext;
import org.aspectj.util.FileUtil;
import service.IUserService;
import util.AddJson;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class GoodsAction extends ActionSupport implements ModelDriven<Goods>{
IUserService iUserService;
public void setiUserService(IUserService iUserService) {
this.iUserService = iUserService;
}
Goods good=new Goods();
@Override
public Goods getModel() {
return good;
}
HttpServletRequest req=ServletActionContext.getRequest();
AddJson json=new AddJson();
private int currPage=1;//当前页
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
private File proPictureFile;
private String proPictureFileFileName;
private String proPictureContentType;
private final int BUFFER_SIZE=16*1024;
private Integer classifyId;
public Integer getClassifyId() {
return classifyId;
}
public void setClassifyId(Integer classifyId) {
this.classifyId = classifyId;
}
public File getProPictureFile() {
return proPictureFile;
}
public void setProPictureFile(File proPictureFile) {
this.proPictureFile = proPictureFile;
}
public String getProPictureContentType() {
return proPictureContentType;
}
public void setProPictureContentType(String proPictureContentType) {
this.proPictureContentType = proPictureContentType;
}
public String getProPictureFileFileName() {
return proPictureFileFileName;
}
public void setProPictureFileFileName(String proPictureFileFileName) {
this.proPictureFileFileName = proPictureFileFileName;
}
/**
*
*/
public String addLostGood() throws Exception{
String newFileName=new Date().getTime()+getExtention(proPictureFileFileName);
String path=ServletActionContext.getServletContext().getRealPath("/upload");
File picFile=new File(path);
if(!picFile.exists()){
picFile.mkdir();
}
FileUtil.copyFile(proPictureFile, new File(picFile,newFileName));
//copy(proPictureFile,picFile);
good.setPicture(newFileName);
good.setCreateTime(new Date());
Classify c=this.iUserService.getClassifyById(good.getClassifyId());
User u=this.iUserService.getUserById(good.getCreatorId());
good.setClassify(c);
good.setUser(u);
good.setGoodsstatus(0);
this.iUserService.saveGood(good);
this.addActionMessage("发布成功!");
return "uploadSuccess";
}
public String addFoundGood() throws Exception{
String newFileName=new Date().getTime()+getExtention(proPictureFileFileName);
String path=ServletActionContext.getServletContext().getRealPath("/upload");
File picFile=new File(path);
if(!picFile.exists()){
picFile.mkdir();
}
FileUtil.copyFile(proPictureFile, new File(picFile,newFileName));
//copy(proPictureFile,picFile);
good.setPicture(newFileName);
good.setCreateTime(new Date());
Classify c=this.iUserService.getClassifyById(good.getClassifyId());
User u=this.iUserService.getUserById(good.getCreatorId());
good.setClassify(c);
good.setUser(u);
good.setGoodsstatus(1);
this.iUserService.saveGood(good);
this.addActionMessage("发布成功!");
return "uploadSuccess";
}
/**
* io
* @param src
* @param dst
* @throws Exception
*/
private void copy(File src, File dst)throws Exception {
InputStream in=null;
OutputStream out=null;
try {
in=new BufferedInputStream(new FileInputStream(src),BUFFER_SIZE);
out=new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
while(in.read(buffer)>0){
out.write(buffer);
}
} catch (Exception e) {
throw e;
}finally{
try {
in.close();
} catch (Exception e2) {
}
try {
out.close();
} catch (Exception e2) {
}
}
}
/**
*
* @param filename
* @return
*/
private String getExtention(String filename) {
int pos=filename.lastIndexOf(".");
return filename.substring(pos);
}
/**
*
* @throws IOException
*/
public void searchClassifyList() throws IOException{
List<Classify> list=this.iUserService.searchClassifyList();
this.json.toJsonArray(list);
}
/**
*
*/
public void searchLostGoodList() throws Exception{
//String keyword=req.getParameter("keyword");
String cid=req.getParameter("cid");
//String conditon=req.getParameter("condition");
Map<Object,String> map=new HashMap<Object,String>();
/*if(keyword!=null&&keyword!=""){
map.put("keyword", keyword);
}*/
if(cid!=null&&cid!=""){
map.put("cid", cid);
}
/*if(conditon!=null&&conditon!=""){
map.put("conditon", conditon);
}*/
map.put("currPage", currPage+"");
PageBean<Goods> proList=this.iUserService.searchLostGoodList(map);
this.json.toJsonObj(proList);
}
public void searchFoundGoodList() throws Exception{
String cid=req.getParameter("cid");
Map<Object,String> map=new HashMap<Object,String>();
if(cid!=null&&cid!=""){
map.put("cid", cid);
}
map.put("currPage", currPage+"");
PageBean<Goods> proList=this.iUserService.searchFoundGoodList(map);
this.json.toJsonObj(proList);
}
/**
*
*/
public void getLostGoodDetail() throws Exception{
String id=req.getParameter("id");
Goods good=this.iUserService.getLostGoodDetail(id);
this.json.toJson(good);
}
public void getFoundGoodDetail() throws Exception{
String id=req.getParameter("id");
Goods good=this.iUserService.getFoundGoodDetail(id);
this.json.toJson(good);
}
/**
*
* @throws Exception
*/
public void searchMyLostProductByPage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
Map<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getId()+"");
PageBean<Goods> myproList=this.iUserService.searchMyLostGoodByPage(map);
this.json.toJson(myproList);
}
}
public void searchMyProductByPage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
Map<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getId()+"");
PageBean<Goods> myproList=this.iUserService.searchMyFoundGoodByPage(map);
this.json.toJson(myproList);
}
}
private String repContent;
private String content;
public String getRepContent() {
return repContent;
}
public void setRepContent(String repContent) {
this.repContent = repContent;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
/**
*
* <p>Description: </p>
* @throws Exception
*/
public void deleteMyGoodById() throws Exception{
User user=(User) req.getSession().getAttribute("User");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
int pid=Integer.parseInt(req.getParameter("id"));
this.iUserService.delectGoodById(pid);
}
}
/**
*
* @throws Exception
* @param flag 0,1
*/
/* public String searchMessageByPage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
String flag="";
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
flag=req.getParameter("flag");//0系统消息,1用户消息
Map<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getId()+"");
map.put("flag", flag);
PageBean<UserAdmin> message=this.iUserService.searchMessageByPage(map);
if(message!=null){
ActionContext.getContext().getValueStack().push(message);
}
}
if(flag=="0"||"0".equals(flag)){
return "sysmessage";
}else{
return "usermessage";
}
}
private String flag;
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
/**
*
* @return
* @throws Exception
*/
/* public String deleteMessage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
//String flag=req.getParameter("flag");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
String id=req.getParameter("id");
this.iUserService.deleteMessage(Integer.parseInt(id));
}
if(flag=="0"||"0".equals(flag)){
return "sysmsgDelete";
}else{
return "usermsgDelete";
}
}*/
}

@ -0,0 +1,162 @@
package action;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import service.ILoginService;
import util.AddJson;
import model.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class UserAction extends ActionSupport implements ModelDriven<User>{
User user=new User();
@Override
public User getModel() {
return user;
}
ILoginService iLoginService;
public void setiLoginService(ILoginService iLoginService) {
this.iLoginService = iLoginService;
}
HttpServletRequest req=ServletActionContext.getRequest();
/**
*
* @return
*/
public String UserLogin(){
//HttpServletRequest req=ServletActionContext.getRequest();
if(user==null){
this.addActionError("请输入账号和密码!");
return "login";
}
User u=this.iLoginService.findByUser(user);
if(u==null){
this.addActionError("用户名或密码错误!");
return "login";
}else{
req.getSession().setAttribute("User", u);
return "index";
}
}
/**
*
*/
public String userRegister(){
//通过用户名先查询该用户是否已经注册
User u=this.iLoginService.findUserByName(user.getUsername());
if(u!=null){
this.addActionError("该用户已被注册!");
return "registerFail";
}
//user.setHeadPic("images/logo-s.jpg");
this.iLoginService.saveUser(user);
return "registerSuccess";
}
/**
* 1
*/
public String forgetPwd(){
//HttpServletRequest req=ServletActionContext.getRequest();
String userName=req.getParameter("userName");
User u=this.iLoginService.findUserByName(userName);
if(u==null){
this.addFieldError(userName, "用户名错误!");
return "getPwdFail";
}
if(u.getQusetion()==null){
this.addActionError("抱歉!你没有设置问题和密码!");
return "getPwdFail";
}
req.getSession().setAttribute("User", u);
return "getPwdSuccess";
}
/**
* 2
*/
public String checkAnswer(){
//HttpServletRequest req=ServletActionContext.getRequest();
String answertext=req.getParameter("answer");
User u=this.iLoginService.findUserByName(user.getUsername());
if(u!=null){
String answer=u.getAnswer();
if(!answer.equals(answertext)){
this.addActionError("抱歉!回答错误!");
return "answerFalse";
}
}
req.getSession().setAttribute("User", u);
return "answerTrue";
}
/**
* 3
*/
public String updatePwd(){
this.iLoginService.updatePed(user);
return "updatePwdSuccess";
}
/**
*
* @throws Exception
*/
public void searchPersonalInfo() throws Exception{
//HttpServletRequest req=ServletActionContext.getRequest();
int uid=Integer.parseInt(req.getParameter("uid"));
if(uid==0){
throw new Exception("用户不存在!");
}
user=this.iLoginService.searchUserInfoById(uid);
AddJson json=new AddJson();
json.toJson(user);
//return "findUserInfoSuccess";
}
/**
*
*/
public void updateUserInfoById(){
int uid=Integer.parseInt(req.getParameter("id"));
String uname=req.getParameter("userName");
String pass=req.getParameter("password");
String phone=req.getParameter("phone");
String qusetion=req.getParameter("qusetion");
String answer=req.getParameter("answer");
int sex=Integer.parseInt(req.getParameter("sex"));
User uu=new User();
uu.setAnswer(answer);
uu.setPassword(pass);
uu.setPhone(phone);
uu.setId(uid);
uu.setUsername(uname);
uu.setQusetion(qusetion);
uu.setSex(sex);
this.iLoginService.updateUser(uu);
}
/**
* 退
*/
public String userExitLogin(){
req.getSession().removeAttribute("User");
return "UserexitSuccess";
}
}

@ -0,0 +1,53 @@
package dao;
//import model.Admin;
import model.User;
public interface ILoginDao {
/**
*
* @param user
* @return
*/
User findByUser(User user);
/**
*
* @param admin
* @return
*/
//Admin findByAdmin(Admin admin);
/**
*
* @param userName
* @return
*/
User findUserByName(String userName);
/**
*
* @param user
*/
void saveUser(User user);
/**
*
* @param user
*/
void updatePed(User user);
/**
* id
* @param uid
* @return
*/
User searchUserInfoById(int uid);
/**
*
* @param user
*/
void updateUser(User user);
}

@ -0,0 +1,111 @@
package dao;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.Goods;
import model.User;
//import model.UserAdmin;
public interface IUserDao {
/**
*
* @param product
*/
void saveGood(Goods good);
/**
*
* @return
*/
List<Classify> searchClassifyList();
/**
*
* @param map
* @return
*/
List<Goods> searchLostGoodList(Map<Object, String> map);
List<Goods> searchFoundGoodList(Map<Object, String> map);
/**
*
* @param map
* @return
*/
int searchLostGoodCount(Map<Object, String> map);
int searchFoundGoodCount(Map<Object, String> map);
/**
*
* @param id
* @return
*/
Goods getLostGoodDetail(String id);
Goods getFoundGoodDetail(String id);
/**
* id
* @param classifyId
*/
Classify getClassifyById(Integer classifyId);
User getUserById(Integer creatorId);
/*void updateProduct(Product product);*/
/**
* <p>Description: </p>
* @param parseInt
* @return
*/
int searchMyLostGoodCount(int parseInt);
int searchMyFoundGoodCount(int parseInt);
/**
* <p>Description: </p>
* @param map
* @return
*/
List<Goods> getMyLostGoodList(Map<Object, String> map);
List<Goods> getMyFoundGoodList(Map<Object, String> map);
/**
* <p>Description: </p>
* @param pid
*/
void delectGoodById(int pid);
/**
* <p>Description: </p>
* @param map
* @return
*/
// void saveUserMessage(UserAdmin uaa);
/**
* <p>Description: </p>
* @param map
* @return
*/
// int searchMessageCount(int uid, String flag);
/**
* <p>Description: </p>
* @param map
* @return
*/
// List<UserAdmin> getMessageList(Map<Object, String> map);
/**
* id
*/
void deleteMessage(int id);
}

@ -0,0 +1,96 @@
package dao.impl;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
//import model.Admin;
import model.User;
import dao.ILoginDao;
public class LoginDao extends HibernateDaoSupport implements ILoginDao {
/**
*
*/
@Override
public User findByUser(User user) {
String hql="from User u where u.userName=? and u.password=?";
@SuppressWarnings("unchecked")
List<User> list=this.getHibernateTemplate().find(hql,user.getUsername(),user.getPassword());
if(list.size()>0){
return list.get(0);
}else{
return null;
}
}
/**
*
*/
/* @Override
public Admin findByAdmin(Admin admin) {
String hql="from Admin a where a.name=? and a.password=?";
@SuppressWarnings("unchecked")
List<Admin> list=this.getHibernateTemplate().find(hql, admin.getName(),admin.getPassword());
if(list.size()>0){
return list.get(0);
}else{
return null;
}
}*/
/**
*
*/
@Override
public User findUserByName(String userName) {
String hql="from User where userName=?";
@SuppressWarnings("unchecked")
List<User> list=this.getHibernateTemplate().find(hql,userName);
if(list.size()>0){
return list.get(0);
}
return null;
}
/**
*
*/
@Override
public void saveUser(User user) {
this.getHibernateTemplate().save(user);
}
/**
*
*/
@Override
public void updatePed(User user) {
User u=this.getHibernateTemplate().get(User.class, user.getId());
u.setPassword(user.getPassword());
this.getHibernateTemplate().update(u);
}
/**
* id
*/
@Override
public User searchUserInfoById(int uid) {
User u=this.getHibernateTemplate().get(User.class, uid);
return u;
}
/**
*
*/
@Override
public void updateUser(User user) {
this.getHibernateTemplate().update(user);
}
}

@ -0,0 +1,362 @@
package dao.impl;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.Goods;
import model.User;
//import model.UserAdmin;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import dao.IUserDao;
public class UserDao extends HibernateDaoSupport implements IUserDao {
/**
*
*/
@Override
public void saveGood(Goods good) {
this.getHibernateTemplate().saveOrUpdate (good);
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public List<Classify> searchClassifyList() {
String hql="from Classify";
return this.getHibernateTemplate().find(hql);
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public List<Goods> searchLostGoodList(Map<Object, String> map) {
String cid=map.get("cid");
DetachedCriteria dc=DetachedCriteria.forClass(Goods.class);
//dc.addOrder(Order.desc("createTime"));
//dc.add(Restrictions.ne("proHassum", 0));
/*if(proName!=null){
proName="%"+map.get("keyword")+"%";
dc.add(Restrictions.like("proName",proName, MatchMode.ANYWHERE));
}*/
if(cid!=null){
dc.add(Restrictions.eq("classify.cid",Integer.parseInt(cid)));
}
dc.add(Restrictions.eq("goodsStatus",0));
/*if(condition!=null){
int con=Integer.parseInt(condition);
switch(con){
case 5:
dc.add(Restrictions.eq("type",1));
break;
case 4:
dc.add(Restrictions.eq("type",0));
break;
case 1:
dc.addOrder(Order.desc("proClicknum"));
break;
case 2:
dc.addOrder(Order.asc("proPrice"));
break;
case 3:
dc.addOrder(Order.desc("proPrice"));
break;
}
}*/
List<Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public int searchLostGoodCount(Map<Object, String> map) {
StringBuffer br=new StringBuffer();
StringBuffer order=new StringBuffer();
//String proName=map.get("keyword");
String cid=map.get("cid");
//String condition=map.get("conditon");
String count_hql="select count(*) from Product where goodsstatus='0'";
/*if(proName!=null){
proName="%"+map.get("keyword")+"%";
br.append(" and proName like '"+proName+"'");
}*/
if(cid!=null){
br.append(" and classify.cid='"+Integer.parseInt(cid)+"'");
}
/*if(condition!=null){
int con=Integer.parseInt(condition);
order.append(" order by createTime DESC");
switch(con){
case 1:
order.append(" ,proClicknum DESC");
break;
case 2:
order.append(" ,proPrice ASC");
break;
case 3:
order.append(" ,proPrice DESC");
break;
case 4:
br.append(" and type=0");
break;
case 5:
br.append(" and type=1");
break;
}
}*/
List<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@SuppressWarnings("unchecked")
@Override
public List<Goods> searchFoundGoodList(Map<Object, String> map) {
String cid=map.get("cid");
DetachedCriteria dc=DetachedCriteria.forClass(Goods.class);
if(cid!=null){
dc.add(Restrictions.eq("classify.cid",Integer.parseInt(cid)));
}
dc.add(Restrictions.eq("goodsStatus",0));
List<Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public int searchFoundGoodCount(Map<Object, String> map) {
StringBuffer br=new StringBuffer();
StringBuffer order=new StringBuffer();
String cid=map.get("cid");
String count_hql="select count(*) from Product where goodsstatus='1'";
if(cid!=null){
br.append(" and classify.cid='"+Integer.parseInt(cid)+"'");
}
List<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public Goods getLostGoodDetail(String id) {
int pid=0;
if(id!=null&&id!=""){
pid=Integer.parseInt(id);
}
String hql=" from Product where id=?";
List<Goods> list=this.getHibernateTemplate().find(hql,pid);
if(list.size()>0){
Goods p=list.get(0);
return p;
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public Goods getFoundGoodDetail(String id) {
int pid=0;
if(id!=null&&id!=""){
pid=Integer.parseInt(id);
}
String hql=" from Product where id=?";
List<Goods> list=this.getHibernateTemplate().find(hql,pid);
if(list.size()>0){
Goods p=list.get(0);
return p;
}
return null;
}
@Override
public Classify getClassifyById(Integer classifyId) {
String hql="from Classify where cid=?";
@SuppressWarnings("unchecked")
List<Classify> c=this.getHibernateTemplate().find(hql, classifyId);
if(c.size()>0){
Classify cla=c.get(0);
return cla;
}
return null;
}
@Override
public User getUserById(Integer creatorId) {
String hql="from User where uid=?";
@SuppressWarnings("unchecked")
List<User> u=this.getHibernateTemplate().find(hql, creatorId);
if(u.size()>0){
User user=u.get(0);
return user;
}
return null;
}
/*@Override
public void updateProduct(Product product) {
this.getHibernateTemplate().update(product);
}*/
/**
* <p>Description: </p>
* @param parseInt
* @return
*/
@SuppressWarnings("unchecked")
@Override
public int searchMyLostGoodCount(int uid) {
String hql="select count(*) from Product where user.uid = ? and goodsstatus='0'";
List<Long> list=this.getHibernateTemplate().find(hql,uid);
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@SuppressWarnings("unchecked")
@Override
public int searchMyFoundGoodCount(int uid) {
String hql="select count(*) from Product where user.uid = ? and goodsstatus='1'";
List<Long> list=this.getHibernateTemplate().find(hql,uid);
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
/**
* <p>Description: </p>
* @param map
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<Goods> getMyLostGoodList(Map<Object, String> map) {
DetachedCriteria dc=DetachedCriteria.forClass(model.Goods.class);
dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId"))));
dc.add(Restrictions.eq("goodsstatus",0));
dc.addOrder(Order.desc("createTime"));
List<model.Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
@SuppressWarnings("unchecked")
@Override
public List<Goods> getMyFoundGoodList(Map<Object, String> map) {
DetachedCriteria dc=DetachedCriteria.forClass(model.Goods.class);
dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId"))));
dc.add(Restrictions.eq("goodsstatus",1));
dc.addOrder(Order.desc("createTime"));
List<model.Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
* <p>Description: </p>
* @param pid
*/
@Override
public void delectGoodById(int pid) {
Goods good=this.getHibernateTemplate().get(Goods.class, pid);
if(good!=null){
this.getHibernateTemplate().delete(good);
}
}
/**
* <p>Description: </p>
* @param map
* @return
*/
/*@Override
public void saveUserMessage(UserAdmin uaa) {
this.getHibernateTemplate().save(uaa);
}
@SuppressWarnings("unchecked")
@Override
public int searchMessageCount(int uid, String flag) {
StringBuffer sb=new StringBuffer();
String hql="select count(*) from UserAndAdmin where 1=1 ";
if(flag=="0"||"0".equals(flag)){
sb.append(" and status='0' and userId="+uid);
}else{
sb.append(" and status='1' and userId="+uid);
}
List<Long> list=this.getHibernateTemplate().find(hql+sb.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@SuppressWarnings("unchecked")
@Override
public List<UserAdmin> getMessageList(Map<Object, String> map) {
DetachedCriteria dc=DetachedCriteria.forClass(model.UserAdmin.class);
String flag=map.get("flag");
if(flag=="0"||"0".equals(flag)){
dc.add(Restrictions.eq("userId",Integer.parseInt( map.get("userId"))));
dc.add(Restrictions.eq("status",0));
}else{
dc.add(Restrictions.eq("userId",Integer.parseInt( map.get("userId"))));
dc.add(Restrictions.eq("status",1));
}
List<model.UserAdmin> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}*/
/**
* id
*/
@Override
public void deleteMessage(int id) {
String hql="delete from UserAndAdmin where id="+id;
SessionFactory factory=this.getHibernateTemplate().getSessionFactory();
Session session=factory.openSession();
Query query=session.createQuery(hql);
query.executeUpdate();
session.close();
}
}

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="model.TClassify" table="t_classify" catalog="lostfound">
<id name="cid" type="java.lang.Integer">
<column name="CID" />
<generator class="identity" />
</id>
<property name="cname" type="java.lang.String">
<column name="CNAME" />
</property>
<property name="csort" type="java.lang.Integer">
<column name="CSORT" />
</property>
<set name="TGoodses" inverse="true">
<key>
<column name="classify_id" />
</key>
<one-to-many class="model.TGoods" />
</set>
</class>
</hibernate-mapping>

@ -0,0 +1,57 @@
package model;
import java.util.HashSet;
import java.util.Set;
/**
* TClassify entity. @author MyEclipse Persistence Tools
*/
public class Classify implements java.io.Serializable {
// Fields
private Integer cid;
private String cname;
private Integer csort;
// Constructors
/** default constructor */
public Classify() {
}
/** full constructor */
public Classify(String cname, Integer csort) {
this.cname = cname;
this.csort = csort;
}
// Property accessors
public Integer getCid() {
return this.cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCname() {
return this.cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public Integer getCsort() {
return this.csort;
}
public void setCsort(Integer csort) {
this.csort = csort;
}
}

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="model.Goods" table="t_goods" catalog="lostfound">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<many-to-one name="user" class="model.User" fetch="select">
<column name="creator_id" not-null="true" />
</many-to-one>
<many-to-one name="classify" class="model.Classify" fetch="select">
<column name="classify_id" />
</many-to-one>
<property name="goodsdescribe" type="java.lang.String">
<column name="goodsdescribe" />
</property>
<property name="goodsname" type="java.lang.String">
<column name="goodsname" length="30" />
</property>
<property name="goodsstatus" type="java.lang.Integer">
<column name="goodsstatus" not-null="true" />
</property>
<property name="goodstime" type="java.sql.Timestamp">
<column name="goodstime" length="19" />
</property>
<property name="area" type="java.lang.String">
<column name="area" length="30" />
</property>
<property name="contact" type="java.lang.String">
<column name="contact" length="30" />
</property>
<property name="qq" type="java.lang.String">
<column name="qq" length="30" />
</property>
<property name="picture" type="java.lang.String">
<column name="picture" length="255" />
</property>
<property name="createTime" type="java.sql.Timestamp">
<column name="createtime" length="19" />
</property>
</class>
</hibernate-mapping>

@ -0,0 +1,168 @@
package model;
import java.sql.Timestamp;
import java.util.Date;
/**
* TGoods entity. @author MyEclipse Persistence Tools
*/
public class Goods implements java.io.Serializable {
// Fields
private Integer id;
private User user;
private Classify classify;
private String goodsdescribe;
private String goodsname;
private Integer goodsstatus;//区分招领和寻物
private Date goodstime;//什么时候捡到的、丢的
private String area;
private String contact;//联系人姓名
private String qq;
private String picture;
private Date createTime;
private Integer creatorId;//发布者id
private Integer classifyId;//分类id
// Constructors
/** default constructor */
public Goods() {
}
/** minimal constructor */
/*public Goods(Integer id, User TUser, Integer goodsstatus) {
this.id = id;
this.User = TUser;
this.goodsstatus = goodsstatus;
}
/** full constructor */
/*public Goods(Integer id, User TUser, Classify TClassify,
String goodsdescribe, String goodsname, Integer goodsstatus,
Timestamp goodstime, String area, String contact, String qq) {
this.id = id;
this.TUser = TUser;
this.TClassify = TClassify;
this.goodsdescribe = goodsdescribe;
this.goodsname = goodsname;
this.goodsstatus = goodsstatus;
this.goodstime = goodstime;
this.area = area;
this.contact = contact;
this.qq = qq;
}*/
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public String getGoodsdescribe() {
return this.goodsdescribe;
}
public void setGoodsdescribe(String goodsdescribe) {
this.goodsdescribe = goodsdescribe;
}
public String getGoodsname() {
return this.goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
public Integer getGoodsstatus() {
return this.goodsstatus;
}
public void setGoodsstatus(Integer goodsstatus) {
this.goodsstatus = goodsstatus;
}
public Date getGoodstime() {
return this.goodstime;
}
public void setGoodstime(Timestamp goodstime) {
this.goodstime = goodstime;
}
public String getArea() {
return this.area;
}
public void setArea(String area) {
this.area = area;
}
public String getContact() {
return this.contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getQq() {
return this.qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public Integer getCreatorId() {
return creatorId;
}
public void setCreatorId(Integer creatorId) {
this.creatorId = creatorId;
}
public Integer getClassifyId() {
return classifyId;
}
public void setClassifyId(Integer classifyId) {
this.classifyId = classifyId;
}
public Classify getClassify() {
return classify;
}
public void setClassify(Classify classify) {
this.classify = classify;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

@ -0,0 +1,118 @@
package model;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}

@ -0,0 +1,47 @@
package model;
import java.util.List;
public class PageBean<T> {
private int currPage;//当前页
private int pageSize;//每页记录数
private int totalCount;//总记录数
private int totalPage;//总页数
List<T> list;//每页显示的数据
public PageBean() {
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
}

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="model.TUser" table="t_user" catalog="lostfound">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="username" type="java.lang.String">
<column name="username" />
</property>
<property name="sex" type="java.lang.Integer">
<column name="SEX" />
</property>
<property name="phone" type="java.lang.String">
<column name="PHONE" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="qusetion" type="java.lang.String">
<column name="QUSETION" />
</property>
<property name="answer" type="java.lang.String">
<column name="ANSWER" />
</property>
<set name="TGoodses" inverse="true">
<key>
<column name="user_id" not-null="true" />
</key>
<one-to-many class="model.TGoods" />
</set>
</class>
</hibernate-mapping>

@ -0,0 +1,95 @@
package model;
import java.util.HashSet;
import java.util.Set;
/**
* TUser entity. @author MyEclipse Persistence Tools
*/
public class User implements java.io.Serializable {
// Fields
private Integer id;
private String username;
private Integer sex;
private String phone;
private String password;
private String qusetion;
private String answer;
// Constructors
/** default constructor */
public User() {
}
/** full constructor */
public User(String username, String password,String qusetion, String answer) {
this.username = username;
this.password = password;
this.qusetion = qusetion;
this.answer = answer;
}
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public Integer getSex() {
return this.sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getQusetion() {
return this.qusetion;
}
public void setQusetion(String qusetion) {
this.qusetion = qusetion;
}
public String getAnswer() {
return this.answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}

@ -0,0 +1,53 @@
package service;
//import model.Admin;
import model.User;
public interface ILoginService {
/**
*
* @param user
* @return
*/
User findByUser(User user);
/**
*
* @param admin
* @return
*/
//Admin findByAdmin(Admin admin);
/**
*
* @param userName
* @return
*/
User findUserByName(String userName);
/**
*
* @param user
*/
void saveUser(User user);
/**
*
* @param user
*/
void updatePed(User user);
/**
* id
* @param uid
* @return
*/
User searchUserInfoById(int uid);
/**
*
* @param user
*/
void updateUser(User user);
}

@ -0,0 +1,95 @@
package service;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.PageBean;
import model.Goods;
import model.User;
//import model.UserAdmin;
public interface IUserService {
/**
*
* @param product
*/
void saveGood(Goods good);
/**
*
* @return
*/
List<Classify> searchClassifyList();
/**
*
* @param map
* @return
*/
PageBean<Goods> searchLostGoodList(Map<Object, String> map);
PageBean<Goods> searchFoundGoodList(Map<Object, String> map);
/**
*
* @param id
* @return
*/
Goods getLostGoodDetail(String id);
Goods getFoundGoodDetail(String id);
/**
* id
* @param classifyId
*/
Classify getClassifyById(Integer classifyId);
User getUserById(Integer creatorId);
/*void updateProduct(Product product);*/
/**
* <p>Description: </p>
* @param map
* @return
*/
PageBean<Goods> searchMyLostGoodByPage(Map<Object, String> map);
PageBean<Goods> searchMyFoundGoodByPage(Map<Object, String> map);
/**
* <p>Description: </p>
* @param pid
*/
void delectGoodById(int pid);
/**
*
* @param uaa
*/
//void saveUserMessage(UserAdmin uaa);
/**
*
* @throws Exception
* @param flag 0,1
*/
//PageBean<UserAdmin> searchMessageByPage(Map<Object, String> map);
/**
* id
* @param parseInt
*/
void deleteMessage(int id);
}

@ -0,0 +1,79 @@
package service.impl;
import org.springframework.transaction.annotation.Transactional;
import dao.ILoginDao;
//import model.Admin;
import model.User;
import service.ILoginService;
@Transactional
public class LoginService implements ILoginService{
private ILoginDao iLoginDao;
public void setiLoginDao(ILoginDao iLoginDao) {
this.iLoginDao = iLoginDao;
}
/**
*
*/
@Override
public User findByUser(User user) {
return iLoginDao.findByUser(user);
}
/**
*
*/
/* @Override
public Admin findByAdmin(Admin admin) {
return iLoginDao.findByAdmin(admin);
}*/
/**
*
*/
@Override
public User findUserByName(String userName) {
return this.iLoginDao.findUserByName(userName);
}
/**
*
*/
@Override
public void saveUser(User user) {
this.iLoginDao.saveUser(user);
}
/**
*
*/
@Override
public void updatePed(User user) {
this.iLoginDao.updatePed(user);
}
/**
* id
*/
@Override
public User searchUserInfoById(int uid) {
return this.iLoginDao.searchUserInfoById(uid);
}
/**
*
*/
@Override
public void updateUser(User user) {
this.iLoginDao.updateUser(user);
}
}

@ -0,0 +1,264 @@
package service.impl;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.PageBean;
import model.Goods;
import model.User;
//import model.UserAdmin;
import org.springframework.transaction.annotation.Transactional;
import service.IUserService;
import dao.IUserDao;
@Transactional
public class UserService implements IUserService {
private IUserDao iUserDao;
public void setiUserDao(IUserDao iUserDao) {
this.iUserDao = iUserDao;
}
Integer currPage=1;
/**
*
*/
@Override
public void saveGood(Goods good) {
this.iUserDao.saveGood(good);
}
/**
*
*/
@Override
public List<Classify> searchClassifyList() {
return this.iUserDao.searchClassifyList();
}
/**
*
*/
@Override
public PageBean<Goods> searchLostGoodList(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=12;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchLostGoodCount(map);
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.searchLostGoodList(map);
pageBean.setList(list);
return pageBean;
}
@Override
public PageBean<Goods> searchFoundGoodList(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=12;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchFoundGoodCount(map);
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.searchFoundGoodList(map);
pageBean.setList(list);
return pageBean;
}
/**
*
*/
@Override
public Goods getLostGoodDetail(String id) {
return this.iUserDao.getLostGoodDetail(id);
}
@Override
public Goods getFoundGoodDetail(String id) {
return this.iUserDao.getFoundGoodDetail(id);
}
@Override
public Classify getClassifyById(Integer classifyId) {
return this.iUserDao.getClassifyById(classifyId);
}
@Override
public User getUserById(Integer creatorId) {
return this.iUserDao.getUserById(creatorId);
}
/*@Override
public void updateProduct(Product product) {
this.iUserDao.updateProduct(product);
}*/
/**
* <p>Description: </p>
* @param map
* @return
*/
@Override
public PageBean<Goods> searchMyLostGoodByPage(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=5;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchMyLostGoodCount(Integer.parseInt(map.get("userId")));
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.getMyLostGoodList(map);
pageBean.setList(list);
return pageBean;
}
public PageBean<Goods> searchMyFoundGoodByPage(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=5;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchMyFoundGoodCount(Integer.parseInt(map.get("userId")));
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.getMyFoundGoodList(map);
pageBean.setList(list);
return pageBean;
}
/**
* <p>Description: </p>
* @param pid
*/
@Override
public void delectGoodById(int pid) {
this.iUserDao.delectGoodById(pid);
}
/**
*
* @param uaa
*/
/* @Override
public void saveUserMessage(UserAdmin uaa) {
this.iUserDao.saveUserMessage(uaa);
}
/**
*
* @throws Exception
* @param flag 0,1
*/
/* @Override
public PageBean<UserAdmin> searchMessageByPage(Map<Object, String> map) {
PageBean<UserAdmin> pageBean=new PageBean<UserAdmin>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=10;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchMessageCount(Integer.parseInt(map.get("userId")),map.get("flag"));
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<UserAdmin> list=this.iUserDao.getMessageList(map);
pageBean.setList(list);
return pageBean;
}*/
/**
* id
*/
@Override
public void deleteMessage(int id) {
this.iUserDao.deleteMessage(id);
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_3_CORE"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/mysql-connector-java-5.1.47.jar"/>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>

@ -0,0 +1,25 @@
#MyEclipse Hibernate Properties
#Sat Jan 04 23:52:24 CST 2020
sessionFactoryName=hib.HibernateSessionFactory
genBasicCompId=false
profile=
daoSFId=
version=3.3
jndiPath=
detectM2M=false
reStrategyClass=
detectO2O=false
springDaoFile=
useJavaTypes=true
keyGenerator=
libInstallFolder=WebRoot/WEB-INF/lib
addLibs2Project=true
genVersionTag=false
sessionFactoryId=
basePersistenceClass=
genAnnotations=false
reSettingsFile=
configFile=/pagebean/src/hibernate.cfg.xml
createConfigFile=true
addLibs2Classpath=true
baseDaoClass=BaseHibernateDAO

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-module
type="WEB"
name="pagebean"
id="myeclipse.1578151183785"
context-root="/pagebean"
j2ee-spec="5.0"
archive="pagebean.war">
<attributes>
<attribute name="webrootdir" value="WebRoot" />
</attributes>
</project-module>

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>pagebean</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.hibernate.HibernateBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
<nature>com.genuitec.eclipse.hibernate.hibernatenature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
</natures>
</projectDescription>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="WebRoot"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

@ -0,0 +1,12 @@
#Sat Jan 04 23:57:23 CST 2020
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="pagebean">
<wb-resource deploy-path="/" source-path="/WebRoot"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="/pagebean"/>
<property name="java-output-path" value="/pagebean/WebRoot/WEB-INF/classes"/>
</wb-module>
</project-modules>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.5"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="hib.Products" table="products" catalog="myday">
<composite-id name="id" class="hib.ProductsId">
<key-property name="proId" type="java.lang.Integer">
<column name="proId" />
</key-property>
<key-property name="userId" type="java.lang.Integer">
<column name="userId" />
</key-property>
<key-property name="proName" type="java.lang.String">
<column name="proName" />
</key-property>
<key-property name="contact" type="java.lang.String">
<column name="contact" />
</key-property>
<key-property name="price" type="java.lang.Float">
<column name="price" precision="12" scale="0" />
</key-property>
<key-property name="oprice" type="java.lang.Float">
<column name="oprice" precision="12" scale="0" />
</key-property>
<key-property name="type" type="java.lang.Integer">
<column name="type" />
</key-property>
<key-property name="classifyId" type="java.lang.Integer">
<column name="classifyId" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/myday
</property>
<property name="connection.username">root</property>
<property name="connection.password">mysql123</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">myday</property>
<mapping resource="hib/Products.hbm.xml" />
</session-factory>
</hibernate-configuration>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

@ -0,0 +1,26 @@
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
</body>
</html>

@ -0,0 +1,42 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>Insert title here</title>
</head>
<body>
<%-- 构建分页导航 --%>
共有${requestScope.pageBean.totalRecord}条信息,共${requestScope.pageBean.totalPage }页,当前为${requestScope.pageBean.pageNum}页
<br/>
<c:choose>
<c:when test="${requestScope.pageBean.pageNum != 1 }"><!-- 如果当前页为1则不显示首页和上一页 -->
<a href="${pageContext.request.contextPath}/FindAllWithPage?pageNum=1">首页</a>
<a href="${pageContext.request.contextPath}/FindAllWithPage?pageNum=${requestScope.pageBean.pageNum-1 }">上一页</a>
</c:when>
</c:choose>
<!-- 遍历页码 -->
<c:forEach begin="${requestScope.pageBean.start}" end="${requestScope.pageBean.end}" step="1" var="i">
<c:choose>
<c:when test="${requestScope.pageBean.pageNum == i}"><!-- 如果为当前页,则特殊显示 -->
<a style="height:24px; margin:0 3px; border:none;">${i}</a>
</c:when>
<c:otherwise><!-- 否则,普通显示 -->
<a href="?pageNum=${i}">${i}</a>
</c:otherwise>
</c:choose>
</c:forEach>
<c:choose>
<c:when test="${requestScope.pageBean.pageNum != requestScope.pageBean.totalPage }"><!-- 如果当前页为总的记录数,则不显示末页和下一页 -->
<a href="${pageContext.request.contextPath}/FindAllWithPage?pageNum=${requestScope.pageBean.pageNum+1 }">下一页</a>
<a href="${pageContext.request.contextPath}/FindAllWithPage?pageNum=${requestScope.pageBean.totalPage }">末页</a>
</c:when>
</c:choose>
<%--尾页 --%>
<a href="${pageContext.request.contextPath}/FindAllWithPage?pageNum=${requestScope.pageBean.totalPage}">尾页</a>
</body>
</html>

@ -0,0 +1,31 @@
package action;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.PageBean;
import service.ProductService;
public class ProductAction {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int pageNum = Integer.valueOf(request.getParameter("pageNum"));
int pageSize=10;
ProductService ps = new ProductService();
//获取一个PageBean对象
PageBean pb = ps.showAllProductWithPage(pageNum, pageSize);
//将pb放入request域中
request.setAttribute("pageBean",pb);
request.getRequestDispatcher("/page.jsp").forward(request,response);
}
}

@ -0,0 +1,35 @@
package dao;
/**
* AbstractProducts entity provides the base persistence definition of the
* Products entity. @author MyEclipse Persistence Tools
*/
public abstract class AbstractProducts implements java.io.Serializable {
// Fields
private ProductsId id;
// Constructors
/** default constructor */
public AbstractProducts() {
}
/** full constructor */
public AbstractProducts(ProductsId id) {
this.id = id;
}
// Property accessors
public ProductsId getId() {
return this.id;
}
public void setId(ProductsId id) {
this.id = id;
}
}

@ -0,0 +1,173 @@
package dao;
/**
* AbstractProductsId entity provides the base persistence definition of the
* ProductsId entity. @author MyEclipse Persistence Tools
*/
public abstract class AbstractProductsId implements java.io.Serializable {
// Fields
private Integer proId;
private Integer userId;
private String proName;
private String contact;
private Float price;
private Float oprice;
private Integer type;
private Integer classifyId;
// Constructors
/** default constructor */
public AbstractProductsId() {
}
/** minimal constructor */
public AbstractProductsId(Integer proId, Integer userId) {
this.proId = proId;
this.userId = userId;
}
/** full constructor */
public AbstractProductsId(Integer proId, Integer userId, String proName,
String contact, Float price, Float oprice, Integer type,
Integer classifyId) {
this.proId = proId;
this.userId = userId;
this.proName = proName;
this.contact = contact;
this.price = price;
this.oprice = oprice;
this.type = type;
this.classifyId = classifyId;
}
// Property accessors
public Integer getProId() {
return this.proId;
}
public void setProId(Integer proId) {
this.proId = proId;
}
public Integer getUserId() {
return this.userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getProName() {
return this.proName;
}
public void setProName(String proName) {
this.proName = proName;
}
public String getContact() {
return this.contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public Float getPrice() {
return this.price;
}
public void setPrice(Float price) {
this.price = price;
}
public Float getOprice() {
return this.oprice;
}
public void setOprice(Float oprice) {
this.oprice = oprice;
}
public Integer getType() {
return this.type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getClassifyId() {
return this.classifyId;
}
public void setClassifyId(Integer classifyId) {
this.classifyId = classifyId;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof AbstractProductsId))
return false;
AbstractProductsId castOther = (AbstractProductsId) other;
return ((this.getProId() == castOther.getProId()) || (this.getProId() != null
&& castOther.getProId() != null && this.getProId().equals(
castOther.getProId())))
&& ((this.getUserId() == castOther.getUserId()) || (this
.getUserId() != null && castOther.getUserId() != null && this
.getUserId().equals(castOther.getUserId())))
&& ((this.getProName() == castOther.getProName()) || (this
.getProName() != null && castOther.getProName() != null && this
.getProName().equals(castOther.getProName())))
&& ((this.getContact() == castOther.getContact()) || (this
.getContact() != null && castOther.getContact() != null && this
.getContact().equals(castOther.getContact())))
&& ((this.getPrice() == castOther.getPrice()) || (this
.getPrice() != null && castOther.getPrice() != null && this
.getPrice().equals(castOther.getPrice())))
&& ((this.getOprice() == castOther.getOprice()) || (this
.getOprice() != null && castOther.getOprice() != null && this
.getOprice().equals(castOther.getOprice())))
&& ((this.getType() == castOther.getType()) || (this.getType() != null
&& castOther.getType() != null && this.getType()
.equals(castOther.getType())))
&& ((this.getClassifyId() == castOther.getClassifyId()) || (this
.getClassifyId() != null
&& castOther.getClassifyId() != null && this
.getClassifyId().equals(castOther.getClassifyId())));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getProId() == null ? 0 : this.getProId().hashCode());
result = 37 * result
+ (getUserId() == null ? 0 : this.getUserId().hashCode());
result = 37 * result
+ (getProName() == null ? 0 : this.getProName().hashCode());
result = 37 * result
+ (getContact() == null ? 0 : this.getContact().hashCode());
result = 37 * result
+ (getPrice() == null ? 0 : this.getPrice().hashCode());
result = 37 * result
+ (getOprice() == null ? 0 : this.getOprice().hashCode());
result = 37 * result
+ (getType() == null ? 0 : this.getType().hashCode());
result = 37
* result
+ (getClassifyId() == null ? 0 : this.getClassifyId()
.hashCode());
return result;
}
}

@ -0,0 +1,16 @@
package dao;
import org.hibernate.Session;
/**
* Data access object (DAO) for domain model
* @author MyEclipse Persistence Tools
*/
public class BaseHibernateDAO implements IBaseHibernateDAO {
public Session getSession() {
return HibernateSessionFactory.getSession();
}
}

@ -0,0 +1,118 @@
package dao;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}

@ -0,0 +1,12 @@
package dao;
import org.hibernate.Session;
/**
* Data access interface for domain model
* @author MyEclipse Persistence Tools
*/
public interface IBaseHibernateDAO {
public Session getSession();
}

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="hib.Products" table="products" catalog="myday">
<composite-id name="id" class="hib.ProductsId">
<key-property name="proId" type="java.lang.Integer">
<column name="proId" />
</key-property>
<key-property name="userId" type="java.lang.Integer">
<column name="userId" />
</key-property>
<key-property name="proName" type="java.lang.String">
<column name="proName" />
</key-property>
<key-property name="contact" type="java.lang.String">
<column name="contact" />
</key-property>
<key-property name="price" type="java.lang.Float">
<column name="price" precision="12" scale="0" />
</key-property>
<key-property name="oprice" type="java.lang.Float">
<column name="oprice" precision="12" scale="0" />
</key-property>
<key-property name="type" type="java.lang.Integer">
<column name="type" />
</key-property>
<key-property name="classifyId" type="java.lang.Integer">
<column name="classifyId" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

@ -0,0 +1,19 @@
package dao;
/**
* Products entity. @author MyEclipse Persistence Tools
*/
public class Products extends AbstractProducts implements java.io.Serializable {
// Constructors
/** default constructor */
public Products() {
}
/** full constructor */
public Products(ProductsId id) {
super(id);
}
}

@ -0,0 +1,135 @@
package dao;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A data access object (DAO) providing persistence and search support for
* Products entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see hib.Products
* @author MyEclipse Persistence Tools
*/
public class ProductsDAO extends BaseHibernateDAO {
private static final Logger log = LoggerFactory
.getLogger(ProductsDAO.class);
// property constants
public void save(Products transientInstance) {
log.debug("saving Products instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Products persistentInstance) {
log.debug("deleting Products instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Products findById(dao.ProductsId id) {
log.debug("getting Products instance with id: " + id);
try {
Products instance = (Products) getSession().get("hib.Products", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Products instance) {
log.debug("finding Products instance by example");
try {
List results = getSession().createCriteria("hib.Products")
.add(Example.create(instance)).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Products instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Products as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findAll() {
log.debug("finding all Products instances");
try {
String queryString = "from Products";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Products merge(Products detachedInstance) {
log.debug("merging Products instance");
try {
Products result = (Products) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Products instance) {
log.debug("attaching dirty Products instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Products instance) {
log.debug("attaching clean Products instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}

@ -0,0 +1,27 @@
package dao;
/**
* ProductsId entity. @author MyEclipse Persistence Tools
*/
public class ProductsId extends AbstractProductsId implements
java.io.Serializable {
// Constructors
/** default constructor */
public ProductsId() {
}
/** minimal constructor */
public ProductsId(Integer proId, Integer userId) {
super(proId, userId);
}
/** full constructor */
public ProductsId(Integer proId, Integer userId, String proName,
String contact, Float price, Float oprice, Integer type,
Integer classifyId) {
super(proId, userId, proName, contact, price, oprice, type, classifyId);
}
}

@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/myday
</property>
<property name="connection.username">root</property>
<property name="connection.password">mysql123</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">myday</property>
<mapping resource="hib/Products.hbm.xml" />
</session-factory>
</hibernate-configuration>

@ -0,0 +1,129 @@
package model;
import java.util.List;
public class PageBean<T> {
private int pageNum; //当前页,从请求那边传过来。
private int pageSize; //每页显示的数据条数。
private int totalRecord; //总的记录条数。查询数据库得到的数据
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
//需要计算得来
private int totalPage; //总页数通过totalRecord和pageSize计算可以得来
//开始索引也就是我们在数据库中要从第几行数据开始拿有了startIndex和pageSize
//就知道了limit语句的两个数据就能获得每页需要显示的数据了
private int startIndex;
//将每页要显示的数据放在list集合中
private List<T> list;
//分页显示的页数,比如在页面上显示12345页start就为1end就为5这个也是算过来的
private int start;
private int end;
//通过pageNumpageSizetotalRecord计算得来tatalPage和startIndex
//构造方法中将pageNumpageSizetotalRecord获得
public PageBean(int pageNum,int pageSize,int totalRecord) {
this.pageNum = pageNum;
this.pageSize = pageSize;
this.totalRecord = totalRecord;
//totalPage 总页数
if(totalRecord%pageSize==0){
//说明整除正好每页显示pageSize条数据没有多余一页要显示少于pageSize条数据的
this.totalPage = totalRecord / pageSize;
}else{
//不整除,就要在加一页,来显示多余的数据。
this.totalPage = totalRecord / pageSize +1;
}
//开始索引
this.startIndex = (pageNum-1)*pageSize ;
//显示5页
this.start = 1;
this.end = 5;
//显示页数的算法
if(totalPage <=5){
//总页数都小于5那么end就为总页数的值了。
this.end = this.totalPage;
}else{
//总页数大于5那么就要根据当前是第几页来判断start和end为多少了
this.start = pageNum - 2;
this.end = pageNum + 2;
if(start <= 0){
//比如当前页是第1页或者第2页那么就不符合这个规则
this.start = 1;
this.end = 5;
}
if(end > this.totalPage){
//比如当前页是倒数第2页或者最后一页也同样不符合上面这个规则
this.end = totalPage;
this.start = end - 5;
}
}
}
}

@ -0,0 +1,56 @@
package model;
public class Product {
private int proId;
private int userId;
private String proName; //物品名称
private String contact; //卖家联系方式
private float price; //转卖价
private float oprice; //原价
private int classifyId; //分类
private int type;
public int getProId() {
return proId;
}
public void setProId(int proId) {
this.proId = proId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getProName() {
return proName;
}
public void setProName(String proName) {
this.proName = proName;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public float getOprice() {
return oprice;
}
public void setOprice(float oprice) {
this.oprice = oprice;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}

@ -0,0 +1,27 @@
package service;
import dao.ProductsDAO;
import java.util.List;
import model.PageBean;
import model.Product;
public class ProductService {
@SuppressWarnings("unchecked")
public PageBean<Product> showAllProductWithPage(int pageNum,int pageSize){
ProductsDAO pro=new ProductsDAO();
List<Product> allProduct = pro.findAll();
int totalRecord = allProduct.size();
PageBean pb= new PageBean(pageNum,pageSize,totalRecord);
int startIndex = pb.getStartIndex();
// pb.setList(ProductsDAO.findAll(startIndex,pageSize));
pb.setList(pro.findAll());
return pb;
}
}
Loading…
Cancel
Save