ssm搭建拍賣系統

<br/>點贊再看,養成習慣<br/>css

項目介紹及流程

拍賣系統採用ssm架構搭建,頁面數據渲染採用jsp的初級簡易拍賣系統,拍賣流程爲 普通用戶註冊、登陸後,進入我的中心發佈商品後, 系統管理員進行商品審覈, 審覈不經過,用戶發佈列表展現拒絕緣由, 審覈經過後,首頁及分類可查詢展現,非發佈人員進行商品競價, 競價完成,發佈者進行商品發貨, 拍賣得到者進行付款, 完成最終交易。html

開發環境:

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

所用技術:

項目框架:ssm前端

前端渲染:jspmysql

前端技術:js/jqueryjquery

項目目錄結構

ssm搭建拍賣系統

  • controller,視圖控制層,
  • service,業務邏輯層
  • dao,數據庫操做層
  • jsp,頁面進行數據渲染
  • mapper.xml,此文件定義了操做數據庫的sql,每一個sql是一個statement,映射文件是mybatis的核心
  • jdbc.properties,數據庫賬號密碼配置

運行效果

  • 註冊

ssm搭建拍賣系統

  • 首頁

ssm搭建拍賣系統

  • 發佈商品

ssm搭建拍賣系統

  • 商品競價

ssm搭建拍賣系統

  • 瀏覽記錄

ssm搭建拍賣系統

  • 後端-商品管理

ssm搭建拍賣系統

核心項目配置:

1.spring-mvc.xml配置:web

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <mvc:annotation-driven/>
    <!-- 自動掃描  @Controller-->
    <context:component-scan base-package="com.pmxt.controller"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/view/**" location="/view/"/>
    <mvc:resources mapping="/upload/**" location="/upload/"/>
    <!--避免IE執行AJAX時,返回JSON出現下載文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 啓動SpringMVC的註解功能,完成請求和註解POJO的映射 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter"/> <!-- JSON轉換器 -->
            </list>
        </property>
    </bean>

    <!-- 定義跳轉的文件的先後綴 ,視圖模式配置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- 文件上傳配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默認編碼 -->
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 上傳文件大小限制爲31M,31*1024*1024 -->
        <property name="maxUploadSize" value="32505856"/>
        <!-- 內存中的最大值 -->
        <property name="maxInMemorySize" value="4096"/>
    </bean>

    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/showLogin"/>
            <mvc:exclude-mapping path="/getVerifyCode"/>
            <mvc:exclude-mapping path="/checkLogin"/>
            <mvc:exclude-mapping path="/showReg"/>
            <mvc:exclude-mapping path="/forget"/>
            <mvc:exclude-mapping path="/checkUname"/>
            <mvc:exclude-mapping path="/forgetPassword"/>
            <mvc:exclude-mapping path="/reg"/>
            <mvc:exclude-mapping path="/css/**"/>
            <mvc:exclude-mapping path="/images/**"/>
            <mvc:exclude-mapping path="/js/**"/>
            <mvc:exclude-mapping path="/upload/**"/>
            <mvc:exclude-mapping path="/WEB-INF/jsp/login.jsp"/>

            <bean class="com.pmxt.interceptor.LoginInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>

    <!--500錯誤和404請求失敗-->
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <map>
                <entry key="ResourceNotFoundException" value="common/error/resourceNotFoundError" />
                <entry key=".DataAccessException" value="common/error/dataAccessError" />
            </map>
        </property>
        <property name="statusCodes">
            <map>
                <entry key="common/error/resourceNotFoundError" value="404" />
                <entry key="common/error/dataAccessError" value="500" />
            </map>
        </property>
    </bean>

</beans>

2.spring-mybatis.xml配置spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 自動掃描 -->
    <context:component-scan base-package="com.pmxt"/>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost:3306/pmxt?characterEncoding=UTF-8</value>

        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>root123</value>
        </property>
    </bean>

    <!-- mybatis和spring完美整合,不須要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!-- 自動掃描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:mapping/*.xml"></property>
    </bean>

    <!-- DAO接口所在包名,Spring會自動查找其下的類 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.pmxt.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

3.登陸驗證sql

@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<PUsersModel> pUsersModels = pUserService.checkLogin(uname, upassword);
        if (pUsersModels.isEmpty()) {
            return 0;//用戶名不存在
        }
        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;//管理員
            }
            return 1;//密碼正確
        } else {
            return 2;//密碼不正確
        }
    }
}

4.系統推薦數據庫

@RequestMapping("/sysRecommend")
public String sysRecommend(HttpSession session, Model model, String page)
{
    PUsersModel pUsersModel=(PUsersModel)session.getAttribute("pUsersModel");
    //先判斷當前用戶是否已經瀏覽過商品
    LookshistoryModel lookModel=new LookshistoryModel();
    lookModel.setUserid(pUsersModel.getUid());
    List<LookshistoryModel> lists=lookshistoryService.selectLookshistory(lookModel);        //查詢總記錄並作降序處理
    Map<Integer,Integer> gmap=new HashMap<Integer, Integer>();
    if(lists!=null&lists.size()>0){                                                         //根據作商品過濾篩選 精準推薦
        int hits=0;                                                                         //獲取瀏覽總數
        for(LookshistoryModel m:lists){
            gmap.put(m.getPgtype(),m.getHits());                                            //填充商品佔比狀況
            hits+=m.getHits();                                                              //疊加瀏覽次數
        }
        Map<Integer,Integer> gpmap=new HashMap<Integer, Integer>();                                     //對象儲存轉換,類型--->>次數 模式
        for (Map.Entry<Integer, Integer> entry : gmap.entrySet()) {
            BigDecimal percentage=new BigDecimal(entry.getValue()).divide(new BigDecimal(hits),2,BigDecimal.ROUND_HALF_DOWN);       //當前最高商品的佔比
            int result=percentage.multiply(new BigDecimal(12)).intValue();                          //推薦每一個商品出現的佔比狀況
            gpmap.put(entry.getKey(),result);
        }
        List<GoodsModel> afterGoodsModels =new ArrayList<GoodsModel>();
        int afterPageNums =0;
        for (Map.Entry<Integer, Integer> entry : gmap.entrySet()) {                             //最終推薦出商品狀況
            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<GoodsModel> 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);      //總頁面
        model.addAttribute("afterGoodsModels", afterGoodsModels);//總商品

    }else{                                                                                  //根據大衆瀏覽推薦

        lists=lookshistoryService.selectLookshistory(new LookshistoryModel());              //根據大衆瀏覽次數多的多推薦
        if(lists!=null&lists.size()>0){
            int hits=0;                                                                         //獲取瀏覽總數
            for(LookshistoryModel m:lists){
                gmap.put(m.getPgtype(),m.getHits());                                            //填充商品佔比狀況
                hits+=m.getHits();                                                              //疊加瀏覽次數
            }
            Map<Integer,Integer> gpmap=new HashMap<Integer, Integer>();//商品佔比存儲對象
            for (Map.Entry<Integer, Integer> entry : gmap.entrySet()) {
                BigDecimal percentage=new BigDecimal(entry.getValue()).divide(new BigDecimal(hits));        //當前最高商品的佔比
                int result=percentage.multiply(new BigDecimal(12)).intValue();                          //推薦每一個商品出現的佔比狀況
                gpmap.put(entry.getKey(),result);
            }
            List<GoodsModel> afterGoodsModels =new ArrayList<GoodsModel>();
            int afterPageNums =0;
            for (Map.Entry<Integer, Integer> entry : gmap.entrySet()) {             //最終推薦出商品狀況
                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<GoodsModel> 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);      //總頁面
            model.addAttribute("afterGoodsModels", afterGoodsModels);//總商品
        }else{
            int lindid=(int)Math.random()*(1);                                  //沒有瀏覽次數系統隨機推薦
            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<GoodsModel> 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";
}

項目總結

目前此版本爲簡易拍賣系統,其餘拍賣邏輯或者額外功能,後續迭代排期開發,敬請關注!json

相關文章
相關標籤/搜索