SSM做一个简单的网上商城-搭建项目
2016-09-05 16:23
621 查看
项目目录:
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>
</configuration>
applicationContext.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" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 配置数据源的文件的位置 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 数据库连接池 -->
</bean>
<!-- 配置SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 指定数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 指定Mybatis配置文件的路径 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
</bean>
<!-- 配置mapper的扫描包 -->
<!-- 去bean的时候,的规则:bean的名字=原先类的类名小写 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.zc.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 事物的配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 通知 -->
<tx:advice transaction-manager="transactionManager" id="txAdvice">
<!-- 传播行为:什么方法需要用到事物 -->
<tx:attributes>
<tx:method name="*" rollback-for="RunTimeException"/>
<!--<tx:method name="save" propagation="REQUIRED"/>
<tx:method name="delete" propagation="REQUIRED"/>
<tx:method name="update" propagation="REQUIRED"/>
<tx:method name="insert" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
--></tx:attributes>
</tx:advice>
<!-- Aop 告诉spring哪里需要用到事物
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.etc.service.impl.*.*(..))"/>
</aop:config>-->
</beans>
dispatcher-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: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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 默认的注解映射支持 -->
<mvc:annotation-driven />
<!-- 启用自动扫描 -->
<context:component-scan base-package="com.zc.*"></context:component-scan>
<!-- 配置ViewResolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 支持上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
<!-- 对静态资源的引用 -->
<mvc:resources mapping="/bank_img/**" location="/bank_img/"
cache-period="31556926" />
<mvc:resources mapping="/images/**" location="/images/"
cache-period="31556926" />
<mvc:resources mapping="/image/**" location="/image/"
cache-period="31556926" />
<mvc:resources mapping="/js/**" location="/js/"
cache-period="31556926" />
<mvc:resources mapping="/css/**" location="/css/"
cache-period="31556926" />
<mvc:resources mapping="/products/**" location="/products/"
cache-period="31556926" />
</beans>
db.properties配置:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/jc?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
log4j.properties配置:
log4j.rootLogger=DEBUG, stdout
log4j.appender.CONSOLE.Encoding=UTF-8
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d[%t]%-5p[%c]-%m%n
log4j.appender.syslog.encoding=UTF-8
web.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- spring 容器配置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- spring 配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--
默认的配置文件的地址:/WEB-INF/servlet的名字-servlet.xml <init-param>-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<!--
第一种:*.html,*.action 就是过滤以.xxx结尾的 第二种:/ 所有的地址都会进入这个进行解析,静态的资源,需要添加配置
第三种:/* 他就是变态,连jsp页面都进来,结果就是报错XXXXX别用
-->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- post中文乱码处理 -->
<filter>
<filter-name>CharacterEncodingFilter</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>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
总体上就这样。
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>
</configuration>
applicationContext.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" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 配置数据源的文件的位置 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 数据库连接池 -->
</bean>
<!-- 配置SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 指定数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 指定Mybatis配置文件的路径 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
</bean>
<!-- 配置mapper的扫描包 -->
<!-- 去bean的时候,的规则:bean的名字=原先类的类名小写 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.zc.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 事物的配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 通知 -->
<tx:advice transaction-manager="transactionManager" id="txAdvice">
<!-- 传播行为:什么方法需要用到事物 -->
<tx:attributes>
<tx:method name="*" rollback-for="RunTimeException"/>
<!--<tx:method name="save" propagation="REQUIRED"/>
<tx:method name="delete" propagation="REQUIRED"/>
<tx:method name="update" propagation="REQUIRED"/>
<tx:method name="insert" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
--></tx:attributes>
</tx:advice>
<!-- Aop 告诉spring哪里需要用到事物
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.etc.service.impl.*.*(..))"/>
</aop:config>-->
</beans>
dispatcher-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: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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 默认的注解映射支持 -->
<mvc:annotation-driven />
<!-- 启用自动扫描 -->
<context:component-scan base-package="com.zc.*"></context:component-scan>
<!-- 配置ViewResolver -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 支持上传文件 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
<!-- 对静态资源的引用 -->
<mvc:resources mapping="/bank_img/**" location="/bank_img/"
cache-period="31556926" />
<mvc:resources mapping="/images/**" location="/images/"
cache-period="31556926" />
<mvc:resources mapping="/image/**" location="/image/"
cache-period="31556926" />
<mvc:resources mapping="/js/**" location="/js/"
cache-period="31556926" />
<mvc:resources mapping="/css/**" location="/css/"
cache-period="31556926" />
<mvc:resources mapping="/products/**" location="/products/"
cache-period="31556926" />
</beans>
db.properties配置:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/jc?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
log4j.properties配置:
log4j.rootLogger=DEBUG, stdout
log4j.appender.CONSOLE.Encoding=UTF-8
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d[%t]%-5p[%c]-%m%n
log4j.appender.syslog.encoding=UTF-8
web.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- spring 容器配置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- spring 配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--
默认的配置文件的地址:/WEB-INF/servlet的名字-servlet.xml <init-param>-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<!--
第一种:*.html,*.action 就是过滤以.xxx结尾的 第二种:/ 所有的地址都会进入这个进行解析,静态的资源,需要添加配置
第三种:/* 他就是变态,连jsp页面都进来,结果就是报错XXXXX别用
-->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- post中文乱码处理 -->
<filter>
<filter-name>CharacterEncodingFilter</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>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
总体上就这样。
相关文章推荐
- 使用idea搭建一个简单的SSM框架:(1)使用idea创建maven项目
- 基于vue-cli网上商城项目实战开发——搭建一个完整的SPA项目开发框架(一)
- 网上商城项目实战之使用nexus搭建maven私有服务器
- 08(maven+SSH)网上商城项目实战之使用nexus搭建maven私有服务器
- 用idea和weblogic简单搭建一个web项目
- 【SSH网上商城项目实战03】使用EasyUI搭建后台页面框架
- vue vuex vue-router vue-resource 简单的搭建一个 vue 小项目
- 04(maven+SSH)网上商城项目实战之Spring mybatis项目搭建
- 【SSH网上商城项目实战03】使用EasyUI搭建后台页面框架
- vue vuex vue-router vue-resource 简单的搭建一个 vue 小项目
- 使用Spring MVC 、Spring、 Mybatis搭建一个简单的项目
- ssm项目的简单搭建
- 【SSH网上商城项目实战10】商品类基本模块的搭建
- 【SSH网上商城项目实战03】使用EasyUI搭建后台页面框架
- VS SPEC FLOW接口自动化之环境搭建及一个简单项目(一)
- Mondrian用于web项目的一个简单搭建实验
- 发布一个开源项目,基于thinkphp框架搭建的一个简单框架
- SSH框架网上商城项目第3战之使用EasyUI搭建后台页面框架
- 【SSH网上商城项目实战03】使用EasyUI搭建后台页面框架
- eclipse+drools 6.5开发环境的搭建,以及创建一个简单的drools项目