Items for Technological process【No.01 a simple SSM combine】

配置文件如下

SQL文件内容:

/*
Navicat MySQL Data Transfer

Source Server         : zou
Source Server Version : 50096
Source Host           : localhost:3306
Source Database       : commodity_sys

Target Server Type    : MYSQL
Target Server Version : 50096
File Encoding         : 65001

Date: 2018-11-13 17:46:54
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `items`
-- ----------------------------
DROP TABLE IF EXISTS `items`;
CREATE TABLE `items` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(32) NOT NULL COMMENT '商品名称',
  `price` float(10,1) NOT NULL COMMENT '商品定价',
  `detail` text COMMENT '商品描述',
  `pic` varchar(64) default NULL COMMENT '商品图片',
  `createtime` datetime NOT NULL COMMENT '生产日期',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of items
-- ----------------------------
INSERT INTO `items` VALUES ('6', '测试', '10.0', '图片上传测试', '127abc49-2672-4103-b435-f0abdfe9af64.png', '2018-03-31 00:00:00');
INSERT INTO `items` VALUES ('7', '测试', '12.0', '测试', '9ad09b30-190b-4421-b32e-ff6e9441661a.png', '2018-02-28 00:00:00');
INSERT INTO `items` VALUES ('8', '测试', '10.0', '测试', 'cb6d513e-d19a-4f3d-8604-dc45cd0068ab.png', '2018-04-01 00:00:00');
INSERT INTO `items` VALUES ('9', '图片修改测试', '22.0', '图片修改测试', 'b2bb9363-668c-4570-914b-a5754c06b63a.jpg', '2018-04-24 00:00:00');
INSERT INTO `items` VALUES ('10', '测试', '12.0', '大四的', '6f403062-2156-4062-b4cb-6e67d2bde1f1.jpg', '2018-04-01 00:00:00');
INSERT INTO `items` VALUES ('13', '阿达的', '55.0', '打', '6961a62a-9461-4a3f-bdbf-569f11be2f2c.jpg', '2018-04-01 00:00:00');
INSERT INTO `items` VALUES ('15', '图片显示测试', '13.0', '图片显示测试', '4185bc11-48a7-4034-ad1e-79a238bb7f49.jpg', '2018-04-24 00:00:00');
INSERT INTO `items` VALUES ('16', '测试', '150.0', '彩色', 'a1283254-7285-4da3-85cd-3f7cd9f5d729.jpg', '2018-04-24 00:00:00');
INSERT INTO `items` VALUES ('17', 'dasdasd', '11.0', '大四的', '6492fc91-09fa-45d2-b0e0-9363cdc2cafa.jpg', '2018-04-24 00:00:00');
INSERT INTO `items` VALUES ('18', '的', '416.0', '安顺', 'b70b4aa3-b3fd-4581-88df-8d67b9667aae.jpg', '2018-04-24 00:00:00');

-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(32) NOT NULL COMMENT '用户名称',
  `password` varchar(32) NOT NULL COMMENT '密码',
  `birthday` date default NULL COMMENT '注册日期',
  `sex` char(1) default NULL COMMENT '性别,"男"“女”',
  `address` varchar(256) default NULL COMMENT '地址',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', 'admin', '123456', '2018-03-31', '1', '贵州贵阳');
INSERT INTO `user` VALUES ('2', 'qxb', '123456', '2018-04-01', '1', '美国纽约市');

appllicationContext.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: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.2.xsd 
	 http://www.springframework.org/schema/tx 
	 http://www.springframework.org/schema/tx/spring-tx.xsd
	 http://www.springframework.org/schema/context
	 http://www.springframework.org/schema/context/spring-context-3.2.xsd
	 http://www.springframework.org/schema/aop
	 http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
	 ">
	<!-- 扫描注解 -->
	<context:component-scan base-package="com.aaa"></context:component-scan>
	<!-- 加载 db.properties文件中的内容 -->
	<context:property-placeholder location="classpath:db.properties" />
	<!-- 数据源管理 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="url"
			value="${jdbc.url}?useUnicode=true&amp;characterEncoding=utf8">
		</property>
		<property name="driverClassName" value="${jdbc.driver}"></property>
		<property name="username" value="${jdbc.username}"></property>
		<property name="password" value="${jdbc.password}"></property>
	</bean>
	<!-- sessionFactory配置 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
	</bean>
	<!-- mapper 扫描器 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.aaa.mapper"></property>
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
	</bean>

	<!--事务管理器 ,使用spring 的jdbc的 事物控制类 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 开启事物 -->
	<tx:annotation-driven transaction-manager="transactionManager" />
	<!-- 配置事务的通知 切面 -->
	<tx:advice id="txadvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!--*代表过滤所有方法,required表示如果当前存在一个事务, 则支持当前事务,如果当前没有事务,则开启一个新的事务 -->
			<tx:method name="*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<!-- 切入点配置 -->
		<aop:pointcut expression="execution(* com.aaa.biz..*.*(..))"
			id="points" />
		<!-- 织入切入点和切面(事务通知) -->
		<aop:advisor advice-ref="txadvice" pointcut-ref="points" />
	</aop:config>

</beans>
	
	
	

SpringMvc.xml

<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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 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.2.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-3.2.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

	<!-- 开启注解配置 -->
	<mvc:annotation-driven conversion-service="conversionServer"></mvc:annotation-driven>
	<context:component-scan base-package="com.aaa.controller"></context:component-scan>
	<!-- 视图解析器 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
	<!--配置转换器 即自定义参数绑定 -->
	<bean id="conversionServer"
		class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
		<!-- 日期转换器 -->
		<property name="converters">
			<list>
				<bean class="com.aaa.converter.DateConverter" />
			</list>
		</property>
	</bean>
	<!-- 文件上传解析器 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
	</bean>

	<!--注解适配器 -->
	<bean
		class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean
					class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
			</list>
		</property>
	</bean>
	<!-- 拦截器 -->
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/**" />
			<bean class="com.aaa.inteceptor.LoginIncetepor"></bean>
		</mvc:interceptor>
	</mvc:interceptors>
</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="logImpl" value="LOG4J" />
	</settings>
	<!-- 和spring整合后enviroments配置将废除 -->
	<typeAliases>
		<!-- 单个定义别名 -->
		<!-- <typeAlias type="com.aaa.entity.User" alias="user"/> -->
		<!-- 批量定义别名 -->
		<package name="com.aaa.entity" />
	</typeAliases>

	<!-- 注册分页插件 -->
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageInterceptor">
		</plugin>
	</plugins>
</configuration>

db.properties:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/commodity_sys?useUnicode=true&amp;characterEncoding=utf8
jdbc.username=root
jdbc.password=123456

log4j.properties:

# Global logging configuration
#\u5728\u5f00\u53d1\u73af\u5883\u4e0b\u65e5\u5fd7\u7ea7\u522b\u8981\u8bbe\u7f6e\u6210DEBUG\uff0c\u751f\u4ea7\u73af\u5883\u8bbe\u7f6e\u6210info\u6216error
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

#4 mybatis \u663E\u793ASQL\u8BED\u53E5\u90E8\u5206
log4j.logger.org.mybatis=DEBUG
#log4j.logger.cn.tibet.cas.dao=DEBUG
#log4j.logger.org.mybatis.common.jdbc.SimpleDataSource=DEBUG#
#log4j.logger.org.mybatis.common.jdbc.ScriptRunner=DEBUG#
#log4j.logger.org.mybatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG#
#log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

d

猜你喜欢

转载自blog.csdn.net/sinat_39030079/article/details/102561259