SuperMarketSys_SSM超市管理系统(Spring+SpringMVC+Mybatis)

项目分层

所需jar包

项目一览

web.xml配置以及相应框架配置文件

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>SuperMarketSys_SSM</display-name>

    <welcome-file-list>
    <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file>
  </welcome-file-list>


  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>
          org.springframework.web.filter.CharacterEncodingFilter
      </filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>



   <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-*.xml</param-value>
  </context-param>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>SuperMarketSys_SSM.root</param-value>
  </context-param>
  <listener>
    <listener-class>
            org.springframework.web.util.Log4jConfigListener
        </listener-class>
  </listener>

</web-app>

resource包
applicationContext-mybatis.xml

<?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:aop="http://www.springframework.org/schema/aop"  
        xmlns:p="http://www.springframework.org/schema/p"  
        xmlns:tx="http://www.springframework.org/schema/tx"  
        xmlns:context="http://www.springframework.org/schema/context"  
        xsi:schemaLocation="   
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd   
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.xsd">  

       <!-- 扫描service层所有的包 -->
       <context:component-scan base-package="com.yccz.service"/> 
<!-- <context:component-scan base-package="com.yccz.entity"/>  -->

           <!-- 读取数据库配置文件 -->
    <context:property-placeholder location="classpath:database.properties"/>

        <!-- JNDI获取数据源(使用dbcp连接池) -->  
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton">
            <property name="driverClassName" value="${driver}" />  
            <property name="url" value="${url}" />  
            <property name="username" value="${user}" />  
            <property name="password" value="${password}" />
            <property name="initialSize" value="${initialSize}"/>
            <property name="maxActive" value="${maxActive}"/>
            <property name="maxIdle" value="${maxIdle}"/>
            <property name="minIdle" value="${minIdle}"/>
            <property name="maxWait" value="${maxWait}"/>
            <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}"/>
            <property name="removeAbandoned" value="${removeAbandoned}"/>
            <!-- sql 心跳 -->
            <property name= "testWhileIdle" value="true"/>
            <property name= "testOnBorrow" value="false"/>
            <property name= "testOnReturn" value="false"/>
            <property name= "validationQuery" value="select 1"/>
            <property name= "timeBetweenEvictionRunsMillis" value="60000"/>
            <property name= "numTestsPerEvictionRun" value="${maxActive}"/>
    </bean>

     <!-- 事务管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean> 

    <!-- 配置mybitas SqlSessionFactoryBean-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </bean>

    <!-- AOP 事务处理 开始 -->    
    <aop:aspectj-autoproxy />
    <aop:config  proxy-target-class="true">
        <aop:pointcut expression="execution(* *com.yccz.service..*(..))" id="transService"/>
        <aop:advisor pointcut-ref="transService" advice-ref="txAdvice" />
    </aop:config> 
    <tx:advice id="txAdvice" transaction-manager="transactionManager">  
        <tx:attributes>  
           <tx:method name="*"  propagation="REQUIRED" rollback-for="Exception"  />
        </tx:attributes>  
    </tx:advice> 
    <!-- AOP 事务处理 结束 -->


    <!-- 没有必要在 Spring 的 XML 配置文件中注册所有的映射器。
    相反,你可以使用一个 MapperScannerConfigurer , 它 将 会 查 找 类 路 径 下 的 映 射 器 并 自 动 将 它 们 创 建 成 MapperFactoryBean。 -->
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
         <property name="basePackage" value="com.yccz.dao" />  
</bean>

</beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE configuration   
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"   
        "http://mybatis.org/dtd/mybatis-3-config.dtd">  
<configuration>  
      <settings>  
          <!-- 懒加载配置 -->  
          <setting name="lazyLoadingEnabled" value="false" />  

      </settings>  
     <typeAliases>  
         <!--这里给实体类取别名,方便在mapper配置文件中使用--> 
         <package name="com.yccz.entity"/>
     </typeAliases> 



</configuration>  

springmvc-servlet.xml

<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

        <!-- 扫描所有的controller层下的类 -->
        <context:component-scan base-package="com.yccz.controller"/>
        <!-- 这个标签注册了Spring MVC分发请求到控制器所必须的DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter实例 -->
        <mvc:annotation-driven/>
        <!-- 扫描所有的静态文件,不写所有的js无效 -->
        <mvc:resources location="/statics/" mapping="/statics/**"/>
        <mvc:default-servlet-handler/>


        <!-- 解决json数据传递的中文乱码问题-StringHttpMessageConverter -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
            <!-- 解决JSON数据传递的日期格式问题-->
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json</value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <!--  Date的日期转换器 -->
                        <value>WriteDateUseDateFormat</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>




        <!-- 完成视图的对应 -->
        <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">  
        <!-- 上传文件大小上限,单位为字节(10MB) -->
        <property name="maxUploadSize">  
            <value>10485760</value>  
        </property>  
      <!--   请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,默认为ISO-8859-1 -->
        <property name="defaultEncoding">
            <value>UTF-8</value>
        </property>
    </bean>

        </beans>

database.properties

driver=com.mysql.jdbc.Driver
#在和mysqlä¼ é€’æ•°æ®çš„è¿‡ç¨‹ä¸­ï¼Œä½¿ç”¨unicodeç¼–ç æ ¼å¼ï¼Œå¹¶ä¸”å­—ç¬¦é›†è®¾ç½®ä¸ºutf-8
url=jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=utf-8
user=root
password=123
minIdle=45
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
#\u8D85\u65F6\u65F6\u95F4\uFF1B\u5355\u4F4D\u4E3A\u79D2\u3002180\u79D2=3\u5206\u949F
removeAbandonedTimeout=180
#\u8D85\u8FC7\u65F6\u95F4\u9650\u5236\u662F\u5426\u56DE\u6536
removeAbandoned=true

实体层entity(省略set、get方法)

package com.yccz.entity;

import java.util.Date;
import java.util.List;
/**
 * 订单表
 * @author Administrator
 *
 */
public class Bill {
   
    private int id;
    private String billCode;
    private String productName;
    private String productDesc;
    private String productUnit;
    private double productCount;
    private double totalPrice;
    private int isPayment;
    private int createdBy;
    private Date creationDate;
    private int modifyBy;
    private Date modifyDate;
    private int providerId;
    private String proName;


    //供应商集合
    private Provider provider;


    }




}
package com.yccz.entity;

import java.util.Date;
/**
 * 
* <p>Title: Provider</p>
* <p>Description:供应商类 </p>
* <p>Company: </p> 
* @author    Bill
* @date       2017年10月20日
 */
public class Provider {
   
    private int id;
    private String proCode;
    private String proName;
    private String proDesc;
    private String proContact;
    private String proPhone;
    private String proAddress;
}



/**
 * 用户表
 * @author Administrator
 *
 */
@Component
public class User {
    
      @Autowired
      RoleService roleService;
      private int id;
      
评论 91
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值