文章目录
- 图书商城系统
- 一、项目演示
- 二、项目介绍
- 三、系统部分功能截图
- 四、部分代码展示
- 五、底部获取项目(9.9¥带走)
图书商城系统
一、项目演示
网上书城
二、项目介绍
基于SSM的图书商城网站
运行环境:idea或eclipse 数据库:mysql
开发语言:java
基于Spring+SpingMVC+Mybatis+jsp的校园互助管理系统
有两个角色:用户和管理员
项目功能如下:
前台功能:
-
图书基本展示,包括推荐图书展示和类图书类型展示.
-
推荐图书包括条幅推荐,热销推荐和新品推荐.
-
按照图书类型展示商品.
-
图书详细信息展示.
-
图书加入购物车.
-
修改购物车内图书信息,例如数量等.
-
用户登录.
-
用户注册.
-
修改个人信息,包括密码和收获信息.
-
购物车付款.
-
用户订单查询.
-
根据关键字搜索图书.
后台功能:
-
订单操作:包括按状态查询订单,修改订单状态(发货,完成,删除).
-
用户操作:包括查询所有用户,新增用户,修改用户密码,修改用户信息和删除用户.
-
图书类目操作:包括查看所有类目,增加图书类目,修改图书类目信息以及删除图书类目.
-
图书操作:包括查询所有图书,新增图书,修改现有图书信息以及删除图书.
三、系统部分功能截图
四、部分代码展示
package com.vilicode.controller;
import com.vilicode.bean.Book;
import com.vilicode.bean.Page;
import com.vilicode.bean.User;
import com.vilicode.mapper.RecommendMapper;
import com.vilicode.service.BookService;
import com.vilicode.service.BookTypeService;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
@Controller
public class BookController {
@Autowired
public BookService bookService;
@Autowired
public BookTypeService bookTypeService;
@RequestMapping("/recommend_books")
public String showRecommendBook(int rtype, int pageNumber, HttpServletRequest request)
{
if(pageNumber<=0)
pageNumber=1;
Page p= bookService.queryBookByRecommendType(rtype,pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p = bookService.queryBookByRecommendType(rtype,p.getTotalPage());
}
}
request.setAttribute("p", p);
request.setAttribute("t", rtype);
return "recommend_list";
}
@RequestMapping("/booktypes_list")
public String showBooksByBookTypeID(int pageNumber, int btid,HttpServletRequest request)
{
String btname="";
if(btid!=0)
{
btname=bookTypeService.queryBookTypeNameByBookTypeID(btid);
}
request.setAttribute("t",btname);
//List<Goods> list=gService.selectGoodsByTypeID(id,1,8);
//request.setAttribute("goodsList",list);
if(pageNumber<=0)
pageNumber=1;
Page p=bookTypeService.queryBookByBookTypeID(btid,pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p=bookTypeService.queryBookByBookTypeID(btid,p.getTotalPage());
}
}
request.setAttribute("p",p);
request.setAttribute("btid",btid);
return "booktypes_list";
}
@RequestMapping("/book_detail")
public String showBookByID(int bid,HttpServletRequest request)
{
Book book= bookService.queryBookByID(bid);
request.setAttribute("book",book);
return "book_detail";
}
@RequestMapping("/search_books")
public String SearchBooksByKeyword(int pageNumber,String keyword,HttpServletRequest request) throws UnsupportedEncodingException {
if(pageNumber<=0)
{
pageNumber=1;
}
Page p =bookService.searchBooksByKeyword(keyword,pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p =bookService.searchBooksByKeyword(keyword,p.getTotalPage());
}
}
request.setAttribute("p", p);
request.setAttribute("keyword", URLEncoder.encode(keyword,"utf-8"));
return "book_search";
}
@RequestMapping("/admin/type_list")
public String ShowBookTypes(HttpServletRequest request)
{
request.setAttribute("list",bookTypeService.queryBookTypes());
return "admin/type_list";
}
@RequestMapping("/admin/type_add")
public String CreateBookType(String btname,HttpServletRequest request)
{
boolean result= bookTypeService.addBookType(btname);
UpdateBookType(request);
return "redirect:type_list.action";
}
@RequestMapping("/admin/type_delete")
public String RemoveBookType(int btid,HttpServletRequest request)
{
boolean result= bookTypeService.removeBookType(btid);
UpdateBookType(request);
return "redirect:type_list.action";
}
@RequestMapping("/admin/type_update")
public String ModifyBookType(int btid,String btname,HttpServletRequest request)
{
boolean result= bookTypeService.modifyBookType(btid,btname);
UpdateBookType(request);
return "redirect:type_list.action";
}
public void UpdateBookType(HttpServletRequest request)
{
if(request.getServletContext().getAttribute("bookTypes")==null)
{
request.getServletContext().setAttribute("bookTypes",bookTypeService.queryBookTypes());
}
else
{
request.getServletContext().removeAttribute("bookTypes");
request.getServletContext().setAttribute("bookTypes",bookTypeService.queryBookTypes());
}
}
@RequestMapping("/admin/book_list")
public String ShowBookByRecommend(int pageNumber,int rtype,HttpServletRequest request)
{
if(pageNumber<=0)
pageNumber=1;
Page p = bookService.queryBookByRecommendType(rtype, pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p = bookService.queryBookByRecommendType(rtype, p.getTotalPage());
}
}
request.setAttribute("p", p);
request.setAttribute("rtype", rtype);
return "/admin/book_list";
}
@RequestMapping("/admin/book_change")
public String ChangeBookRecommend(int bid,int rtype,String method,int page)
{
boolean result=false;
if(method.equals("add")) {
result=bookService.addRecommend(bid,rtype);
}else {
result=bookService.remoteRecommend(bid,rtype);
}
return "redirect:book_list.action?pageNumber=1&rtype="+page;
}
@RequestMapping("/admin/book_delete")
public String DeleteBook(int bid,int rtype)
{
boolean result=bookService.removeBookByBid(bid);
//
return "redirect:book_list.action?pageNumber=1&rtype="+rtype;
}
@RequestMapping("/admin/book_add")
public String uploadimg(HttpServletRequest request) throws Exception{
DiskFileItemFactory factory=new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List<FileItem> list = upload.parseRequest(request);
Book b = new Book();
for(FileItem item:list) {
if(item.isFormField()) {
switch(item.getFieldName()) {
case "bname":
b.setBname(item.getString("utf-8"));
break;
case "bprice":
b.setBprice(Double.parseDouble(item.getString("utf-8")));
break;
case "bmark":
b.setBmark(item.getString("utf-8"));
break;
case "bstock":
b.setBstock(Integer.parseInt(item.getString("utf-8")));
break;
case "btid":
b.setBtid(Integer.parseInt(item.getString("utf-8")));
break;
case "bisbn":
b.setBisbn(item.getString("utf-8"));
break;
case "bauthor":
b.setBauthor(item.getString("utf-8"));
break;
case "bpublisher":
b.setBpublisher(item.getString("utf-8"));
break;
}
}else {
if(item.getInputStream().available()<=0)continue;
String fileName = item.getName();
fileName = fileName.substring(fileName.lastIndexOf("."));
fileName = "/"+new Date().getTime()+fileName;
String path = request.getServletContext().getRealPath("/images")+fileName;
InputStream in = item.getInputStream();
FileOutputStream out = new FileOutputStream(path);
byte[] buffer = new byte[1024];
int len=0;
while( (len=in.read(buffer))>0 ) {
out.write(buffer);
}
in.close();
out.close();
item.delete();
switch(item.getFieldName()) {
case "bcover":
b.setBcover("images"+fileName);
break;
case "bimage1":
b.setBimage1("images"+fileName);
break;
case "bimage2":
b.setBimage2("images"+fileName);
break;
}
}
}
bookService.addBook(b);
} catch (FileUploadException e) {
System.out.println(e.getMessage());
}
return "redirect:book_list.action?pageNumber=1&rtype=0";
}
@RequestMapping("/admin/book_edit_show")
public String ShowBookByBid(int bid,HttpServletRequest request)
{
Book b = bookService.queryBookByID(bid);
request.setAttribute("g", b);
return "admin/book_edit";
}
@RequestMapping("/admin/book_update")
public String ModifyBook(HttpServletRequest request) throws Exception {
DiskFileItemFactory factory=new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List<FileItem> list = upload.parseRequest(request);
Book b=new Book();
for(FileItem item:list) {
if(item.isFormField()) {
switch(item.getFieldName()) {
case "bid":
b.setBid(Integer.parseInt(item.getString("utf-8")));
break;
case "bname":
b.setBname(item.getString("utf-8"));
break;
case "bprice":
b.setBprice(Double.parseDouble(item.getString("utf-8")));
break;
case "bmark":
b.setBmark(item.getString("utf-8"));
break;
case "bstock":
b.setBstock(Integer.parseInt(item.getString("utf-8")));
break;
case "btid":
b.setBtid(Integer.parseInt(item.getString("utf-8")));
break;
case "bisbn":
b.setBisbn(item.getString("utf-8"));
break;
case "bauthor":
b.setBauthor(item.getString("utf-8"));
break;
case "bpublisher":
b.setBpublisher(item.getString("utf-8"));
break;
case "bcover":
b.setBcover(item.getString("utf-8"));
break;
case "bimage1":
b.setBimage1(item.getString("utf-8"));
break;
case "bimage2":
b.setBimage2(item.getString("utf-8"));
break;
}
}else {
if(item.getInputStream().available()<=0)continue;
String fileName = item.getName();
fileName = fileName.substring(fileName.lastIndexOf("."));
fileName = "/"+new Date().getTime()+fileName;
String path = request.getServletContext().getRealPath("/images")+fileName;
InputStream in = item.getInputStream();
FileOutputStream out = new FileOutputStream(path);
byte[] buffer = new byte[1024];
int len=0;
while( (len=in.read(buffer))>0 ) {
out.write(buffer);
}
in.close();
out.close();
item.delete();
switch(item.getFieldName()) {
case "bcover":
b.setBcover("images"+fileName);
break;
case "bimage1":
b.setBimage1("images"+fileName);
break;
case "bimage2":
b.setBimage2("images"+fileName);
break;
}
}
}
bookService.modifyBook(b);
//Service.update(g);
//request.getRequestDispatcher("/admin/goods_list?pageNumber="+pageNumber+"&type="+type).forward(request, response);
} catch (FileUploadException e) {
System.out.println(e.getMessage());
}
return "redirect:book_list.action?pageNumber=1&rtype=0";
}
}
package com.vilicode.controller;
import com.vilicode.bean.Book;
import com.vilicode.bean.Order;
import com.vilicode.bean.Page;
import com.vilicode.bean.User;
import com.vilicode.service.BookService;
import com.vilicode.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
@Controller
public class OrderController {
@Autowired
public BookService bookService;
@Autowired
public OrderService orderService;
@RequestMapping(value = "/books_buy")
public void AddBookToCart(@RequestParam("bid") int bid, HttpServletRequest request, HttpServletResponse response) throws IOException {
Order o = null;
if(request.getSession().getAttribute("order") != null) {
o = (Order) request.getSession().getAttribute("order");
}else {
o = new Order();
o.setOamount(0);
o.setOtotal(0.0);
request.getSession().setAttribute("order", o);
}
Book book = bookService.queryBookByID(bid);
if(book.getBstock()>0) {
o.addGoods(book);
response.getWriter().print("ok");
}else {
response.getWriter().print("fail");
}
}
@RequestMapping(value = "/books_lessen")
public void LessenBookToCart(@RequestParam("bid") int bid, HttpServletRequest request, HttpServletResponse response) throws IOException {
Order o = (Order) request.getSession().getAttribute("order");
o.lessen(bid);
response.getWriter().print("ok");
}
@RequestMapping(value = "/books_delete")
public void DeleteBookToCart(@RequestParam("bid") int bid, HttpServletRequest request, HttpServletResponse response) throws IOException {
Order o = (Order) request.getSession().getAttribute("order");
o.delete(bid);
response.getWriter().print("ok");
}
@RequestMapping(value = "/order_confirm")
public String OrderConfirm( int opaytype,HttpServletRequest request)
{
Order o = (Order) request.getSession().getAttribute("order");
o.setOstatus(2);
o.setOpaytype(opaytype);
User user=(User)request.getSession().getAttribute("user");
o.setUid(user.getUid());
o.setOrealname(user.getUrealname());
o.setOphone(user.getUphone());
o.setOaddress(user.getUaddress());
boolean result=orderService.addOrder(o);
if(result)
{
request.getSession().removeAttribute("order");
request.setAttribute("msg", "订单支付成功!");
return "order_result";
}
else
{
request.setAttribute("failmsg", "订单支付失败!");
return "order_result";
}
}
@RequestMapping("/order_submit")
public String OrderSubmit(HttpServletRequest request)
{
if(request.getSession().getAttribute("user")!=null) {
return "order_submit";
}else {
request.setAttribute("failMsg", "请登录后,再提交订单!");
return "redirect:user_login.jsp";
}
}
@RequestMapping("order_list")
public String ShowOrderByUid(HttpServletRequest request)
{
User user=(User)request.getSession().getAttribute("user");
if(user==null)
{
return "redirect:/index.action";
}
List<Order> orderList=orderService.queryOrderByUid(user.getUid());
request.setAttribute("orderList", orderList);
return "order_list";
}
@RequestMapping("/admin/order_list")
public String ShowOrderList(int pageNumber,int ostatus,HttpServletRequest request)
{
request.setAttribute("ostatus", ostatus);
if(pageNumber<=0)
pageNumber=1;
Page p = orderService.queryOrdersByOstatus(ostatus,pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p = orderService.queryOrdersByOstatus(ostatus,p.getTotalPage());
}
}
request.setAttribute("p", p);
return "admin/order_list";
}
@RequestMapping("/admin/order_status_change")
public String ChangeOrderStatusByOid(String oid,int ostatus,HttpServletRequest request)
{
boolean result= orderService.updateOrderStatus(oid,ostatus);
return "redirect:order_list.action?pageNumber=1&ostatus="+ostatus;
}
@RequestMapping("/admin/order_delete")
public String DeleteOrderByOid(String oid,int ostatus,HttpServletRequest request)
{
boolean result= orderService.deleteOrderByOid(oid);
return "redirect:order_list.action?pageNumber=1&ostatus="+ostatus;
}
}
package com.vilicode.controller;
import com.vilicode.Utils.MyCipher;
import com.vilicode.bean.Page;
import com.vilicode.bean.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.vilicode.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/login")
public String login(User tempUser, HttpServletRequest request, HttpSession session)
{
String path="";
User user=userService.login(tempUser.getUname());
if(user==null)
{
request.setAttribute("failMsg","用户名不存在!");
return "user_login";
}
if(tempUser.getUpwd().equals(user.getUpwd()))
{
session.setAttribute("user", user);
request.setAttribute("msg","登录成功!");
return "redirect:/index.action";
}else{
request.setAttribute("failMsg","密码错误!");
return "user_login";
}
}
@RequestMapping("/register")
public String register(User user, HttpServletRequest request)
{
String path="";
user.setUrole(1);
user.setUmark("普通用户");
if(userService.register(user))
{
path="redirect:user_login.jsp";
}else{
request.setAttribute("msg","用户名重复!");
path="user_register";
}
return path;
}
@RequestMapping("/admin/user_add")
public String AddUser(User user, HttpServletRequest request)
{
user.setUrole(1);
user.setUmark("普通用户");
if(userService.register(user))
{
return "redirect:user_list.action?pageNumber=1";
}else{
request.setAttribute("msg","用户名重复!");
return "admin/user_add";
}
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request)
{
request.getSession().removeAttribute("user");
return "redirect:index.action";
}
@RequestMapping("/admin/logout")
public String adminLogout(HttpServletRequest request)
{
request.getSession().removeAttribute("user");
return "redirect:index.action";
}
@RequestMapping("/change_phone_and_address")
public String updateUphoneAndUaddress(int uid,String uphone,String uaddress,HttpServletRequest request)
{
boolean result=userService.UpdatePhoneAndAddress(uid,uphone,uaddress);
if(result)
{
request.setAttribute("msg","修改成功!");
User u=(User)request.getSession().getAttribute("user");
u.setUaddress(uaddress);
u.setUphone(uphone);
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",u);
return "user_center";
}
else
{
request.setAttribute("failMsg","修改密码时出现错误,请确认原密码是否正确或联系管理员!");
return "user_center";
}
}
@RequestMapping("/change_password")
public String updatePassword(int uid,String oldupwd,String upwd,HttpServletRequest request)
{
boolean result=userService.UpdatePassword(uid,upwd,oldupwd);
if(result)
{
request.setAttribute("msg","修改成功!");
MyCipher myCipher=new MyCipher();
User u=(User)request.getSession().getAttribute("user");
u.setUpwd(myCipher.encrypt(upwd,"!"));
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",u);
return "user_center";
}
else
{
request.setAttribute("failMsg","修改密码时出现错误,请确认原密码是否正确或联系管理员!");
return "user_center";
}
}
@RequestMapping("admin/change_password")
public String updatePassword(int uid,String upwd,HttpServletRequest request)
{
boolean result=userService.UpdatePassword(uid,upwd);
if(result)
{
MyCipher myCipher=new MyCipher();
request.setAttribute("msg","修改成功!");
User u=(User)request.getSession().getAttribute("user");
u.setUpwd(myCipher.encrypt(upwd,"!"));
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",u);
return "redirect:user_list.action?pageNumber=1";
}
else
{
request.setAttribute("failMsg","修改失败");
return "redirect:user_list.action?pageNumber=1";
}
}
@RequestMapping("admin/user_list")
public String ShowUserList(int pageNumber,HttpServletRequest request)
{
if(pageNumber<=0)
pageNumber=1;
Page p = userService.queryUser(pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p = userService.queryUser(p.getTotalPage());
}
}
request.setAttribute("p", p);
return "admin/user_list";
}
@RequestMapping("admin/user_delete")
public String DeleteUser(int uid)
{
boolean result= userService.deleteUser(uid);
return "redirect:user_list.action?pageNumber=1";
}
@RequestMapping("/admin/user_edit_show")
public String ChangeUser(int uid,HttpServletRequest request)
{
User user=userService.queryUserByUid(uid);
if(user==null)
return "redirect:user_list.action?pageNumber=1";
else
{
request.setAttribute("u",user);
return "admin/user_edit";
}
}
@RequestMapping("/admin/user_update")
public String updateUser(int uid,String uphone,String uaddress,HttpServletRequest request)
{
boolean result=userService.UpdatePhoneAndAddress(uid,uphone,uaddress);
if(result)
{
User user=(User)request.getSession().getAttribute("user");
if(user.getUid()==uid)
{
user.setUaddress(uaddress);
user.setUphone(uphone);
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",user);
}
}
return "redirect:user_list.action?pageNumber=1";
}
}
package com.vilicode.controller;
import com.vilicode.Utils.MyCipher;
import com.vilicode.bean.Page;
import com.vilicode.bean.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.vilicode.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/login")
public String login(User tempUser, HttpServletRequest request, HttpSession session)
{
String path="";
User user=userService.login(tempUser.getUname());
if(user==null)
{
request.setAttribute("failMsg","用户名不存在!");
return "user_login";
}
if(tempUser.getUpwd().equals(user.getUpwd()))
{
session.setAttribute("user", user);
request.setAttribute("msg","登录成功!");
return "redirect:/index.action";
}else{
request.setAttribute("failMsg","密码错误!");
return "user_login";
}
}
@RequestMapping("/register")
public String register(User user, HttpServletRequest request)
{
String path="";
user.setUrole(1);
user.setUmark("普通用户");
if(userService.register(user))
{
path="redirect:user_login.jsp";
}else{
request.setAttribute("msg","用户名重复!");
path="user_register";
}
return path;
}
@RequestMapping("/admin/user_add")
public String AddUser(User user, HttpServletRequest request)
{
user.setUrole(1);
user.setUmark("普通用户");
if(userService.register(user))
{
return "redirect:user_list.action?pageNumber=1";
}else{
request.setAttribute("msg","用户名重复!");
return "admin/user_add";
}
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request)
{
request.getSession().removeAttribute("user");
return "redirect:index.action";
}
@RequestMapping("/admin/logout")
public String adminLogout(HttpServletRequest request)
{
request.getSession().removeAttribute("user");
return "redirect:index.action";
}
@RequestMapping("/change_phone_and_address")
public String updateUphoneAndUaddress(int uid,String uphone,String uaddress,HttpServletRequest request)
{
boolean result=userService.UpdatePhoneAndAddress(uid,uphone,uaddress);
if(result)
{
request.setAttribute("msg","修改成功!");
User u=(User)request.getSession().getAttribute("user");
u.setUaddress(uaddress);
u.setUphone(uphone);
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",u);
return "user_center";
}
else
{
request.setAttribute("failMsg","修改密码时出现错误,请确认原密码是否正确或联系管理员!");
return "user_center";
}
}
@RequestMapping("/change_password")
public String updatePassword(int uid,String oldupwd,String upwd,HttpServletRequest request)
{
boolean result=userService.UpdatePassword(uid,upwd,oldupwd);
if(result)
{
request.setAttribute("msg","修改成功!");
MyCipher myCipher=new MyCipher();
User u=(User)request.getSession().getAttribute("user");
u.setUpwd(myCipher.encrypt(upwd,"!"));
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",u);
return "user_center";
}
else
{
request.setAttribute("failMsg","修改密码时出现错误,请确认原密码是否正确或联系管理员!");
return "user_center";
}
}
@RequestMapping("admin/change_password")
public String updatePassword(int uid,String upwd,HttpServletRequest request)
{
boolean result=userService.UpdatePassword(uid,upwd);
if(result)
{
MyCipher myCipher=new MyCipher();
request.setAttribute("msg","修改成功!");
User u=(User)request.getSession().getAttribute("user");
u.setUpwd(myCipher.encrypt(upwd,"!"));
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",u);
return "redirect:user_list.action?pageNumber=1";
}
else
{
request.setAttribute("failMsg","修改失败");
return "redirect:user_list.action?pageNumber=1";
}
}
@RequestMapping("admin/user_list")
public String ShowUserList(int pageNumber,HttpServletRequest request)
{
if(pageNumber<=0)
pageNumber=1;
Page p = userService.queryUser(pageNumber);
if(p.getTotalPage()==0)
{
p.setTotalPage(1);
p.setPageNumber(1);
}
else {
if(pageNumber>=p.getTotalPage()+1)
{
p = userService.queryUser(p.getTotalPage());
}
}
request.setAttribute("p", p);
return "admin/user_list";
}
@RequestMapping("admin/user_delete")
public String DeleteUser(int uid)
{
boolean result= userService.deleteUser(uid);
return "redirect:user_list.action?pageNumber=1";
}
@RequestMapping("/admin/user_edit_show")
public String ChangeUser(int uid,HttpServletRequest request)
{
User user=userService.queryUserByUid(uid);
if(user==null)
return "redirect:user_list.action?pageNumber=1";
else
{
request.setAttribute("u",user);
return "admin/user_edit";
}
}
@RequestMapping("/admin/user_update")
public String updateUser(int uid,String uphone,String uaddress,HttpServletRequest request)
{
boolean result=userService.UpdatePhoneAndAddress(uid,uphone,uaddress);
if(result)
{
User user=(User)request.getSession().getAttribute("user");
if(user.getUid()==uid)
{
user.setUaddress(uaddress);
user.setUphone(uphone);
request.getSession().removeAttribute("user");
request.getSession().setAttribute("user",user);
}
}
return "redirect:user_list.action?pageNumber=1";
}
}
五、底部获取项目(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以