基於ssm框架和freemarker的商品銷售系統


項目說明

1、項目文件結構

 

 

2、項目主要接口及其實現

 (1)Index:

首頁頁面:展示商品功能,可登錄或查看商品詳細信息

 

 (2)登錄:/ApiLogin

 

 

3、dao層

數據持久化層,把商品和用戶信息寸進mysql數據庫

(1)ContentDao

 

 

 (2)PersonDao

 

(3)ProductDao

 

(4)TransactionDao

 

4、spring配置文件和mybatis配置文件

spring-mvc.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:mvc="http://www.springframework.org/schema/mvc"
 6        xsi:schemaLocation="http://www.springframework.org/schema/beans
 7                         http://www.springframework.org/schema/beans/spring-beans.xsd
 8                         http://www.springframework.org/schema/context
 9                         http://www.springframework.org/schema/context/spring-context.xsd
10                         http://www.springframework.org/schema/mvc
11                         http://www.springframework.org/schema/mvc/spring-mvc.xsd">
12 
13     <!-- 自動掃描該包,使SpringMVC認為包下用了@controller注解的類是控制器 -->
14     <context:component-scan base-package="com.web.controller"></context:component-scan>
15     <!-- 擴充了注解驅動,可以將請求參數綁定到控制器參數 -->
16     <mvc:annotation-driven/>
17     <mvc:default-servlet-handler/>
18     
19     <!-- 配置事務管理器
20     <bean id="transactionManager"
21           class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
22         <!- 注入數據庫連接池 ->
23         <property name="dataSource" ref="dataSource"/>
24     </bean>
25     -->
26     <!-- freemarker配置 -->
27     <bean id="freemarkerConfig"
28           class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
29         <property name="templateLoaderPath" value="/WEB-INF/freemarker" />
30         <property name="templateLoaderPaths" value="/template"/>
31         <property name="freemarkerSettings">
32             <props>
33                 <prop key="template_update_delay">0</prop><!--刷新模板的周期,單位為秒-->
34                 <prop key="defaultEncoding">UTF-8</prop><!--模板的編碼格式 -->
35             </props>
36         </property>
37     </bean>
38     <!-- freemarker視圖解析器 -->
39     <bean
40             class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
41         <property name="viewResolvers">
42             <list>
43                 <bean id="viewResolver"
44                       class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
45                     <property name="cache" value="true" />
46                     <property name="prefix" value="" />
47                     <property name="suffix" value=".ftl" />
48                     <property name="contentType" value="text/html; charset=UTF-8" />
49                 </bean>
50             </list>
51         </property>
52         <property name="defaultViews">
53             <list>
54                 <bean
55                         class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
56             </list>
57         </property>
58     </bean>
59     <!-- SpringMVC上傳文件時,需要配置MultipartResolver處理器 -->
60     <bean id="multipartResolver"
61           class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
62         <property name="defaultEncoding" value="UTF-8" />
63         <!-- 指定所上傳文件的總大小,單位字節。注意maxUploadSize屬性的限制不是針對單個文件,而是所有文件的容量之和 -->
64         <property name="maxUploadSize" value="10240000" />
65     </bean>
66 
67     <!--注冊攔截器-->
68 
69 </beans>

 

spring-mybatis.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!-- 配置文件需要引入的類 -->
 3 <beans xmlns="http://www.springframework.org/schema/beans"
 4        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5        xmlns:context="http://www.springframework.org/schema/context"
 6        xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
 7        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 8 
 9         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
10 
11 
12 
13 
14         http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
15     <!-- scanner -->
16     <context:component-scan base-package="com.web.service"></context:component-scan>
17     <context:component-scan base-package="com.web.service.impl"></context:component-scan>
18 
19 
20     <!-- Spring and mybatis-->
21     <mybatis:scan base-package="com.web.dao"/>
22 
23 
24     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
25         <property name="dataSource" ref="dataSource"/>
26     </bean>
27 
28     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
29           destroy-method="close">
30         <property name="driverClassName" value="${jdbc.driverClassName}"></property>
31         <property name="url" value="${jdbc.url}"></property>
32         <property name="username" value="${jdbc.username}"></property>
33         <property name="password" value="${jdbc.password}"></property>
34         <!-- 初始化連接大小 -->
35         <property name="initialSize" value="${initialSize}"></property>
36         <!-- 連接池最大數量 -->
37         <property name="maxActive" value="${maxActive}"></property>
38         <!-- 連接池最大空閑 -->
39         <property name="maxIdle" value="${maxIdle}"></property>
40         <!-- 連接池最小空閑 -->
41         <property name="minIdle" value="${minIdle}"></property>
42         <!-- 獲取連接最大等待時間 -->
43         <property name="maxWait" value="${maxWait}"></property>
44     </bean>
45 
46     <context:property-placeholder location="classpath:db.properties"/>
47 
48     <!-- 配置基於注解的聲明式事務
49     <bean id="transactionManager"
50                 class="org.springframework.orm.jpa.JpaTransactionManager">
51         <property name="dataSource" ref="dataSource" />
52     </bean>
53 
54     <tx:annotation-driven transaction-manager="transactionManager"/>
55     -->
56 </beans>

 

db.properties

 1 jdbc.driverClassName= com.mysql.jdbc.Driver
 2 jdbc.url= jdbc:mysql://localhost:3306/shen_db?characterEncoding=utf8&useSSL=true
 3 jdbc.username=root
 4 jdbc.password=123456
 5 initialSize=0
 6 #定義最大連接數
 7 maxActive=20
 8 #定義最大空閑
 9 maxIdle=20
10 #定義最小空閑
11 minIdle=1
12 #定義最長等待時間
13 maxWait=60000

 

5、運行截圖

 

首頁

 

 買家購物車

 

買家賬單

 

賣家發布商品界面

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM