Building auction system with SSM

Time:2021-9-18

Like and watch again to form a habit

Project introduction and process

The auction system is built with SSM architecture, and the page data rendering adopts JSP primary simple auction system. The auction process is that after ordinary users register and log in, after entering the personal center to publish goods, the system administrator reviews the goods. If the review fails, the user publishes a list to show the reasons for rejection. After the review is passed, the home page and classification can be queried and displayed, Non publishers bid for goods, the bidding is completed, the publisher ships the goods, and the auction winner pays to complete the final transaction.

Development environment:

  1. jdk 8
  2. intellij idea
  3. tomcat 8
  4. mysql 5.7

Technology used:

Project framework: SSM

Front end rendering: JSP

Front end technology: JS / jquery

Project directory structure

目录结构

  • Controller, view control layer,
  • Service, business logic layer
  • Dao, database operation layer
  • JSP, page data rendering
  • Mapper.xml, which defines the SQL for operating the database. Each SQL is a statement, and the mapping file is the core of mybatis
  • Jdbc.properties, database account password configuration

Operation effect

  • register

  • home page

  • Release product

  • Commodity bidding

  • Browse records

Core project configuration:

1. Spring-mvc.xml configuration:

text/html;charset=UTF-8

2. Spring-mybatis.xml configuration

com.mysql.jdbc.Driver
        
        
            jdbc:mysql://localhost:3306/pmxt?characterEncoding=UTF-8

        
        
            root
        
        
            root123

3. Login verification

@RequestMapping("/checkLogin")
@ResponseBody
public int checkLogin(HttpServletRequest request, String uname, String upassword, String verifyCode) {
    HttpSession session = request.getSession();
    String sessionVerifyCode = (String) session.getAttribute("verifyCodeValue");
    if (!verifyCode.equalsIgnoreCase(sessionVerifyCode)) {
        int flag = 4;
        return flag;

    } else {
        List pUsersModels = pUserService.checkLogin(uname, upassword);
        if (pUsersModels.isEmpty()) {
            return 0;// user name does not exist
        }
        String relpassword = pUsersModels.get(0).getUpassword();
        int utype = pUsersModels.get(0).getUtype();
        if (upassword.equals(relpassword)) {
            session = request.getSession();
            session.setAttribute("uname", uname);
            session.setAttribute("utype", utype);
            session.setAttribute("pUsersModel", pUsersModels.get(0));
            if (utype == 1) {
                return 3;// administrators
            }
            return 1;// The password is correct
        } else {
            return 2;// Incorrect password
        }
    }
}

4. System recommendation

@RequestMapping("/sysRecommend")
public String sysRecommend(HttpSession session, Model model, String page)
{
    PUsersModel pUsersModel=(PUsersModel)session.getAttribute("pUsersModel");
    //First judge whether the current user has browsed the goods
    LookshistoryModel lookModel=new LookshistoryModel();
    lookModel.setUserid(pUsersModel.getUid());
    List lists=lookshistoryService.selectLookshistory(lookModel); 		// Query the total records and process them in descending order
    Map gmap=new HashMap();
    if(lists!=null&lists.size()>0){  														// Make accurate recommendations according to product filtering and screening
        int hits=0; 																			// Get total number of views
        for(LookshistoryModel m:lists){
            gmap.put(m.getPgtype(),m.getHits()); 											// Proportion of filled goods
            hits+=m.getHits(); 																// Overlay views
        }
        Map gpmap=new HashMap(); 										// Object storage conversion, type -- > > times mode
        for (Map.Entry entry : gmap.entrySet()) {
            BigDecimal percentage=new BigDecimal(entry.getValue()).divide(new BigDecimal(hits),2,BigDecimal.ROUND_HALF_DOWN); 		// Proportion of current highest commodities
            int result=percentage.multiply(new BigDecimal(12)).intValue(); 							// Recommend the proportion of each product
            gpmap.put(entry.getKey(),result);
        }
        List afterGoodsModels =new ArrayList();
        int afterPageNums =0;
        for (Map.Entry entry : gmap.entrySet()) { 								// Final recommended products
            int afterPageItem = goodsService.countAfterGoodsByKinds(entry.getKey());
            final int afterPageSize = entry.getValue();
            if (page == null)
            {
                page = "1";
            }
            PageUtil afterPageUtil = new PageUtil(afterPageItem, afterPageSize, Integer.parseInt(page));
            int afterPageNum = afterPageUtil.getPageNum();
            afterPageNums+=afterPageNum;
            int afterStartRow = afterPageUtil.getStartRow();
            List goodsModels = goodsService.getAfterCheckGoodsByPageBykinds(afterStartRow, afterPageSize, entry.getKey());
            Boolean afterHasNextPage = (Integer.parseInt(page) != afterPageNum) && (afterPageNum != 0);
            model.addAttribute("afterHasPrePage", Integer.parseInt(page) != 1);
            model.addAttribute("afterHasNextPage", afterHasNextPage);
            model.addAttribute("afterGoodsModels", afterGoodsModels);
            model.addAttribute("afterPageItem", afterPageItem);

            model.addAttribute("nowPage", Integer.parseInt(page));
            afterGoodsModels.addAll(goodsModels);
        }
        model.addAttribute("afterPrePage", Integer.parseInt(page) - 1);
        model.addAttribute("afterNextPage", Integer.parseInt(page) + 1);
        model.addAttribute("afterPageNum", afterPageNums); 		// Total page
        model.addAttribute("afterGoodsModels", afterGoodsModels);// Total commodity

    }else{ 																					// According to popular browsing recommendations

        lists=lookshistoryService.selectLookshistory(new LookshistoryModel()); 				// According to the recommendation of the public with more browsing times
        if(lists!=null&lists.size()>0){
            int hits=0; 																			// Get total number of views
            for(LookshistoryModel m:lists){
                gmap.put(m.getPgtype(),m.getHits()); 											// Proportion of filled goods
                hits+=m.getHits(); 																// Overlay views
            }
            Map gpmap=new HashMap();// Commodity proportion storage object
            for (Map.Entry entry : gmap.entrySet()) {
                BigDecimal percentage=new BigDecimal(entry.getValue()).divide(new BigDecimal(hits)); 		// Proportion of current highest commodities
                int result=percentage.multiply(new BigDecimal(12)).intValue(); 							// Recommend the proportion of each product
                gpmap.put(entry.getKey(),result);
            }
            List afterGoodsModels =new ArrayList();
            int afterPageNums =0;
            for (Map.Entry entry : gmap.entrySet()) { 				// Final recommended products
                int afterPageItem = goodsService.countAfterGoodsByKinds(entry.getKey());
                final int afterPageSize = entry.getValue();
                if (page == null)
                {
                    page = "1";
                }``
                PageUtil afterPageUtil = new PageUtil(afterPageItem, afterPageSize, Integer.parseInt(page));
                int afterPageNum = afterPageUtil.getPageNum();
                afterPageNums+=afterPageNum;
                int afterStartRow = afterPageUtil.getStartRow();
                List goodsModels = goodsService.getAfterCheckGoodsByPageBykinds(afterStartRow, afterPageSize, entry.getKey());
                Boolean afterHasNextPage = (Integer.parseInt(page) != afterPageNum) && (afterPageNum != 0);
                model.addAttribute("afterHasPrePage", Integer.parseInt(page) != 1);
                model.addAttribute("afterHasNextPage", afterHasNextPage);
                model.addAttribute("afterGoodsModels", afterGoodsModels);
                model.addAttribute("afterPageItem", afterPageItem);

                model.addAttribute("nowPage", Integer.parseInt(page));
                afterGoodsModels.addAll(goodsModels);
            }
            model.addAttribute("afterPrePage", Integer.parseInt(page) - 1);
            model.addAttribute("afterNextPage", Integer.parseInt(page) + 1);
            model.addAttribute("afterPageNum", afterPageNums); 		// Total page
            model.addAttribute("afterGoodsModels", afterGoodsModels);// Total commodity
        }else{
            int lindid=(int)Math.random()*(1); 									// No number of views recommended by the system
            int afterPageItem = goodsService.countAfterGoodsByKinds(lindid);
            final int afterPageSize = 12;
            if (page == null)
            {
                page = "1";
            }
            PageUtil afterPageUtil = new PageUtil(afterPageItem, afterPageSize, Integer.parseInt(page));
            int afterPageNum = afterPageUtil.getPageNum();
            int afterStartRow = afterPageUtil.getStartRow();
            List afterGoodsModels = goodsService.getAfterCheckGoodsByPageBykinds(afterStartRow, afterPageSize, 0);
            Boolean afterHasNextPage = (Integer.parseInt(page) != afterPageNum) && (afterPageNum != 0);
            model.addAttribute("afterHasPrePage", Integer.parseInt(page) != 1);
            model.addAttribute("afterHasNextPage", afterHasNextPage);
            model.addAttribute("afterPrePage", Integer.parseInt(page) - 1);
            model.addAttribute("afterNextPage", Integer.parseInt(page) + 1);
            model.addAttribute("afterGoodsModels", afterGoodsModels);
            model.addAttribute("afterPageItem", afterPageItem);
            model.addAttribute("afterPageNum", afterPageNum);
            model.addAttribute("nowPage", Integer.parseInt(page));
        }
    }
    return "otherkinds";
}

Project summary

At present, this version is a simple auction system with other auction logic or additional functions. Please pay attention to the subsequent iterative scheduling development!