图书商城系统

news2024/11/19 13:16:42

文章目录

  • 图书商城系统
    • 一、项目演示
    • 二、项目介绍
    • 三、系统部分功能截图
    • 四、部分代码展示
    • 五、底部获取项目(9.9¥带走)

图书商城系统

一、项目演示

网上书城

二、项目介绍

基于SSM的图书商城网站

运行环境:idea或eclipse 数据库:mysql

开发语言:java

基于Spring+SpingMVC+Mybatis+jsp的校园互助管理系统

有两个角色:用户和管理员

项目功能如下:

前台功能:

  1. 图书基本展示,包括推荐图书展示和类图书类型展示.

  2. 推荐图书包括条幅推荐,热销推荐和新品推荐.

  3. 按照图书类型展示商品.

  4. 图书详细信息展示.

  5. 图书加入购物车.

  6. 修改购物车内图书信息,例如数量等.

  7. 用户登录.

  8. 用户注册.

  9. 修改个人信息,包括密码和收获信息.

  10. 购物车付款.

  11. 用户订单查询.

  12. 根据关键字搜索图书.

后台功能:

  1. 订单操作:包括按状态查询订单,修改订单状态(发货,完成,删除).

  2. 用户操作:包括查询所有用户,新增用户,修改用户密码,修改用户信息和删除用户.

  3. 图书类目操作:包括查看所有类目,增加图书类目,修改图书类目信息以及删除图书类目.

  4. 图书操作:包括查询所有图书,新增图书,修改现有图书信息以及删除图书.

三、系统部分功能截图

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

四、部分代码展示

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¥带走)

有问题,或者需要协助调试运行项目的也可以

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1442832.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Web组件

鸿蒙&#xff08;HarmonyOS&#xff09;项目方舟框架&#xff08;ArkUI&#xff09;之Web组件 一、操作环境 操作系统: Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1 二、Web组件 提供具有网页显示能力的Web组件&#xff0c;ohos.web.webview提供web控制能…

4. TypeScript

目录 1 TypeScript 介绍 2 TypeScript 常用类型 2.1 类型标注的位置 2.2 字符串、数字、布尔类型 2.3 字面量类型 2.4 interface 类型 2.5 class 类型 Vue1&#xff1a;基础跟使用方式 Vue2&#xff1a;路由方面 Vue3&#xff1a;状态管理 vuex 状态管理库 1 TypeScrip…

鸿蒙原生应用再添新丁!央视新闻 入局鸿蒙

鸿蒙原生应用再添新丁&#xff01;央视新闻 入局鸿蒙 来自 HarmonyOS 微博2月9日消息&#xff0c;#央视新闻启动鸿蒙原生应用开发#中央广播电视总台旗舰央视新闻客户端正式宣布&#xff0c;将基于HarmonyOS NEXT鸿蒙星河版&#xff0c;启动央视新闻 鸿蒙原生应用开发&#xf…

springboot微信小程序 uniapp学习资料分享系统v9uy4

理论意义 当今网络教学已成为各国教育改革 和发展的趋势。因此&#xff0c;构建一个适合交互式课堂教学模式的教学平台就成了当务之 急。 在国内高校&#xff0c;目前交互平台主要用于网络学院的远程教学&#xff0c;至于校园内的正规教学&#xff0c;老师自发建立课程主页的比…

Web后端开发:事务与AOP

事务管理 在学习数据库时&#xff0c;讲到&#xff1a;事务是一组操作的集合&#xff0c;它是一个不可分割的工作单位。事务会把所有的操作作为一个整体&#xff0c;一起向数据库提交或者是撤销操作请求&#xff0c;要么同时成功&#xff0c;要么同时失败。 事务的操作主要有三…

VUE学习——数组变化侦测

官方文档 变更方法&#xff1a; 使用之后&#xff0c;ui可以直接发生改变。改变原数组 替换数组&#xff1a; 使用之后需要接受重新赋值&#xff0c;不然ui不发生改变。不改变原数组

深度学习的进展及其在各领域的应用

深度学习&#xff0c;作为人工智能的核心分支&#xff0c;近年来在全球范围内引起了广泛的关注和研究。它通过模拟人脑的学习机制&#xff0c;构建复杂的神经网络结构&#xff0c;从大量数据中学习并提取有用的特征表示&#xff0c;进而解决各种复杂的模式识别问题。 一、深度…

一、OpenAI API介绍

Open AI API可以应用到任何的业务场景。 文本生成 创造助理 嵌入数据 语音转化 图片生成 图片输入 1. 核心概念 1.1 Text generation models OpenAI 的文本生成模型(通常被称为generative pre-trained transformers 模型简称&#xff1a;GPT),有GPT-4和G…

RCS-YOLO复现

复现结果–Precision&#xff1a;0.941&#xff0c;Recall&#xff1a;0.945&#xff0c;AP 50 _{50} 50​&#xff1a;0.941&#xff0c;AP 50 : 95 _{50:95} 50:95​&#xff1a;0.693&#xff0c;误差在5个点内&#xff0c;可以接受 感想 第5篇完全复现的论文

postman接口功能测试

前言 之前还没实际做过接口测试的时候呢&#xff0c;对接口测试这个概念比较渺茫&#xff0c;只能靠百度&#xff0c;查看各种接口实例&#xff0c;然后在工作中也没用上&#xff0c;现在呢是各种各样的接口都丢过来&…

客观看待前后端分离,优劣、场景、对程序员职业的影响

前后端分离倡导多年了&#xff0c;现在基本成为了开发的主流模式了&#xff0c;贝格前端工场承接的前端项目只要不考虑seo的&#xff0c;都采用前后端分离模式。 一、在前端开发中&#xff0c;前后端分离是指什么 在前端开发中&#xff0c;前后端分离是一种架构模式&#xff…

python爬虫入门(一)

使用requests 库获取网站html信息 import requests response requests.get("https://jingyan.baidu.com/article/17bd8e52c76b2bc5ab2bb8a2.html#:~:text1.%E6%89%93%E5%BC%80%E6%B5%8F%E8%A7%88%E5%99%A8F12%202.%E6%89%BE%E5%88%B0headers%E9%87%8C%E9%9D%A2%E7%9A%84…

Java:集合以及集合进阶 --黑马笔记

一、集合概述和分类 1.1 集合的分类 除了ArrayList集合&#xff0c;Java还提供了很多种其他的集合&#xff0c;如下图所示&#xff1a; 我想你的第一感觉是这些集合好多呀&#xff01;但是&#xff0c;我们学习时会对这些集合进行分类学习&#xff0c;如下图所示&#xff1a;…

微信小程序上传代码教程

文章目录 概要整体架构流程技术名词解释技术细节小结 概要 小程序上传代码到gogs上面来 整体架构流程 小程序也要远程连接仓库&#xff0c;实现代码上传 技术名词解释 微信开发者工具gogs 技术细节 连接gogs仓库地址 微信小程序需要head将本地代码和gogs代码同步 小结 …

【C生万物】数组

&#x1f4da;博客主页&#xff1a;爱敲代码的小杨. ✨专栏&#xff1a;《Java SE语法》 | 《数据结构与算法》 | 《C生万物》 ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更新的动力❤️ &#x1f64f;小杨水平有…

node.js基础-02

Author nodes&#xff1a;&#xff08;题记&#xff09; Hypertest Transfer protocol is very important to programming personnel。it doesnt matter if youre a front-end engineer or a back-end engineer.So,lets study it together. http协议对于编程工程师很重要&am…

python coding with ChatGPT 打卡第19天| 二叉树:合并二叉树

相关推荐 python coding with ChatGPT 打卡第12天| 二叉树&#xff1a;理论基础 python coding with ChatGPT 打卡第13天| 二叉树的深度优先遍历 python coding with ChatGPT 打卡第14天| 二叉树的广度优先遍历 python coding with ChatGPT 打卡第15天| 二叉树&#xff1a;翻转…

【C++】实现一个二叉搜索树

目录 二叉搜索树的概念 1.结点定义 2.构造、析构、拷贝构造、赋值重载 3.插入、删除、查找、排序 3.1插入 3.2插入递归版 3.3查找指定值 3.3查找指定值递归版 3.4中序遍历 3.5删除 最后 二叉搜索树的概念 二叉搜索树又称为二叉排序树或二叉查找树&#xff0c;它或者…

python WEB接口自动化测试之requests库详解

由于web接口自动化测试需要用到python的第三方库--requests库&#xff0c;运用requests库可以模拟发送http请求&#xff0c;再结合unittest测试框架&#xff0c;就能完成web接口自动化测试。 所以笔者今天先来总结一下requests库的用法。希望对大家&#xff08;尤其是新手&…

使用CICFlowMeter 实现对pcap文件的特征提取【教程】

使用CICFlowMeter 实现对pcap文件的特征提取【教程】 针对现有的关于CICFlowMeter 的使用教程不够全面&#xff0c;一些细节没有展示&#xff0c;我将结合网络上的相关资料和实际的经历&#xff0c;提供一些经验和建议。 configuration information --------------- Windows…