扫一扫,关注我们
微信号:375279829
需要代码段如下:
用户登入注册及我的信息里修改信息代码
登录:
public String userLogin()
{
String sql="from TUser where userName=? and userPw=?";
Object[] con={userName,userPw};
List userList=userDAO.getHibernateTemplate().find(sql,con);
if(userList.size()==0)
{
this.setMessage("用户名或密码错误");
this.setPath("qiantai/default.jsp");
}
else
{
Map session= ServletActionContext.getContext().getSession();
TUser user=(TUser)userList.get(0);
session.put("user", user);
session.put("userid", user.getUserId());
session.put("userjifen", user.getUserJifen());
session.put("username", user.getUserName());
session.put("userage", user.getUserAge());
session.put("userman", user.getUserMan());
this.setMessage("成功登录");
this.setPath("qiantai/default.jsp");
}
return "succeed";
}
注册
public String userReg()
{
TUser user=new TUser();
user.setUserName(userName);
user.setUserPw(userPw);
user.setUserAddress(userAddress);
user.setUserTel(userTel);
user.setUserRealname(userRealname);
user.setUserEmail(userEmail);
user.setUserSex(userSex);
user.setUserAge(userAge);
user.setUserMan(userMan);
user.setUserPic(userPic);
user.setUserDel("no");
userDAO.save(user);
Map session= ServletActionContext.getContext().getSession();
session.put("user", user);
return "successAdd";
}
我的信息里修改信息
public String userEdit()
{
TUser user=userDAO.findById(userId);
user.setUserName(userName);
user.setUserPw(userPw);
user.setUserAddress(userAddress);
user.setUserTel(userTel);
user.setUserRealname(userRealname);
user.setUserEmail(userEmail);
user.setUserSex(userSex);
user.setUserAge(userAge);
user.setUserMan(userMan);
user.setUserPic(userPic);
user.setUserDel("no");
userDAO.attachDirty(user);
Map session= ServletActionContext.getContext().getSession();
session.put("user", user);
session.put("userid", user.getUserId());
session.put("userjifen", user.getUserJifen());
session.put("username", user.getUserName());
session.put("userage", user.getUserAge());
session.put("userman", user.getUserMan());
return "successAdd";
}
添加图书
public String bookinfoNAdd()
{
TBookinfo bookinfo=new TBookinfo();
bookinfo.setBookinfoCatelogId(bookinfoCatelogId);
bookinfo.setBookinfoName(bookinfoName);
bookinfo.setBookinfoMiaoshu(bookinfoMiaoshu);
bookinfo.setBookinfoPic(fujian);
bookinfo.setBookinfoFavs(bookinfoFavs);
bookinfo.setBookinfoLeibie(bookinfoLeibie);
bookinfo.setBookinfoMaterial(bookinfoMaterial);
bookinfo.setBookinfoStatus("no");
Map session= ServletActionContext.getContext().getSession();
TUser user=(TUser)session.get("user");
bookinfo.setBookinfoUser(user.getUserId());
bookinfo.setBookinfoDel("no");
bookinfoDAO.save(bookinfo);
this.setMessage("操作成功");
this.setPath("bookinfoMyList.action");
return "succeed";
}
个人书库
public String bookinfoMyList()
{
Map session= ServletActionContext.getContext().getSession();
TUser user=(TUser)session.get("user");
String sql="from TBookinfo where bookinfoDel='no' and bookinfoUser="+user.getUserId()+" order by bookinfoId";
List bookinfoList=bookinfoDAO.getHibernateTemplate().find(sql);
int listSize=bookinfoList.size();
int fromIndex = (pageNow - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, listSize);
pageTotle = listSize%pageSize==0?listSize/pageSize:listSize/pageSize+1 ;
bookinfoList = bookinfoList.subList(fromIndex, toIndex);
for(int i=0;i<bookinfoList.size();i++)
{
TBookinfo bookinfo=(TBookinfo)bookinfoList.get(i);
System.out.println(bookinfo.getBookinfoCatelogId());
bookinfo.setBookinfoCatelogName(catelogDAO.findById(bookinfo.getBookinfoCatelogId()).getCatelogName());
}
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("bookinfoList", bookinfoList);
return ActionSupport.SUCCESS;
}
已读图书
public String bookinfoMyItem()
{
Map request=(Map)ServletActionContext.getContext().get("request");
Map session= ServletActionContext.getContext().getSession();
TUser user=(TUser)session.get("user");
String sql="from TOrderItem where userId="+user.getUserId()+" order by orderItemId";
List orderItemList=orderItemDAO.getHibernateTemplate().find(sql);
int listSize=orderItemList.size();
int fromIndex = (pageNow - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, listSize);
pageTotle = listSize%pageSize==0?listSize/pageSize:listSize/pageSize+1 ;
orderItemList = orderItemList.subList(fromIndex, toIndex);
for(int i=0;i<orderItemList.size();i++)
{
TOrderItem orderItem=(TOrderItem)orderItemList.get(i);
//System.out.println(orderItem.getBookinfoId());
orderItem.setBookinfo(bookinfoDAO.findById(orderItem.getBookinfoId()));
}
request.put("orderItemList", orderItemList);
return ActionSupport.SUCCESS;
}
图书评价
public String discussAdd()
{
TDiscuss discuss=new TDiscuss();
discuss.setDiscussContent(discussContent);
//discuss.setDiscussTitle(discussTitle);
discuss.setDiscussDate(new Date().toLocaleString());
discuss.setBookinfoId(bookinfoId);
Map session=ServletActionContext.getContext().getSession();
if(session.get("user")!=null)
{
TUser user=(TUser)session.get("user");
discuss.setDiscussUser(user.getUserId());
}
discussDAO.save(discuss);
this.setMessage("操作成功");
this.setPath("bookinfoDetail.action?bookinfoId="+bookinfoId);
return "succeed";
}
图书推荐
<%
String userage= session.getAttribute("userage").toString();
String userman= session.getAttribute("userman").toString();
String sql="select t_bookinfo.* from t_bookinfo left join t_catelog on t_catelog.catelog_id=t_bookinfo.bookinfo_catelog_id where t_catelog.catelog_name='"+ userman +"' and t_bookinfo.bookinfo_leibie='"+ userage +"' ";
ResultSet rs = db1.executeQuery(sql);
System.out.println(sql);
while(rs.next())
{
%>
<tr align='center' bgcolor="#FFFFFF" height="22">
<td><%= rs.getString("bookinfo_name") %></td>
<td><%= userman %><br/></td>
<td><a href="<%=path %>/bookinfoDetail.action?bookinfoId=<%= rs.getString("bookinfo_id") %>"> <img src="<%=path %><%= rs.getString("bookinfo_pic") %>" width="60" height="60" border="0"/> </a></td>
<td><a href="<%=path %>/bookinfoDetail.action?bookinfoId=<%= rs.getString("bookinfo_id") %>">查看详细</a></td>
</tr>
<%
}
rs.close();
%>
阅读排名
public String bookinfoAllYesT()
{
Map request=(Map)ServletActionContext.getContext().get("request");
String sql="from TBookinfo where bookinfoDel='no' and bookinfoStatus='yes' order by bookinfoFavs desc";
List bookinfoYesTejiaList=bookinfoDAO.getHibernateTemplate().find(sql);
int listSize=bookinfoYesTejiaList.size();
int fromIndex = (pageNow - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, listSize);
pageTotle = listSize%pageSize==0?listSize/pageSize:listSize/pageSize+1 ;
bookinfoYesTejiaList = bookinfoYesTejiaList.subList(fromIndex, toIndex);
request.put("bookinfoYesTejiaList", bookinfoYesTejiaList);
return ActionSupport.SUCCESS;
}
我爱阅读数量增加
public String userAddBookinfo(int userId, int bookinfoId) {
String result = "no";
// Map session= ServletActionContext.getContext().getSession();
// TUser user=(TUser)session.get("user");
// int userId= user.getUserId();
String sql = "from TOrderItem where userId=? and bookinfoId=?";
Object con[] = {userId, bookinfoId};
List list = orderItemDAO.getHibernateTemplate().find(sql, con);
if (list.size() == 0) {
TOrderItem orderItem = new TOrderItem();
orderItem.setUserId(userId);
orderItem.setBookinfoId(bookinfoId);
orderItem.setOrderItemStatus("已读");
orderItemDAO.save(orderItem);
TBookinfo bookinfo = bookinfoDAO.findById(bookinfoId);
bookinfo.setBookinfoFavs(bookinfo.getBookinfoFavs()+1);
bookinfoDAO.attachDirty(bookinfo);
DB sqlherper=new DB();
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
String sql2="update t_user set user_jifen=user_jifen+1 where user_id="+session.getAttribute("userid");
sqlherper.executeMysql(sql2);
System.out.println(sql2);
result = "yes";
}
if (list.size() > 0) {
//result = "no";
TOrderItem orderItem = new TOrderItem();
orderItem.setUserId(userId);
orderItem.setBookinfoId(bookinfoId);
orderItem.setOrderItemStatus("已读");
orderItemDAO.save(orderItem);
TBookinfo bookinfo = bookinfoDAO.findById(bookinfoId);
bookinfo.setBookinfoFavs(bookinfo.getBookinfoFavs()+1);
bookinfoDAO.attachDirty(bookinfo);
DB sqlherper=new DB();
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
String sql2="update t_user set user_jifen=user_jifen+1 where user_id="+session.getAttribute("userid");
sqlherper.executeMysql(sql2);
System.out.println(sql2);
result = "yes";
}
return result;
}
管理员登入
if(userType==0)//系统管理员登陆
{
String sql="from TAdmin where userName=? and userPw=?";
Object[] con={userName,userPw};
List adminList=adminDAO.getHibernateTemplate().find(sql,con);
if(adminList.size()==0)
{
result="no";
}
else
{
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
TAdmin admin=(TAdmin)adminList.get(0);
session.setAttribute("userType", 0);
session.setAttribute("admin", admin);
result="yes";
}
}
修改个人密码
public String adminPwEdit(String userPwNew)
{
System.out.println("DDDD");
try
{
Thread.sleep(700);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
TAdmin admin=(TAdmin)session.getAttribute("admin");
admin.setUserPw(userPwNew);
adminDAO.getHibernateTemplate().update(admin);
session.setAttribute("admin", admin);
return "yes";
}
会员信息管理删除
管理
public String userMana()
{
List userList=userDAO.findAll();
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("userList", userList);
return ActionSupport.SUCCESS;
}
删除
public String userDel()
{
TUser user=userDAO.findById(userId);
user.setUserDel("yes");
userDAO.attachDirty(user);
this.setMessage("删除成功");
this.setPath("userMana.action");
return "succeed";
}
后台图书分类,
public String catelogMana()
{
String sql="from TCatelog where catelogDel='no'";
List cateLogList=catelogDAO.getHibernateTemplate().find(sql);
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("cateLogList", cateLogList);
return ActionSupport.SUCCESS;
}
public String catelogAdd()
{
TCatelog catelog=new TCatelog();
catelog.setCatelogName(catelogName);
catelog.setCatelogMiaoshu(catelogMiaoshu);
catelog.setCatelogDel("no");
catelogDAO.save(catelog);
this.setMessage("操作成功");
this.setPath("catelogMana.action");
return "succeed";
}
图书管理
public String bookinfoMana()
{
String sql="from TBookinfo where bookinfoDel='no' order by bookinfoStatus";
List bookinfoList=bookinfoDAO.getHibernateTemplate().find(sql);
int listSize=bookinfoList.size();
int fromIndex = (pageNow - 1) * pageSize;
int toIndex = Math.min(fromIndex + pageSize, listSize);
pageTotle = listSize%pageSize==0?listSize/pageSize:listSize/pageSize+1 ;
bookinfoList = bookinfoList.subList(fromIndex, toIndex);
for(int i=0;i<bookinfoList.size();i++)
{
TBookinfo bookinfo=(TBookinfo)bookinfoList.get(i);
System.out.println(bookinfo.getBookinfoCatelogId());
bookinfo.setBookinfoCatelogName(catelogDAO.findById(bookinfo.getBookinfoCatelogId()).getCatelogName());
}
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("bookinfoList", bookinfoList);
return ActionSupport.SUCCESS;
}
public String bookinfoDel()
{
TBookinfo bookinfo=bookinfoDAO.findById(bookinfoId);
bookinfo.setBookinfoDel("yes");
bookinfoDAO.attachDirty(bookinfo);
this.setMessage("操作成功");
this.setPath("bookinfoMana.action");
return "succeed";
}