ssm整合rabbitmq,shiro,mybatis,mysql,javaemil,dbcp等相关组件,完成物流管理系统

1页面展示,效果展示

1.1登录页

1.2主页面

1.3操作展示

1.4商品档案

1.5商品表的权限展示

lxq这个权限没有添加操作

而zjj这个权限都有

1.6入库操作

2ssm的pom文件,相关依赖

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.xzp</groupId>
  <artifactId>wuliu</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

 

  <!--配置了一个名为"maven-war-plugin"的Maven War插件 解决:Cannot access defaults field of Properties问题 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>
        </plugins>
    </build>

  <!--配置了一个名为"maven-war-plugin"的Maven War插件 解决:Cannot access defaults field of Properties问题 -->
   <!--  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>
        </plugins>
    </build> -->

  
  
  
  
  

  <properties>
	<!--  spring版本号  -->
	<spring.version>5.0.0.RELEASE</spring.version>
	<!--  mybatis版本号  -->
	<mybatis.version>3.2.7</mybatis.version>
	<!--  log4j日志文件管理包版本  -->
	<slf4j.version>1.7.7</slf4j.version>
	<log4j.version>1.2.17</log4j.version>
	
	
	  
	  
      

  
	
	
	
  </properties>
  
  
  <dependencies>
  
  
  
  <dependency>
      <groupId>javax.mail</groupId>
      <artifactId>mail</artifactId>
      <version>1.4.7</version>
    </dependency>
  
  	<!-- https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit -->
<!-- <dependency>
    <groupId>org.springframework.amqp</groupId>
    <artifactId>spring-rabbit</artifactId>
    <version>1.7.5.RELEASE</version>
</dependency> -->
  
<dependency>
	    <groupId>org.springframework.amqp</groupId>
	    <artifactId>spring-rabbit</artifactId>
	    <version>2.3.2</version>
	</dependency> 
 
  
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.12</version>
		<!--  表示开发的时候引入,发布的时候不会加载此包  -->
		<scope>test</scope>
	</dependency>
	<!--  spring核心包  -->
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>${spring.version}</version>
	</dependency>
	
	
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-web</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-oxm</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-tx</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-jdbc</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aop</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context-support</artifactId>
		<version>${spring.version}</version>
	</dependency>
	
	 <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
	
	
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-test</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<!--  mybatis核心包  -->
	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis</artifactId>
		<version>${mybatis.version}</version>
	</dependency>
	<!--  mybatis/spring包  -->
	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis-spring</artifactId>
		<version>1.3.1</version>
	</dependency>
	<!--  导入java ee jar 包  -->
	<dependency>
		<groupId>javax</groupId>
		<artifactId>javaee-api</artifactId>
		<version>7.0</version>
	</dependency>
	<!--  导入Mysql数据库链接jar包  -->
	<!--  导入dbcp的jar包,用来在applicationContext.xml中配置数据库  -->
	<dependency>
		<groupId>commons-dbcp</groupId>
		<artifactId>commons-dbcp</artifactId>
		<version>1.2.2</version>
	</dependency>
	<!--  JSTL标签类  -->
	<dependency>
		<groupId>jstl</groupId>
		<artifactId>jstl</artifactId>
		<version>1.2</version>
	</dependency>
	<!--  日志文件管理包  -->
	<!--  log start  -->
	<dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>${log4j.version}</version>
	</dependency>
	<!--  格式化对象,方便输出日志  -->
	<!-- <dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>fastjson</artifactId>
		<version>1.1.41</version>
	</dependency> -->
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<!--  log end  -->
	<!--  映入JSON  -->
	<dependency>
		<groupId>org.codehaus.jackson</groupId>
		<artifactId>jackson-mapper-asl</artifactId>
		<version>1.9.13</version>
	</dependency>
	
	 <dependency> 
			<groupId>com.fasterxml.jackson.core</groupId> 
			<artifactId>jackson-databind</artifactId> 
			<version>2.9.8</version> 
		</dependency> 
		<dependency> 
			<groupId>com.fasterxml.jackson.core</groupId> 
			<artifactId>jackson-core</artifactId> 
			<version>2.9.8</version> 
		</dependency> 
		<dependency> 
			<groupId>com.fasterxml.jackson.core</groupId> 
			<artifactId>jackson-annotations</artifactId> 
			<version>2.9.0</version> 
		</dependency>
	
	
	<!--  上传组件包  -->
	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>1.3.1</version>
	</dependency>
	<dependency>
		<groupId>commons-io</groupId>
		<artifactId>commons-io</artifactId>
		<version>2.4</version>
	</dependency>
	<dependency>
		<groupId>commons-codec</groupId>
		<artifactId>commons-codec</artifactId>
		<version>1.9</version>
	</dependency>
	<!--  https://mvnrepository.com/artifact/mysql/mysql-connector-java  -->
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.0.8</version>
	</dependency>
	<!-- <dependency>
		<groupId>com.mysql</groupId>
		<artifactId>mysql-connector-j</artifactId>
		<version>8.1.0</version>
	</dependency> -->
	<dependency>
		<groupId>org.apache.shiro</groupId>
		<artifactId>shiro-core</artifactId>
		<version>1.3.2</version>
	</dependency>
	<dependency>
		<groupId>org.apache.shiro</groupId>
		<artifactId>shiro-spring</artifactId>
		<version>1.3.2</version>
	</dependency>
	<!--  https://mvnrepository.com/artifact/org.apache.shiro/shiro-web  -->
	<dependency>
		<groupId>org.apache.shiro</groupId>
		<artifactId>shiro-web</artifactId>
		<version>1.2.4</version>
	</dependency>
	<!--  <dependency>
	    	<groupId>com.github.theborakompanioni</groupId>
	    	<artifactId>thymeleaf-extras-shiro</artifactId>
	    	<version>2.0.0</version>
	</dependency>  -->
  </dependencies>
</project>

3相关配置文件

3.1web.xml配置

主要的是前端控制器,加载soring-context.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_2_5.xsd" version="2.5">
  <display-name>wuliu</display-name>
  
<!--   这里定义了一个上下文参数(Context Parameter),用于指定 Spring 容器的配置文件。 -->
  <context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:spring-context.xml</param-value>
  </context-param>
  
  
  <!--里定义了一个过滤器(Filter),用于统一设置请求和响应的编码格式为 UTF-8。  -->
	<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>
	</filter>
	
	
	<!-- 这里将上面定义的过滤器与所有请求(URL Pattern)都进行了匹配,即所有请求都会被该过滤器处理。 -->
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	
	<!-- 这里定义了一个 Shiro 过滤器(Filter),用于实现身份认证和授权的功能。 -->
	<filter>
		<filter-name>shiroFilter</filter-name>
		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
		<init-param>
			<param-name>targetFilterLifecycle</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	
	<!--这里将上面定义的 Shiro 过滤器与所有请求(URL Pattern)都进行了匹配,即所有请求都会被该过滤器处理。这也说明了 Shiro 过滤器是一个全局过滤器。  -->
	<filter-mapping>
		<filter-name>shiroFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	
	<listener>
	    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
	    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>
	
	
	<!--这里定义了一个 Servlet(称为 Spring MVC Servlet),用于处理所有的用户请求,并将其分发到相应的控制器(Controller)中进行处理。  -->
	<servlet>
		<servlet-name>SpringMVC</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-context.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	
	
	<!--这里将上面定义的 Spring MVC Servlet 与所有请求(URL Pattern)都进行了匹配,即所有请求都会被该 Servlet 处理。  -->
	<servlet-mapping>
		<servlet-name>SpringMVC</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>





    <!--这里将静态资源文件(如 JavaScript 文件、CSS 文件、图片等)的 URL Pattern 都与默认 Servlet 进行了匹配,这样就可以提高 Web 应用程序的性能表现。  -->
	<servlet-mapping>
		<servlet-name>default</servlet-name>
		<url-pattern>*.js</url-pattern>
		<url-pattern>*.css</url-pattern>
		<url-pattern>/layui/*</url-pattern>
		<url-pattern>/img/*</url-pattern>
		<url-pattern>*.png</url-pattern>
		<url-pattern>*.jpg</url-pattern>
	</servlet-mapping>

   
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>login.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

3.2spring-mvc.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: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-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/mvc    
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
    <mvc:annotation-driven></mvc:annotation-driven>
    <context:component-scan base-package="com.it" />  
   	

   	
    <!--\u907F\u514DIE\u6267\u884CAJAX\u65F6\uFF0C\u8FD4\u56DEJSON\u51FA\u73B0\u4E0B\u8F7D\u6587\u4EF6 -->  
    <!-- <bean id="mappingJacksonHttpMessageConverter"  
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean>  
	
	
    <bean  
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="mappingJacksonHttpMessageConverter" /> JSON\u8F6C\u6362\u5668  
            </list>  
        </property>  
    </bean>   -->
    
    
    <bean id="zhou1" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/jsp/" />  
        <property name="suffix" value=".jsp" />  
    </bean>  
    
    <bean id="zhou" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/" />  
        <property name="suffix" value=".jsp" />  
    </bean> 
    
    
    <bean id="multipartResolver"    
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
        <!-- \u9ED8\u8BA4\u7F16\u7801 -->  
        <property name="defaultEncoding" value="utf-8" />    
        <!-- \u6587\u4EF6\u5927\u5C0F\u6700\u5927\u503C -->  
        <property name="maxUploadSize" value="10485760000" />    
        <!-- \u5185\u5B58\u4E2D\u7684\u6700\u5927\u503C -->  
        <property name="maxInMemorySize" value="40960" />    
    </bean> 
    
    <mvc:interceptors >
		<mvc:interceptor>
			<!-- 拦截匹配的请求 -->
			<mvc:mapping path="/fandonebySingleItemTracking_idyibu.do" /> 
			<mvc:mapping path="/updateById.do" />
			<mvc:mapping path="/deleteById.do" />
			<mvc:mapping path="/addone.do" />
			<!-- 但是排除下面这些,也就是不拦截请求 -->
			<!-- <mvc:exclude-mapping path="/commons/**" /> -->
			<bean class="com.it.interceptor.SingleItemTrackingInterceptor" />
		</mvc:interceptor>
    </mvc:interceptors>
    
   <mvc:resources location="/static/" mapping="/static/**" />
    
    

      
</beans>

3.3spring-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:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/util 
      http://www.springframework.org/schema/util/spring-util.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 引入配置文件 -->  
    <bean id="propertyConfigurer"  
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="location" value="classpath:jdbc.properties" />  
    </bean>  
  
  
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
        destroy-method="close">  
        <property name="driverClassName" value="${driver}" />  
        <property name="url" value="${url}" />  
        <property name="username" value="${username}" />  
        <property name="password" value="${password}" />  
        <!-- 初始化连接大小 -->  
        <property name="initialSize" value="${initialSize}"></property>  
        <!-- 连接池最大数量 -->  
        <property name="maxActive" value="${maxActive}"></property>  
        <!-- 连接池最大空闲 -->  
        <property name="maxIdle" value="${maxIdle}"></property>  
        <!-- 连接池最小空闲 -->  
        <property name="minIdle" value="${minIdle}"></property>  
        <!-- 获取连接最大等待时间 -->  
        <property name="maxWait" value="${maxWait}"></property>  
    </bean>  
  
    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <!-- 自动扫描mapping.xml文件 -->  
        <property name="mapperLocations" value="classpath:com/it/mapper/*.xml"></property>  
    </bean>  
  
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="com.it.mapper" />  
        <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>  
    
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

3.4spring-shiro.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
    default-lazy-init="true">

    <description>Shiro Configuration</description>

    <!-- 自定义Realm -->
    <bean id="myRealm" class="com.it.realm.ShiroRealm" />

    <!-- 安全管理器 -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="myRealm" />
    </bean>


    <!-- Shiro过滤器 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <!-- Shiro的核心安全接口,这个属性是必须的 -->
        <property name="securityManager" ref="securityManager" />
        <!-- 身份认证失败,则跳转到登录页面的配置 -->
        <property name="loginUrl" value="/adm_index/login" />
        <!-- 权限认证失败,则跳转到指定页面 -->
        <property name="unauthorizedUrl" value="/unauthorized" />
        <!-- Shiro连接约束配置,即过滤链的定义 -->
        <property name="filterChainDefinitions">
            <value>
                /login=anon
                /index/**=authc
            </value>
        </property>
    </bean>

    <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />

    <bean
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
        depends-on="lifecycleBeanPostProcessor" />

    <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
    <bean
        class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager" />
    </bean>

</beans>

3.5spring-emil.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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

 
    
    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.qq.com"/>
        <!-- <property name="port" value="465"/> -->
        <property name="username" value="957398289@qq.com"/>
        <property name="password" value="ugqjvyglwizxbbjj"/>
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">false</prop>
                <prop key="mail.smtp.ssl.enable">false</prop>
            </props>
        </property>
    </bean>
    
     <context:component-scan base-package="com.*">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>


</beans>

3.6spring-rabbitmq.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:context="http://www.springframework.org/schema/context"
       xmlns:rabbit="http://www.springframework.org/schema/rabbit"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       https://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/rabbit
       http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
    <!-- 定义rabbitmq connectionFactory -->
    <rabbit:connection-factory id="connectionFactory" host="localhost"
                               port="5672"
                               username="guest"
                               password="guest" />
    <!--定义管理交换机、队列-->
    <rabbit:admin connection-factory="connectionFactory"/>
    
    <bean id="rabbitMQCustomer" class="com.it.customer.RabbitMQCustomer"/>
 
  <rabbit:listener-container connection-factory="connectionFactory" auto-declare="true">
        <rabbit:listener ref="rabbitMQCustomer" queue-names="firstQueue1"/>
    </rabbit:listener-container>
 
    <!--定义rabbitTemplate对象操作可以在代码中方便发送消息-->
    <rabbit:template id="rabbitTemplate" connection-factory="connectionFactory"/>
</beans>

3.7log4j

#\u5B9A\u4E49LOG\u8F93\u51FA\u7EA7\u522B  
log4j.rootLogger=INFO,Console,File  
#\u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0  
log4j.appender.Console=org.apache.log4j.ConsoleAppender  
log4j.appender.Console.Target=System.out  
#\u53EF\u4EE5\u7075\u6D3B\u5730\u6307\u5B9A\u65E5\u5FD7\u8F93\u51FA\u683C\u5F0F\uFF0C\u4E0B\u9762\u4E00\u884C\u662F\u6307\u5B9A\u5177\u4F53\u7684\u683C\u5F0F  
log4j.appender.Console.layout = org.apache.log4j.PatternLayout  
log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n  
  
#\u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6  
log4j.appender.File = org.apache.log4j.RollingFileAppender  
#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55  
log4j.appender.File.File = logs/ssm.log  
#\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F  
log4j.appender.File.MaxFileSize = 10MB  
# \u8F93\u51FA\u6240\u4EE5\u65E5\u5FD7\uFF0C\u5982\u679C\u6362\u6210DEBUG\u8868\u793A\u8F93\u51FADEBUG\u4EE5\u4E0A\u7EA7\u522B\u65E5\u5FD7  
log4j.appender.File.Threshold = ALL  
log4j.appender.File.layout = org.apache.log4j.PatternLayout  
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n


3.8jdbc

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/xianmu?characterEncoding=utf8
username=root
password=123456
#\u5B9A\u4E49\u521D\u59CB\u8FDE\u63A5\u6570  
initialSize=0
#\u5B9A\u4E49\u6700\u5927\u8FDE\u63A5\u6570  
maxActive=20
#\u5B9A\u4E49\u6700\u5927\u7A7A\u95F2  
maxIdle=20
#\u5B9A\u4E49\u6700\u5C0F\u7A7A\u95F2  
minIdle=1
#\u5B9A\u4E49\u6700\u957F\u7B49\u5F85\u65F6\u95F4  
maxWait=60000

4主要代码实现

4.1拦截器特定请求

package com.it.interceptor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.it.bean.SingleItemTrackingDataSuoce;
import com.it.mapper.SingleItemTrackingDataSuoceMapper;

public class SingleItemTrackingInterceptor implements HandlerInterceptor{

	@Resource
	SingleItemTrackingDataSuoceMapper singleItemTrackingDataSuoceMapper;
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("==============preHandle============");
		//获取当前的登录地址
		String url=request.getRequestURI();
		String singleItemTracking_caozuo = url;
		System.out.println("=====url====="+url);
		
		LocalDateTime currentTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String singleItemTracking_time = currentTime.format(formatter);
        
        System.out.println("=====time===="+singleItemTracking_time);
        
		HttpSession session=request.getSession();
		String singleItemTracking_name=(String)session.getAttribute("username");
		/*if(url.indexOf("login")>0){*/
			SingleItemTrackingDataSuoce singleItemTrackingDataSuoce = new SingleItemTrackingDataSuoce();
			singleItemTrackingDataSuoce.setSingleItemTracking_name(singleItemTracking_name);
			singleItemTrackingDataSuoce.setSingleItemTracking_caozuo(singleItemTracking_caozuo+"是个好操作");
			singleItemTrackingDataSuoce.setSingleItemTracking_time(singleItemTracking_time);
			System.out.println("=====1====");
			System.out.println("==singleItemTrackingDataSuoce=="+singleItemTrackingDataSuoce.getSingleItemTracking_caozuo());
			singleItemTrackingDataSuoceMapper.addoneSingleItemTrackingDataSuoce(singleItemTrackingDataSuoce);
			System.out.println("=====2=====");
			return true; 
		/*}*/
		
		
			
		
		
		/*return false;*/
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println("==============postHandle============");
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("==============afterCompletion============");
		
	}

}

4.2rabbitmq和emil

package com.it.customer;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.tomcat.jni.Time;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.it.MailService.MailService;
import com.it.bean.Stockinorderdetails_zjj;
import com.it.bean.ToStock_zjj;
import com.it.bean.inventory;
import com.it.mapper.Stockinorderdetails_zjjMapper;
import com.it.mapper.ToStock_zjjMapper;
import com.it.mapper.inventoryMapper;

/*import com.it.service.StudentService;*/

/**
 * 我们需要告诉程序你这个RabbitMQCustomer消费者
 * 需要群监听那个队列。
 *
 */


@Component
public class RabbitMQCustomer implements MessageListener {
	
	
	@Resource
	inventoryMapper  inventoryMapper;
	
	@Resource
	ToStock_zjjMapper ToStock_zjjMapper;
	
	
	@Autowired
	private MailService mailService;

	
	@Resource
	Stockinorderdetails_zjjMapper Stockinorderdetails_zjjMapper;
    //回调方法,监听到消息后执行的方法
    public void onMessage(Message message) {
    	System.out.println("zhoujiajun1");
    	
    	
    	
    	
    	String Stockindetails_bh = new String(message.getBody());
    	
    	System.out.println("zhoujiajun1"+Stockindetails_bh);
    	
    	
    	Stockinorderdetails_zjj Stockinorderdetails_zjj = Stockinorderdetails_zjjMapper.findonebyStockindetails_bh(Stockindetails_bh);
    	
    	System.out.println("======Stockinorderdetails_zjj====="+Stockinorderdetails_zjj);
    	
    	String  shuliang = Stockinorderdetails_zjj.getQuantityofstockindetails();
    	
    	String id = Stockinorderdetails_zjj.getGoods_id();
    	
    	
    	String itemid ="1001";
    	
    	/*String  shuliang= "1001";*/
    	
    	System.out.println("======1====="+itemid);
    	
    	
    	inventory inventory = inventoryMapper.findone(itemid);
    	
    	
    	String hh = inventory.getInventoryquantity();
    	
    
    	System.out.println("======shuliang====="+shuliang);
    	System.out.println("======hh====="+hh);
    	
    	
    	inventory inventory1 = new inventory();
    	
    	inventory1.setItemid(itemid);
    	
    	String hhh = (Integer.parseInt(hh)+Integer.parseInt(shuliang))+"";
    	
    	System.out.println("======hhh====="+hhh);
    	
    	inventory1.setInventoryquantity(hhh);
    	
    	System.out.println("zhoujiajun1"+inventory1);
    	
    	inventoryMapper.updateInventory(inventory1);
    	
    
    	System.out.println("消费消息:"+new String(message.getBody()));//打印监听到的消息
    	
    	String to = "957398289@qq.com";
        String subject = "Hello";
        String text = "李雪其是个大傻逼,不知道跑哪快活去了,还来学习干嘛,浪法钱,又浪费一天吧,别来学习了,回去睡觉吧!";
        
        List<inventory>  inventorylist = inventoryMapper.findall();
        for(int i =0 ; i<inventorylist.size();i++){
        	
        	
        	if(Integer.parseInt(hhh)<Integer.parseInt(inventorylist.get(i).getProductalertvalue())){
          	  try{
             	   mailService.sendMail(to, subject, text);
                	
                } catch (Exception e) {
             	   System.out.println(e);
         		System.out.println("11111111");
                }
            }
        	
        	
        }
        
      
      
        System.out.println("发送成功:");
       /*studentService.findById("1001");*/
    }

}

	
	

package com.it.MailService;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

@Component
public class MailService {

	
	 @Autowired
	    private JavaMailSender mailSender;

	    public void sendMail(String to, String subject, String text) throws MessagingException {
	        /*SimpleMailMessage message = new SimpleMailMessage();
	        message.setTo(to);
	        message.setSubject(subject);
	        message.setText(text);
	        System.out.println("准备好了");
	        mailSender.send(message);*/
	        
	        MimeMessage message = mailSender.createMimeMessage();
	        MimeMessageHelper helper = new MimeMessageHelper(message, true); // 使用true指定支持附件
	        helper.setFrom("957398289@qq.com");
	        helper.setTo(to);
	        
	        System.out.println("====to==="+to);
	        helper.setSubject(subject);
	        helper.setText(text);
	        mailSender.send(message);
	        System.out.println("====邮件发送成功==="+to);
	    }

		
}

package com.it.contoller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.it.bean.Stockinorderdetails_zjj;
@Controller
public class rabbitmqController {
	@Resource
	private RabbitTemplate rabbitTemplate;
	
	
	
	@RequestMapping("/addQueueMessage")
	public String addQueueMessage(HttpServletRequest request){
		Stockinorderdetails_zjj Stockinorderdetails_zjj = (Stockinorderdetails_zjj) request.getAttribute("zhou");
		System.out.println("=============zosaihf==="+Stockinorderdetails_zjj);
		rabbitTemplate.convertAndSend("firstQueue1",""+Stockinorderdetails_zjj.getStockindetails_bh()+"");
		System.out.println("=======消息发送成功======");
		
		return "Stockin_zjj";
	}
}
@RequestMapping("/rkuandan.do")
	public  String zhoujiajun1(HttpSession session ,HttpServletRequest request,HttpServletResponse response){
		
		String toStock_bh = "1";
		String warehouse_id = request.getParameter("Warehouse_id");
		String stockindate = request.getParameter("stockindate");
		String documentdate = request.getParameter("Documentdate");
		
		/*String customer_id = request.getParameter("Customer_id");*/
		String incomingorder_bh = request.getParameter("Incomingorder_bh");
		String qualityinspector = request.getParameter("Qualityinspector");
		String ordercreator = request.getParameter("Ordercreator");
		String deliverydriver = request.getParameter("Deliverydriver");
		
		String note = request.getParameter("note");
		
		ToStock_zjj ToStock_zjj1 = ToStock_zjjMapper.findonebyid(incomingorder_bh);
		/*String customer_id = ToStock_zjj1.getCustomeroftheincomingorder_id();
		*/
		String customer_id = "1001";
		
		String toStockorReturnStockIn = ToStock_zjj1.getToStockorReturnStockIn();
		
		
//		给rabbitmq的数据
		
		
		/*session.setAttribute("rabbitmqruku", ToStock_zjj1);*/
		
		
		Stockin_zjj Stockin_zjj1 = new Stockin_zjj(toStock_bh, warehouse_id, stockindate, documentdate, customer_id, incomingorder_bh, qualityinspector, ordercreator, deliverydriver, toStockorReturnStockIn, note);
		System.out.println("===Stockin_zjj1======"+Stockin_zjj1);
		Stockin_zjjMapper.addoneStockin_zjj(Stockin_zjj1);
//		订单详情的数据展示
		/*session.getAttribute("");*/
		
		  String stockinbatchnumber = SnowFlakeUtils.nextId()+"";
		  String stockindetails_bh = SnowFlakeUtils.nextId()+"";
		  String toStock_bh1 = Stockin_zjj1.getToStock_bh();
		  String stockinlocation = "1";
		  String goods_id = "1001";
		  String quantityofstockindetails = "1";
		  String expirationdateofinventoryintake = "1";
		  String productiondateofinventoryintake = "1";
		  
		
		
		Stockinorderdetails_zjj   Stockinorderdetails_zjj1 = new Stockinorderdetails_zjj(stockinbatchnumber, stockindetails_bh, toStock_bh1, stockinlocation, goods_id, quantityofstockindetails, expirationdateofinventoryintake, productiondateofinventoryintake);
		
		Stockinorderdetails_zjjMapper.addoneStockinorderdetails_zjj(Stockinorderdetails_zjj1);
		
		request.setAttribute("zhou", Stockinorderdetails_zjj1);                    
		
		
		return "forward:/addQueueMessage";
	}

5总结

我们基于SSM框架(Spring+SpringMVC+MyBatis)开发了一个物流系统。系统实现了以下功能

使用RabbitMQ对入库的库存进行修改:通过RabbitMQ消息队列,实现异步处理入库操作和库存修改,提高系统性能和可扩展性。

使用拦截器拦截操作请求并记录操作日志:通过自定义拦截器,拦截用户的操作请求,并在执行写入数据库之前,记录下操作人、操作内容等信息,保留操作日志以便追溯和审计。

发送邮件提醒库存不足:当库存不足时,系统通过集成QQ邮箱,使用邮箱提醒功能,发送邮件到指定的邮箱地址,提醒相关人员库存不足的情况。

使用Shiro权限认证和授权:系统使用Shiro框架,对用户登录进行认证,通过用户名和密码验证用户身份,并为不同角色的用户分配相应的权限,实现权限管理和访问控制。

使用SVN进行团队协作:为了方便团队协作和版本管理,我们使用SVN作为代码版本控制工具,实现多人开发、代码合并和冲突解决等功能。

前端使用Layui框架:系统前端使用Layui框架进行页面布局和交互设计,提供了美观、简洁的用户界面和丰富的组件库。

使用MyBatis、MySQL数据库和C3P0数据库连接池:通过集成MyBatis框架,实现了与MySQL数据库的无缝集成,通过配置和映射文件,实现对象关系映射(ORM),提高了数据库操作的效率和可维护性。同时,引入C3P0数据库连接池,有效管理数据库连接的创建、释放和重用,提升系统性能和资源利用率。

使用Log4j进行日志管理:系统使用Log4j框架进行日志管理,可以将日志记录到多种目标,并提供了灵活的配置和日志级别控制,方便排查问题和系统监控。

通过以上技术和功能的应用,我们的物流系统实现了数据的持久化、操作的记录和追溯、库存提醒、权限认证和授权等核心功能,提高了系统的稳定性、可靠性和安全性。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值