Java从零打造企业级电商项目实战 项目初始化

1.项目初始化

1.1 新建maven项目

(1)new project -> maven -> maven-archetype-webapp

 

project name:mmall

project location:E:\lyh\file\workspace\mmall_learning\mmall

 

(2)新增main/java,src/test,src/test/java,并且分别标记为source root,test source root(选中文件,右键mark directory as)

 

1.2. 执行git命令,新增文件README.md和.gitignore

前提:IDEA已经把teminal改为了bash.exe

 

新增README.md 和 .gitignore文件:

git touch README.md

git touch .gitignore

 

1.3. 执行git命令,连接远程仓库,拉取和提交代码

前提:已经在码云上创建了项目和仓库,并且设置好了SSH公钥。

 

(在项目所在路径下)初始化本地仓库:

 

 查看当前变动状况:

 

 将代码变动增加到缓存区:

 

将代码变动提交本地仓库:

 

连接远程仓库并查看当前分支:

 

同步本地仓库代码到远程仓库:

 

此处要注意:因为第一次提交时,并没有先从远程仓库拉取代码,所以提交时会报错。

 

 所以先拉取远程仓库中的代码:

 

然后再同步本地仓库的代码到远程仓库,但是此时的提交仍然报错,显示本地分支最新程度低于远程分支:

 

所以就干脆强制提交,覆盖远程仓库的代码(因为第一次提交,其实远程仓库中就只有一个README.md文件):

 

1.4.查看远程仓库最新情况

已经有了最新提交上去的代码了。

 

1.5 pom.xml

这里就不一一解释了。

  c1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3   <modelVersion>4.0.0</modelVersion>
  4   <groupId>com</groupId>
  5   <artifactId>mmall</artifactId>
  6   <packaging>war</packaging>
  7   <version>1.0-SNAPSHOT</version>
  8   <name>mmall Maven Webapp</name>
  9   <url>http://maven.apache.org</url>
 10 
 11   <properties>
 12     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 13     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 14     <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
 15 
 16     <org.springframework.version>4.0.0.RELEASE</org.springframework.version>
 17     <org.mybatis.version>3.4.1</org.mybatis.version>
 18     <org.mybatis.spring.version>1.3.0</org.mybatis.spring.version>
 19   </properties>
 20 
 21   <dependencies>
 22 
 23     <dependency>
 24       <groupId>org.apache.tomcat</groupId>
 25       <artifactId>tomcat-servlet-api</artifactId>
 26       <version>7.0.64</version>
 27     </dependency>
 28 
 29     <dependency>
 30       <groupId>org.springframework</groupId>
 31       <artifactId>spring-webmvc</artifactId>
 32       <version>${org.springframework.version}</version>
 33     </dependency>
 34 
 35     <dependency>
 36       <groupId>org.springframework</groupId>
 37       <artifactId>spring-oxm</artifactId>
 38       <version>${org.springframework.version}</version>
 39     </dependency>
 40 
 41     <dependency>
 42       <groupId>org.springframework</groupId>
 43       <artifactId>spring-jdbc</artifactId>
 44       <version>${org.springframework.version}</version>
 45     </dependency>
 46 
 47     <dependency>
 48       <groupId>org.springframework</groupId>
 49       <artifactId>spring-tx</artifactId>
 50       <version>${org.springframework.version}</version>
 51     </dependency>
 52 
 53     <dependency>
 54       <groupId>org.springframework</groupId>
 55       <artifactId>spring-test</artifactId>
 56       <version>${org.springframework.version}</version>
 57     </dependency>
 58 
 59     <!-- lp -->
 60     <dependency>
 61       <groupId>org.aspectj</groupId>
 62       <artifactId>aspectjweaver</artifactId>
 63       <version>1.7.3</version>
 64     </dependency>
 65 
 66     <dependency>
 67       <groupId>org.mybatis</groupId>
 68       <artifactId>mybatis-spring</artifactId>
 69       <version>${org.mybatis.spring.version}</version>
 70     </dependency>
 71     <dependency>
 72       <groupId>org.mybatis</groupId>
 73       <artifactId>mybatis</artifactId>
 74       <version>${org.mybatis.version}</version>
 75     </dependency>
 76 
 77     <!-- lp -->
 78     <dependency>
 79       <groupId>org.aspectj</groupId>
 80       <artifactId>aspectjrt</artifactId>
 81       <version>1.6.11</version>
 82     </dependency>
 83 
 84     <!-- json序列化和反序列化-->
 85     <dependency>
 86       <groupId>org.codehaus.jackson</groupId>
 87       <artifactId>jackson-mapper-asl</artifactId>
 88       <version>1.9.12</version>
 89     </dependency>
 90 
 91     <!--连接池-->
 92     <dependency>
 93       <groupId>commons-dbcp</groupId>
 94       <artifactId>commons-dbcp</artifactId>
 95       <version>1.4</version>
 96       <!--<scope>runtime</scope>-->
 97     </dependency>
 98 
 99 
100     <dependency>
101       <groupId>ch.qos.logback</groupId>
102       <artifactId>logback-classic</artifactId>
103       <version>1.1.2</version>
104       <scope>compile</scope>
105     </dependency>
106     <dependency>
107       <groupId>ch.qos.logback</groupId>
108       <artifactId>logback-core</artifactId>
109       <version>1.1.2</version>
110       <scope>compile</scope>
111     </dependency>
112 
113     <dependency>
114       <groupId>mysql</groupId>
115       <artifactId>mysql-connector-java</artifactId>
116       <version>5.1.6</version>
117     </dependency>
118 
119     <dependency>
120       <groupId>com.google.guava</groupId>
121       <artifactId>guava</artifactId>
122       <version>20.0</version>
123     </dependency>
124 
125 
126     <dependency>
127       <groupId>org.apache.commons</groupId>
128       <artifactId>commons-lang3</artifactId>
129       <version>3.5</version>
130     </dependency>
131 
132 
133     <dependency>
134       <groupId>commons-collections</groupId>
135       <artifactId>commons-collections</artifactId>
136       <version>3.2.1</version>
137     </dependency>
138 
139 
140     <dependency>
141       <groupId>junit</groupId>
142       <artifactId>junit</artifactId>
143       <version>4.12</version>
144       <!--<scope>test</scope>-->
145     </dependency>
146 
147     <!-- 时间处理-->
148     <dependency>
149       <groupId>joda-time</groupId>
150       <artifactId>joda-time</artifactId>
151       <version>2.3</version>
152     </dependency>
153 
154     <!-- id加密解密 -->
155     <dependency>
156       <groupId>org.hashids</groupId>
157       <artifactId>hashids</artifactId>
158       <version>1.0.1</version>
159     </dependency>
160 
161     <!-- ftpclient -->
162     <dependency>
163       <groupId>commons-net</groupId>
164       <artifactId>commons-net</artifactId>
165       <version>3.1</version>
166     </dependency>
167 
168     <!-- file upload -->
169 
170     <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
171     <dependency>
172       <groupId>commons-fileupload</groupId>
173       <artifactId>commons-fileupload</artifactId>
174       <version>1.2.2</version>
175     </dependency>
176 
177     <dependency>
178       <groupId>commons-io</groupId>
179       <artifactId>commons-io</artifactId>
180       <version>2.0.1</version>
181     </dependency>
182 
183     <!-- mybatis pager -->
184     <dependency>
185       <groupId>com.github.pagehelper</groupId>
186       <artifactId>pagehelper</artifactId>
187       <version>4.1.0</version>
188     </dependency>
189 
190     <dependency>
191       <groupId>com.github.miemiedev</groupId>
192       <artifactId>mybatis-paginator</artifactId>
193       <version>1.2.17</version>
194     </dependency>
195 
196     <dependency>
197       <groupId>com.github.jsqlparser</groupId>
198       <artifactId>jsqlparser</artifactId>
199       <version>0.9.4</version>
200     </dependency>
201 
202     <!-- alipay -->
203     <dependency>
204       <groupId>commons-codec</groupId>
205       <artifactId>commons-codec</artifactId>
206       <version>1.10</version>
207     </dependency>
208     <dependency>
209       <groupId>commons-configuration</groupId>
210       <artifactId>commons-configuration</artifactId>
211       <version>1.10</version>
212     </dependency>
213     <dependency>
214       <groupId>commons-lang</groupId>
215       <artifactId>commons-lang</artifactId>
216       <version>2.6</version>
217     </dependency>
218     <dependency>
219       <groupId>commons-logging</groupId>
220       <artifactId>commons-logging</artifactId>
221       <version>1.1.1</version>
222     </dependency>
223     <dependency>
224       <groupId>com.google.zxing</groupId>
225       <artifactId>core</artifactId>
226       <version>2.1</version>
227     </dependency>
228     <dependency>
229       <groupId>com.google.code.gson</groupId>
230       <artifactId>gson</artifactId>
231       <version>2.3.1</version>
232     </dependency>
233     <dependency>
234       <groupId>org.hamcrest</groupId>
235       <artifactId>hamcrest-core</artifactId>
236       <version>1.3</version>
237     </dependency>
238 
239     <dependency>
240       <groupId>redis.clients</groupId>
241       <artifactId>jedis</artifactId>
242       <version>2.9.0</version>
243     </dependency>
244   </dependencies>
245 
246 
247   <build>
248     <finalName>mmall</finalName>
249     <plugins>
250       <plugin>
251         <groupId>org.mybatis.generator</groupId>
252         <artifactId>mybatis-generator-maven-plugin</artifactId>
253         <version>1.3.2</version>
254         <configuration>
255           <verbose>true</verbose>
256           <overwrite>true</overwrite>
257         </configuration>
258       </plugin>
259 
260       <!-- maven的核心插件之-complier插件默认只支持编译Java 1.4,因此需要加上支持高版本jre的配置,在pom.xml里面加上 增加编译插件 -->
261       <plugin>
262         <groupId>org.apache.maven.plugins</groupId>
263         <artifactId>maven-compiler-plugin</artifactId>
264         <configuration>
265           <source>1.7</source>
266           <target>1.7</target>
267           <encoding>UTF-8</encoding>
268           <!-- 编译时引入本地lib下的jar包。因为后续会将集成支付宝需要的jar放在lib下,这样配置后发布到线上时,编译不会报错 -->
269           <compilerArguments>
270             <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
271           </compilerArguments>
272         </configuration>
273       </plugin>
274     </plugins>
275 
276   </build>
277 
278 
279 </project>
pom.xml

 

1.6 项目package的层次设计

 

1.7 mybatis-generator的配置与使用

先确保数据库连接ok,并且表已经建好。

建表语句xml:

  1 /*
  2  Navicat Premium Data Transfer
  3 
  4  Source Server         : 182.92.82.103
  5  Source Server Type    : MySQL
  6  Source Server Version : 50173
  7  Source Host           : 182.92.82.103
  8  Source Database       : mmall
  9 
 10  Target Server Type    : MySQL
 11  Target Server Version : 50173
 12  File Encoding         : utf-8
 13 
 14  Date: 04/13/2017 22:04:18 PM
 15 */
 16 
 17 SET NAMES utf8;
 18 SET FOREIGN_KEY_CHECKS = 0;
 19 
 20 -- ----------------------------
 21 --  Table structure for `mmall_cart`
 22 -- ----------------------------
 23 DROP TABLE IF EXISTS `mmall_cart`;
 24 CREATE TABLE `mmall_cart` (
 25   `id` int(11) NOT NULL AUTO_INCREMENT,
 26   `user_id` int(11) NOT NULL,
 27   `product_id` int(11) DEFAULT NULL COMMENT '商品id',
 28   `quantity` int(11) DEFAULT NULL COMMENT '数量',
 29   `checked` int(11) DEFAULT NULL COMMENT '是否选择,1=已勾选,0=未勾选',
 30   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
 31   `update_time` datetime DEFAULT NULL COMMENT '更新时间',
 32   PRIMARY KEY (`id`),
 33   KEY `user_id_index` (`user_id`) USING BTREE
 34 ) ENGINE=InnoDB AUTO_INCREMENT=146 DEFAULT CHARSET=utf8;
 35 
 36 -- ----------------------------
 37 --  Records of `mmall_cart`
 38 -- ----------------------------
 39 BEGIN;
 40 INSERT INTO `mmall_cart` VALUES ('126', '21', '26', '1', '1', '2017-04-13 21:27:06', '2017-04-13 21:27:06');
 41 COMMIT;
 42 
 43 -- ----------------------------
 44 --  Table structure for `mmall_category`
 45 -- ----------------------------
 46 DROP TABLE IF EXISTS `mmall_category`;
 47 CREATE TABLE `mmall_category` (
 48   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '类别Id',
 49   `parent_id` int(11) DEFAULT NULL COMMENT '父类别id当id=0时说明是根节点,一级类别',
 50   `name` varchar(50) DEFAULT NULL COMMENT '类别名称',
 51   `status` tinyint(1) DEFAULT '1' COMMENT '类别状态1-正常,2-已废弃',
 52   `sort_order` int(4) DEFAULT NULL COMMENT '排序编号,同类展示顺序,数值相等则自然排序',
 53   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
 54   `update_time` datetime DEFAULT NULL COMMENT '更新时间',
 55   PRIMARY KEY (`id`)
 56 ) ENGINE=InnoDB AUTO_INCREMENT=100032 DEFAULT CHARSET=utf8;
 57 
 58 -- ----------------------------
 59 --  Records of `mmall_category`
 60 -- ----------------------------
 61 BEGIN;
 62 INSERT INTO `mmall_category` VALUES ('100001', '0', '家用电器', '1', null, '2017-03-25 16:46:00', '2017-03-25 16:46:00'), ('100002', '0', '数码3C', '1', null, '2017-03-25 16:46:21', '2017-03-25 16:46:21'), ('100003', '0', '服装箱包', '1', null, '2017-03-25 16:49:53', '2017-03-25 16:49:53'), ('100004', '0', '食品生鲜', '1', null, '2017-03-25 16:50:19', '2017-03-25 16:50:19'), ('100005', '0', '酒水饮料', '1', null, '2017-03-25 16:50:29', '2017-03-25 16:50:29'), ('100006', '100001', '冰箱', '1', null, '2017-03-25 16:52:15', '2017-03-25 16:52:15'), ('100007', '100001', '电视', '1', null, '2017-03-25 16:52:26', '2017-03-25 16:52:26'), ('100008', '100001', '洗衣机', '1', null, '2017-03-25 16:52:39', '2017-03-25 16:52:39'), ('100009', '100001', '空调', '1', null, '2017-03-25 16:52:45', '2017-03-25 16:52:45'), ('100010', '100001', '电热水器', '1', null, '2017-03-25 16:52:54', '2017-03-25 16:52:54'), ('100011', '100002', '电脑', '1', null, '2017-03-25 16:53:18', '2017-03-25 16:53:18'), ('100012', '100002', '手机', '1', null, '2017-03-25 16:53:27', '2017-03-25 16:53:27'), ('100013', '100002', '平板电脑', '1', null, '2017-03-25 16:53:35', '2017-03-25 16:53:35'), ('100014', '100002', '数码相机', '1', null, '2017-03-25 16:53:56', '2017-03-25 16:53:56'), ('100015', '100002', '3C配件', '1', null, '2017-03-25 16:54:07', '2017-03-25 16:54:07'), ('100016', '100003', '女装', '1', null, '2017-03-25 16:54:44', '2017-03-25 16:54:44'), ('100017', '100003', '帽子', '1', null, '2017-03-25 16:54:51', '2017-03-25 16:54:51'), ('100018', '100003', '旅行箱', '1', null, '2017-03-25 16:55:02', '2017-03-25 16:55:02'), ('100019', '100003', '手提包', '1', null, '2017-03-25 16:55:09', '2017-03-25 16:55:09'), ('100020', '100003', '保暖内衣', '1', null, '2017-03-25 16:55:18', '2017-03-25 16:55:18'), ('100021', '100004', '零食', '1', null, '2017-03-25 16:55:30', '2017-03-25 16:55:30'), ('100022', '100004', '生鲜', '1', null, '2017-03-25 16:55:37', '2017-03-25 16:55:37'), ('100023', '100004', '半成品菜', '1', null, '2017-03-25 16:55:47', '2017-03-25 16:55:47'), ('100024', '100004', '速冻食品', '1', null, '2017-03-25 16:55:56', '2017-03-25 16:55:56'), ('100025', '100004', '进口食品', '1', null, '2017-03-25 16:56:06', '2017-03-25 16:56:06'), ('100026', '100005', '白酒', '1', null, '2017-03-25 16:56:22', '2017-03-25 16:56:22'), ('100027', '100005', '红酒', '1', null, '2017-03-25 16:56:30', '2017-03-25 16:56:30'), ('100028', '100005', '饮料', '1', null, '2017-03-25 16:56:37', '2017-03-25 16:56:37'), ('100029', '100005', '调制鸡尾酒', '1', null, '2017-03-25 16:56:45', '2017-03-25 16:56:45'), ('100030', '100005', '进口洋酒', '1', null, '2017-03-25 16:57:05', '2017-03-25 16:57:05');
 63 COMMIT;
 64 
 65 -- ----------------------------
 66 --  Table structure for `mmall_order`
 67 -- ----------------------------
 68 DROP TABLE IF EXISTS `mmall_order`;
 69 CREATE TABLE `mmall_order` (
 70   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单id',
 71   `order_no` bigint(20) DEFAULT NULL COMMENT '订单号',
 72   `user_id` int(11) DEFAULT NULL COMMENT '用户id',
 73   `shipping_id` int(11) DEFAULT NULL,
 74   `payment` decimal(20,2) DEFAULT NULL COMMENT '实际付款金额,单位是元,保留两位小数',
 75   `payment_type` int(4) DEFAULT NULL COMMENT '支付类型,1-在线支付',
 76   `postage` int(10) DEFAULT NULL COMMENT '运费,单位是元',
 77   `status` int(10) DEFAULT NULL COMMENT '订单状态:0-已取消-10-未付款,20-已付款,40-已发货,50-交易成功,60-交易关闭',
 78   `payment_time` datetime DEFAULT NULL COMMENT '支付时间',
 79   `send_time` datetime DEFAULT NULL COMMENT '发货时间',
 80   `end_time` datetime DEFAULT NULL COMMENT '交易完成时间',
 81   `close_time` datetime DEFAULT NULL COMMENT '交易关闭时间',
 82   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
 83   `update_time` datetime DEFAULT NULL COMMENT '更新时间',
 84   PRIMARY KEY (`id`),
 85   UNIQUE KEY `order_no_index` (`order_no`) USING BTREE
 86 ) ENGINE=InnoDB AUTO_INCREMENT=118 DEFAULT CHARSET=utf8;
 87 
 88 -- ----------------------------
 89 --  Records of `mmall_order`
 90 -- ----------------------------
 91 BEGIN;
 92 INSERT INTO `mmall_order` VALUES ('103', '1491753014256', '1', '25', '13998.00', '1', '0', '10', null, null, null, null, '2017-04-09 23:50:14', '2017-04-09 23:50:14'), ('104', '1491830695216', '1', '26', '13998.00', '1', '0', '10', null, null, null, null, '2017-04-10 21:24:55', '2017-04-10 21:24:55'), ('105', '1492089528889', '1', '29', '3299.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:18:48', '2017-04-13 21:18:48'), ('106', '1492090946105', '1', '29', '27894.00', '1', '0', '20', '2017-04-13 21:42:40', null, null, null, '2017-04-13 21:42:26', '2017-04-13 21:42:41'), ('107', '1492091003128', '1', '29', '8597.00', '1', '0', '20', '2017-04-13 21:43:38', null, null, null, '2017-04-13 21:43:23', '2017-04-13 21:43:38'), ('108', '1492091051313', '1', '29', '1999.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:11', '2017-04-13 21:44:11'), ('109', '1492091061513', '1', '29', '6598.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:21', '2017-04-13 21:44:21'), ('110', '1492091069563', '1', '29', '3299.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:29', '2017-04-13 21:44:29'), ('111', '1492091076073', '1', '29', '4299.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:36', '2017-04-13 21:44:36'), ('112', '1492091083720', '1', '29', '3299.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:43', '2017-04-13 21:44:43'), ('113', '1492091089794', '1', '29', '6999.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:49', '2017-04-13 21:44:49'), ('114', '1492091096400', '1', '29', '6598.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:44:56', '2017-04-13 21:44:56'), ('115', '1492091102371', '1', '29', '3299.00', '1', '0', '10', null, null, null, null, '2017-04-13 21:45:02', '2017-04-13 21:45:02'), ('116', '1492091110004', '1', '29', '8598.00', '1', '0', '40', '2017-04-13 21:55:16', '2017-04-13 21:55:31', null, null, '2017-04-13 21:45:09', '2017-04-13 21:55:31'), ('117', '1492091141269', '1', '29', '22894.00', '1', '0', '20', '2017-04-13 21:46:06', null, null, null, '2017-04-13 21:45:41', '2017-04-13 21:46:07');
 93 COMMIT;
 94 
 95 -- ----------------------------
 96 --  Table structure for `mmall_order_item`
 97 -- ----------------------------
 98 DROP TABLE IF EXISTS `mmall_order_item`;
 99 CREATE TABLE `mmall_order_item` (
100   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单子表id',
101   `user_id` int(11) DEFAULT NULL,
102   `order_no` bigint(20) DEFAULT NULL,
103   `product_id` int(11) DEFAULT NULL COMMENT '商品id',
104   `product_name` varchar(100) DEFAULT NULL COMMENT '商品名称',
105   `product_image` varchar(500) DEFAULT NULL COMMENT '商品图片地址',
106   `current_unit_price` decimal(20,2) DEFAULT NULL COMMENT '生成订单时的商品单价,单位是元,保留两位小数',
107   `quantity` int(10) DEFAULT NULL COMMENT '商品数量',
108   `total_price` decimal(20,2) DEFAULT NULL COMMENT '商品总价,单位是元,保留两位小数',
109   `create_time` datetime DEFAULT NULL,
110   `update_time` datetime DEFAULT NULL,
111   PRIMARY KEY (`id`),
112   KEY `order_no_index` (`order_no`) USING BTREE,
113   KEY `order_no_user_id_index` (`user_id`,`order_no`) USING BTREE
114 ) ENGINE=InnoDB AUTO_INCREMENT=135 DEFAULT CHARSET=utf8;
115 
116 -- ----------------------------
117 --  Records of `mmall_order_item`
118 -- ----------------------------
119 BEGIN;
120 INSERT INTO `mmall_order_item` VALUES ('113', '1', '1491753014256', '26', 'Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg', '6999.00', '2', '13998.00', '2017-04-09 23:50:14', '2017-04-09 23:50:14'), ('114', '1', '1491830695216', '26', 'Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg', '6999.00', '2', '13998.00', '2017-04-10 21:24:55', '2017-04-10 21:24:55'), ('115', '1', '1492089528889', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '1', '3299.00', '2017-04-13 21:18:48', '2017-04-13 21:18:48'), ('116', '1', '1492090946105', '29', 'Haier/海尔HJ100-1HU1 10公斤滚筒洗衣机全自动带烘干家用大容量 洗烘一体', '173335a4-5dce-4afd-9f18-a10623724c4e.jpeg', '4299.00', '2', '8598.00', '2017-04-13 21:42:26', '2017-04-13 21:42:26'), ('117', '1', '1492090946105', '28', '4+64G送手环/Huawei/华为 nova 手机P9/P10plus青春', '0093f5d3-bdb4-4fb0-bec5-5465dfd26363.jpeg', '1999.00', '1', '1999.00', '2017-04-13 21:42:26', '2017-04-13 21:42:26'), ('118', '1', '1492090946105', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '1', '3299.00', '2017-04-13 21:42:26', '2017-04-13 21:42:26'), ('119', '1', '1492090946105', '26', 'Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg', '6999.00', '2', '13998.00', '2017-04-13 21:42:26', '2017-04-13 21:42:26'), ('120', '1', '1492091003128', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '2', '6598.00', '2017-04-13 21:43:23', '2017-04-13 21:43:23'), ('121', '1', '1492091003128', '28', '4+64G送手环/Huawei/华为 nova 手机P9/P10plus青春', '0093f5d3-bdb4-4fb0-bec5-5465dfd26363.jpeg', '1999.00', '1', '1999.00', '2017-04-13 21:43:23', '2017-04-13 21:43:23'), ('122', '1', '1492091051313', '28', '4+64G送手环/Huawei/华为 nova 手机P9/P10plus青春', '0093f5d3-bdb4-4fb0-bec5-5465dfd26363.jpeg', '1999.00', '1', '1999.00', '2017-04-13 21:44:11', '2017-04-13 21:44:11'), ('123', '1', '1492091061513', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '2', '6598.00', '2017-04-13 21:44:21', '2017-04-13 21:44:21'), ('124', '1', '1492091069563', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '1', '3299.00', '2017-04-13 21:44:29', '2017-04-13 21:44:29'), ('125', '1', '1492091076073', '29', 'Haier/海尔HJ100-1HU1 10公斤滚筒洗衣机全自动带烘干家用大容量 洗烘一体', '173335a4-5dce-4afd-9f18-a10623724c4e.jpeg', '4299.00', '1', '4299.00', '2017-04-13 21:44:36', '2017-04-13 21:44:36'), ('126', '1', '1492091083720', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '1', '3299.00', '2017-04-13 21:44:43', '2017-04-13 21:44:43'), ('127', '1', '1492091089794', '26', 'Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg', '6999.00', '1', '6999.00', '2017-04-13 21:44:49', '2017-04-13 21:44:49'), ('128', '1', '1492091096400', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '2', '6598.00', '2017-04-13 21:44:56', '2017-04-13 21:44:56'), ('129', '1', '1492091102371', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '1', '3299.00', '2017-04-13 21:45:02', '2017-04-13 21:45:02'), ('130', '1', '1492091110004', '29', 'Haier/海尔HJ100-1HU1 10公斤滚筒洗衣机全自动带烘干家用大容量 洗烘一体', '173335a4-5dce-4afd-9f18-a10623724c4e.jpeg', '4299.00', '2', '8598.00', '2017-04-13 21:45:09', '2017-04-13 21:45:09'), ('131', '1', '1492091141269', '26', 'Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg', '6999.00', '1', '6999.00', '2017-04-13 21:45:41', '2017-04-13 21:45:41'), ('132', '1', '1492091141269', '27', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', '3299.00', '1', '3299.00', '2017-04-13 21:45:41', '2017-04-13 21:45:41'), ('133', '1', '1492091141269', '29', 'Haier/海尔HJ100-1HU1 10公斤滚筒洗衣机全自动带烘干家用大容量 洗烘一体', '173335a4-5dce-4afd-9f18-a10623724c4e.jpeg', '4299.00', '2', '8598.00', '2017-04-13 21:45:41', '2017-04-13 21:45:41'), ('134', '1', '1492091141269', '28', '4+64G送手环/Huawei/华为 nova 手机P9/P10plus青春', '0093f5d3-bdb4-4fb0-bec5-5465dfd26363.jpeg', '1999.00', '2', '3998.00', '2017-04-13 21:45:41', '2017-04-13 21:45:41');
121 COMMIT;
122 
123 -- ----------------------------
124 --  Table structure for `mmall_pay_info`
125 -- ----------------------------
126 DROP TABLE IF EXISTS `mmall_pay_info`;
127 CREATE TABLE `mmall_pay_info` (
128   `id` int(11) NOT NULL AUTO_INCREMENT,
129   `user_id` int(11) DEFAULT NULL COMMENT '用户id',
130   `order_no` bigint(20) DEFAULT NULL COMMENT '订单号',
131   `pay_platform` int(10) DEFAULT NULL COMMENT '支付平台:1-支付宝,2-微信',
132   `platform_number` varchar(200) DEFAULT NULL COMMENT '支付宝支付流水号',
133   `platform_status` varchar(20) DEFAULT NULL COMMENT '支付宝支付状态',
134   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
135   `update_time` datetime DEFAULT NULL COMMENT '更新时间',
136   PRIMARY KEY (`id`)
137 ) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8;
138 
139 -- ----------------------------
140 --  Records of `mmall_pay_info`
141 -- ----------------------------
142 BEGIN;
143 INSERT INTO `mmall_pay_info` VALUES ('53', '1', '1492090946105', '1', '2017041321001004300200116250', 'WAIT_BUYER_PAY', '2017-04-13 21:42:33', '2017-04-13 21:42:33'), ('54', '1', '1492090946105', '1', '2017041321001004300200116250', 'TRADE_SUCCESS', '2017-04-13 21:42:41', '2017-04-13 21:42:41'), ('55', '1', '1492091003128', '1', '2017041321001004300200116251', 'WAIT_BUYER_PAY', '2017-04-13 21:43:31', '2017-04-13 21:43:31'), ('56', '1', '1492091003128', '1', '2017041321001004300200116251', 'TRADE_SUCCESS', '2017-04-13 21:43:38', '2017-04-13 21:43:38'), ('57', '1', '1492091141269', '1', '2017041321001004300200116252', 'WAIT_BUYER_PAY', '2017-04-13 21:45:59', '2017-04-13 21:45:59'), ('58', '1', '1492091141269', '1', '2017041321001004300200116252', 'TRADE_SUCCESS', '2017-04-13 21:46:07', '2017-04-13 21:46:07'), ('59', '1', '1492091110004', '1', '2017041321001004300200116396', 'WAIT_BUYER_PAY', '2017-04-13 21:55:08', '2017-04-13 21:55:08'), ('60', '1', '1492091110004', '1', '2017041321001004300200116396', 'TRADE_SUCCESS', '2017-04-13 21:55:17', '2017-04-13 21:55:17');
144 COMMIT;
145 
146 -- ----------------------------
147 --  Table structure for `mmall_product`
148 -- ----------------------------
149 DROP TABLE IF EXISTS `mmall_product`;
150 CREATE TABLE `mmall_product` (
151   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '商品id',
152   `category_id` int(11) NOT NULL COMMENT '分类id,对应mmall_category表的主键',
153   `name` varchar(100) NOT NULL COMMENT '商品名称',
154   `subtitle` varchar(200) DEFAULT NULL COMMENT '商品副标题',
155   `main_image` varchar(500) DEFAULT NULL COMMENT '产品主图,url相对地址',
156   `sub_images` text COMMENT '图片地址,json格式,扩展用',
157   `detail` text COMMENT '商品详情',
158   `price` decimal(20,2) NOT NULL COMMENT '价格,单位-元保留两位小数',
159   `stock` int(11) NOT NULL COMMENT '库存数量',
160   `status` int(6) DEFAULT '1' COMMENT '商品状态.1-在售 2-下架 3-删除',
161   `create_time` datetime DEFAULT NULL COMMENT '创建时间',
162   `update_time` datetime DEFAULT NULL COMMENT '更新时间',
163   PRIMARY KEY (`id`)
164 ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;
165 
166 -- ----------------------------
167 --  Records of `mmall_product`
168 -- ----------------------------
169 BEGIN;
170 INSERT INTO `mmall_product` VALUES ('26', '100002', 'Apple iPhone 7 Plus (A1661) 128G 玫瑰金色 移动联通电信4G手机', 'iPhone 7,现更以红色呈现。', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg', '241997c4-9e62-4824-b7f0-7425c3c28917.jpeg,b6c56eb0-1748-49a9-98dc-bcc4b9788a54.jpeg,92f17532-1527-4563-aa1d-ed01baa0f7b2.jpeg,3adbe4f7-e374-4533-aa79-cc4a98c529bf.jpeg', '<p><img alt=\"10000.jpg\" src=\"http://img.happymmall.com/00bce8d4-e9af-4c8d-b205-e6c75c7e252b.jpg\" width=\"790\" height=\"553\"><br></p><p><img alt=\"20000.jpg\" src=\"http://img.happymmall.com/4a70b4b4-01ee-46af-9468-31e67d0995b8.jpg\" width=\"790\" height=\"525\"><br></p><p><img alt=\"30000.jpg\" src=\"http://img.happymmall.com/0570e033-12d7-49b2-88f3-7a5d84157223.jpg\" width=\"790\" height=\"365\"><br></p><p><img alt=\"40000.jpg\" src=\"http://img.happymmall.com/50515c02-3255-44b9-a829-9e141a28c08a.jpg\" width=\"790\" height=\"525\"><br></p><p><img alt=\"50000.jpg\" src=\"http://img.happymmall.com/c138fc56-5843-4287-a029-91cf3732d034.jpg\" width=\"790\" height=\"525\"><br></p><p><img alt=\"60000.jpg\" src=\"http://img.happymmall.com/c92d1f8a-9827-453f-9d37-b10a3287e894.jpg\" width=\"790\" height=\"525\"><br></p><p><br></p><p><img alt=\"TB24p51hgFkpuFjSspnXXb4qFXa-1776456424.jpg\" src=\"http://img.happymmall.com/bb1511fc-3483-471f-80e5-c7c81fa5e1dd.jpg\" width=\"790\" height=\"375\"><br></p><p><br></p><p><img alt=\"shouhou.jpg\" src=\"http://img.happymmall.com/698e6fbe-97ea-478b-8170-008ad24030f7.jpg\" width=\"750\" height=\"150\"><br></p><p><img alt=\"999.jpg\" src=\"http://img.happymmall.com/ee276fe6-5d79-45aa-8393-ba1d210f9c89.jpg\" width=\"790\" height=\"351\"><br></p>', '6999.00', '9991', '1', null, '2017-04-13 21:45:41'), ('27', '100006', 'Midea/美的 BCD-535WKZM(E)冰箱双开门对开门风冷无霜智能电家用', '送品牌烤箱,五一大促', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg', 'ac3e571d-13ce-4fad-89e8-c92c2eccf536.jpeg,4bb02f1c-62d5-48cc-b358-97b05af5740d.jpeg,36bdb49c-72ae-4185-9297-78829b54b566.jpeg', '<p><img alt=\"miaoshu.jpg\" src=\"http://img.happymmall.com/9c5c74e6-6615-4aa0-b1fc-c17a1eff6027.jpg\" width=\"790\" height=\"444\"><br></p><p><img alt=\"miaoshu2.jpg\" src=\"http://img.happymmall.com/31dc1a94-f354-48b8-a170-1a1a6de8751b.jpg\" width=\"790\" height=\"1441\"><img alt=\"miaoshu3.jpg\" src=\"http://img.happymmall.com/7862594b-3063-4b52-b7d4-cea980c604e0.jpg\" width=\"790\" height=\"1442\"><img alt=\"miaoshu4.jpg\" src=\"http://img.happymmall.com/9a650563-dc85-44d6-b174-d6960cfb1d6a.jpg\" width=\"790\" height=\"1441\"><br></p>', '3299.00', '8876', '1', '2017-04-13 18:51:54', '2017-04-13 21:45:41'), ('28', '100012', '4+64G送手环/Huawei/华为 nova 手机P9/P10plus青春', 'NOVA青春版1999元', '0093f5d3-bdb4-4fb0-bec5-5465dfd26363.jpeg', '0093f5d3-bdb4-4fb0-bec5-5465dfd26363.jpeg,13da2172-4445-4eb5-a13f-c5d4ede8458c.jpeg,58d5d4b7-58d4-4948-81b6-2bae4f79bf02.jpeg', '<p><img alt=\"11TB2fKK3cl0kpuFjSsziXXa.oVXa_!!1777180618.jpg\" src=\"http://img.happymmall.com/5c2d1c6d-9e09-48ce-bbdb-e833b42ff664.jpg\" width=\"790\" height=\"966\"><img alt=\"22TB2YP3AkEhnpuFjSZFpXXcpuXXa_!!1777180618.jpg\" src=\"http://img.happymmall.com/9a10b877-818f-4a27-b6f7-62887f3fb39d.jpg\" width=\"790\" height=\"1344\"><img alt=\"33TB2Yyshk.hnpuFjSZFpXXcpuXXa_!!1777180618.jpg\" src=\"http://img.happymmall.com/7d7fbd69-a3cb-4efe-8765-423bf8276e3e.jpg\" width=\"790\" height=\"700\"><img alt=\"TB2diyziB8kpuFjSspeXXc7IpXa_!!1777180618.jpg\" src=\"http://img.happymmall.com/1d7160d2-9dba-422f-b2a0-e92847ba6ce9.jpg\" width=\"790\" height=\"393\"><br></p>', '1999.00', '9994', '1', '2017-04-13 18:57:18', '2017-04-13 21:45:41'), ('29', '100008', 'Haier/海尔HJ100-1HU1 10公斤滚筒洗衣机全自动带烘干家用大容量 洗烘一体', '门店机型 德邦送货', '173335a4-5dce-4afd-9f18-a10623724c4e.jpeg', '173335a4-5dce-4afd-9f18-a10623724c4e.jpeg,42b1b8bc-27c7-4ee1-80ab-753d216a1d49.jpeg,2f1b3de1-1eb1-4c18-8ca2-518934931bec.jpeg', '<p><img alt=\"1TB2WLZrcIaK.eBjSspjXXXL.XXa_!!2114960396.jpg\" src=\"http://img.happymmall.com/ffcce953-81bd-463c-acd1-d690b263d6df.jpg\" width=\"790\" height=\"920\"><img alt=\"2TB2zhOFbZCO.eBjSZFzXXaRiVXa_!!2114960396.jpg\" src=\"http://img.happymmall.com/58a7bd25-c3e7-4248-9dba-158ef2a90e70.jpg\" width=\"790\" height=\"1052\"><img alt=\"3TB27mCtb7WM.eBjSZFhXXbdWpXa_!!2114960396.jpg\" src=\"http://img.happymmall.com/2edbe9b3-28be-4a8b-a9c3-82e40703f22f.jpg\" width=\"790\" height=\"820\"><br></p>', '4299.00', '9993', '1', '2017-04-13 19:07:47', '2017-04-13 21:45:41');
171 COMMIT;
172 
173 -- ----------------------------
174 --  Table structure for `mmall_shipping`
175 -- ----------------------------
176 DROP TABLE IF EXISTS `mmall_shipping`;
177 CREATE TABLE `mmall_shipping` (
178   `id` int(11) NOT NULL AUTO_INCREMENT,
179   `user_id` int(11) DEFAULT NULL COMMENT '用户id',
180   `receiver_name` varchar(20) DEFAULT NULL COMMENT '收货姓名',
181   `receiver_phone` varchar(20) DEFAULT NULL COMMENT '收货固定电话',
182   `receiver_mobile` varchar(20) DEFAULT NULL COMMENT '收货移动电话',
183   `receiver_province` varchar(20) DEFAULT NULL COMMENT '省份',
184   `receiver_city` varchar(20) DEFAULT NULL COMMENT '城市',
185   `receiver_district` varchar(20) DEFAULT NULL COMMENT '区/县',
186   `receiver_address` varchar(200) DEFAULT NULL COMMENT '详细地址',
187   `receiver_zip` varchar(6) DEFAULT NULL COMMENT '邮编',
188   `create_time` datetime DEFAULT NULL,
189   `update_time` datetime DEFAULT NULL,
190   PRIMARY KEY (`id`)
191 ) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8;
192 
193 -- ----------------------------
194 --  Records of `mmall_shipping`
195 -- ----------------------------
196 BEGIN;
197 INSERT INTO `mmall_shipping` VALUES ('4', '13', 'geely', '010', '18688888888', '北京', '北京市', '海淀区', '中关村', '100000', '2017-01-22 14:26:25', '2017-01-22 14:26:25'), ('7', '17', 'Rosen', '13800138000', '13800138000', '北京', '北京', null, '中关村', '100000', '2017-03-29 12:11:01', '2017-03-29 12:11:01'), ('29', '1', '吉利', '13800138000', '13800138000', '北京', '北京', '海淀区', '海淀区中关村', '100000', '2017-04-09 18:33:32', '2017-04-09 18:33:32');
198 COMMIT;
199 
200 -- ----------------------------
201 --  Table structure for `mmall_user`
202 -- ----------------------------
203 DROP TABLE IF EXISTS `mmall_user`;
204 CREATE TABLE `mmall_user` (
205   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户表id',
206   `username` varchar(50) NOT NULL COMMENT '用户名',
207   `password` varchar(50) NOT NULL COMMENT '用户密码,MD5加密',
208   `email` varchar(50) DEFAULT NULL,
209   `phone` varchar(20) DEFAULT NULL,
210   `question` varchar(100) DEFAULT NULL COMMENT '找回密码问题',
211   `answer` varchar(100) DEFAULT NULL COMMENT '找回密码答案',
212   `role` int(4) NOT NULL COMMENT '角色0-管理员,1-普通用户',
213   `create_time` datetime NOT NULL COMMENT '创建时间',
214   `update_time` datetime NOT NULL COMMENT '最后一次更新时间',
215   PRIMARY KEY (`id`),
216   UNIQUE KEY `user_name_unique` (`username`) USING BTREE
217 ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;
218 
219 -- ----------------------------
220 --  Records of `mmall_user`
221 -- ----------------------------
222 BEGIN;
223 INSERT INTO `mmall_user` VALUES ('1', 'admin', '427338237BD929443EC5D48E24FD2B1A', '[email protected]', '13800138000', '问题', '答案', '1', '2016-11-06 16:56:45', '2017-04-04 19:27:36'), ('13', 'geely', '08E9A6EA287E70E7E3F7C982BF7923AC', '[email protected]', '13800138000', '问题', '答案', '0', '2016-11-19 22:19:25', '2016-11-19 22:19:25'), ('17', 'rosen', '095AC193FE2212EEC7A93E8FEFF11902', '[email protected]', '13800138000', '问题', '答案', '0', '2017-03-17 10:51:33', '2017-04-09 23:13:26'), ('21', 'soonerbetter', 'DE6D76FE7C40D5A1A8F04213F2BEFBEE', '[email protected]', '13800138000', '105204', '105204', '0', '2017-04-13 21:26:22', '2017-04-13 21:26:22');
224 COMMIT;
225 
226 SET FOREIGN_KEY_CHECKS = 1;
mmall.sql

 

(1)pom.xml中增加mybatis-generator的配置

 1 <build>
 2     <finalName>mmall</finalName>
 3     <plugins>
 4       <plugin>
 5         <groupId>org.mybatis.generator</groupId>
 6         <artifactId>mybatis-generator-maven-plugin</artifactId>
 7         <version>1.3.2</version>
 8         <configuration>
 9           <verbose>true</verbose>
10           <overwrite>true</overwrite>
11         </configuration>
12       </plugin>
13       ...
14 </build>

 

(2)generatorConfig.xml

新建文件 : src/main/resources/generatorConfig.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration
 3         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 
 6 <generatorConfiguration>
 7     <!--导入属性配置-->
 8     <properties resource="datasource.properties"></properties>
 9 
10     <!--指定特定数据库的jdbc驱动jar包的位置-->
11     <classPathEntry location="${db.driverLocation}"/>
12 
13     <context id="default" targetRuntime="MyBatis3">
14 
15         <!-- optional,旨在创建class时,对注释进行控制 -->
16         <commentGenerator>
17             <property name="suppressDate" value="true"/>
18             <property name="suppressAllComments" value="true"/>
19         </commentGenerator>
20 
21         <!--jdbc的数据库连接 -->
22         <jdbcConnection
23                 driverClass="${db.driverClassName}"
24                 connectionURL="${db.url}"
25                 userId="${db.username}"
26                 password="${db.password}">
27         </jdbcConnection>
28 
29 
30         <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
31         <javaTypeResolver>
32             <property name="forceBigDecimals" value="false"/>
33         </javaTypeResolver>
34 
35 
36         <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
37             targetPackage     指定生成的model生成所在的包名
38             targetProject     指定在该项目下所在的路径
39         -->
40         <!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".\src\main\java">-->
41         <javaModelGenerator targetPackage="com.mmall.pojo" targetProject="./src/main/java">
42             <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
43             <property name="enableSubPackages" value="false"/>
44             <!-- 是否对model添加 构造函数 -->
45             <property name="constructorBased" value="true"/>
46             <!-- 是否对类CHAR类型的列的数据进行trim操作 -->
47             <property name="trimStrings" value="true"/>
48             <!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 -->
49             <property name="immutable" value="false"/>
50         </javaModelGenerator>
51 
52         <!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
53         <!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->
54         <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
55             <property name="enableSubPackages" value="false"/>
56         </sqlMapGenerator>
57 
58         <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
59                 type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
60                 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
61                 type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
62         -->
63 
64         <!-- targetPackage:mapper接口dao生成的位置 -->
65         <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->
66         <javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject="./src/main/java">
67             <!-- enableSubPackages:是否让schema作为包的后缀 -->
68             <property name="enableSubPackages" value="false" />
69         </javaClientGenerator>
70 
71 
72         <table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
73         <table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
74         <table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
75         <table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
76         <table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
77         <table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
78         <table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
79         <table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
80             <!-- 数据库的表中这两个字段用的text,mybatis不同版本生成的不一样,所以改为VARCHAR -->
81             <columnOverride column="detail" jdbcType="VARCHAR" />
82             <columnOverride column="sub_images" jdbcType="VARCHAR" />
83         </table>
84         <table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
85 
86 
87         <!-- geelynote mybatis插件的搭建 -->
88     </context>
89 </generatorConfiguration>
gerneratorConfig.xml

重点说明的几个点:

 

 

(3)datasource.properties

 generatorConfig.xml中用到了datasource.properties,在同目录新增文件datasource.properties。

 

注意这里的driverLocation:

1 db.driverLocation=E:/lyh/file/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
2 db.driverClassName=com.mysql.jdbc.Driver
3 db.url=jdbc:mysql://localhost:3306/mmall_learning?characterEncoding=utf-8
4 db.username=root
5 db.password=****

 

在pom.xml中配置过mysql的驱动,所以只要去maven的本地仓库里找到地址就行:

 

 

 

 (4)执行mybatis-generator:generate

 

 运行之后:

 

1.8 create_time和update_time的处理

因为要将create_time和update_time的生成交给数据库,而不是代码来处理,所以在mapper/**.xml文件中要修改一些东西。

注意:now()是mysql的方法,其他比如postgresql不适用!

(1)insert

修改前:

修改后:

 

(2)insertSelective

 

(3)updateByPrimaryKey

 

(4)updateByPrimaryKeySelective

 

1.9 mybatis-plugin的配置与使用

 

1.10 mybatis-pagehelper的配置与使用

(1)pom.xml中加入依赖

 

(2)在spring中配置

这里的配置后面会有,略过。

 

1.11 web.xml

引入spring、springmvc的配置文件,配置filter和listener等。

 

 

<?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"
         id="WebApp_ID" version="2.5">

    <display-name>Archetype Created Web Application</display-name>

    <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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </context-param>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>



    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

</web-app>

1.12 spring配置

(1)applicationContext.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" xmlns:aop="http://www.springframework.org/schema/aop"
 4        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
 5        xmlns:context="http://www.springframework.org/schema/context"
 6        xsi:schemaLocation="
 7      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
 8      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 9      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
10      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
11 
12     <!-- 扫描注解的包 -->
13     <context:component-scan base-package="com.mmall" annotation-config="true"/>
14 
15     <!--<context:annotation-config/>-->
16     <!-- aop -->
17     <aop:aspectj-autoproxy/>
18 
19     <import resource="applicationContext-datasource.xml"/>
20 
21 
22 </beans>
applicationContext.xml

 

(2)applicationContext-datasource.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" xmlns:aop="http://www.springframework.org/schema/aop"
 4        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
 5        xmlns:context="http://www.springframework.org/schema/context"
 6        xsi:schemaLocation="
 7      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
 8      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 9      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
10      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
11 
12     <context:component-scan base-package="com.mmall" annotation-config="true"/>
13 
14     <!-- Spring的配置文件可以引用这里配置的datasource.properties中的key-->
15     <bean id="propertyConfigurer"
16           class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
17         <property name="order" value="2"/>
18         <property name="ignoreUnresolvablePlaceholders" value="true"/>
19         <property name="locations">
20             <list>
21                 <value>classpath:datasource.properties</value>
22             </list>
23         </property>
24         <property name="fileEncoding" value="utf-8"/>
25     </bean>
26 
27 
28     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
29         <property name="driverClassName" value="${db.driverClassName}"/>
30         <property name="url" value="${db.url}"/>
31         <property name="username" value="${db.username}"/>
32         <property name="password" value="${db.password}"/>
33         <!-- 连接池启动时的初始值 -->
34         <property name="initialSize" value="${db.initialSize}"/>
35         <!-- 连接池的最大值 -->
36         <property name="maxActive" value="${db.maxActive}"/>
37         <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
38         <property name="maxIdle" value="${db.maxIdle}"/>
39         <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
40         <property name="minIdle" value="${db.minIdle}"/>
41         <!-- 最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制 -->
42         <property name="maxWait" value="${db.maxWait}"/>
43         <!--#给出一条简单的sql语句进行验证 -->
44         <!--<property name="validationQuery" value="select getdate()" />-->
45         <property name="defaultAutoCommit" value="${db.defaultAutoCommit}"/>
46         <!-- 回收被遗弃的(一般是忘了释放的)数据库连接到连接池中 -->
47         <!--<property name="removeAbandoned" value="true" />-->
48         <!-- 数据库连接过多长时间不用将被视为被遗弃而收回连接池中 -->
49         <!--<property name="removeAbandonedTimeout" value="120" />-->
50         <!-- #连接的超时时间,默认为半小时。 -->
51         <property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}"/>
52 
53         <!--# 失效检查线程运行时间间隔,要小于MySQL默认-->
54         <property name="timeBetweenEvictionRunsMillis" value="40000"/>
55         <!--# 检查连接是否有效-->
56         <property name="testWhileIdle" value="true"/>
57         <!--# 检查连接有效性的SQL语句-->
58         <property name="validationQuery" value="SELECT 1 FROM dual"/>
59     </bean>
60 
61     <!-- mybatis -->
62     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
63         <property name="dataSource" ref="dataSource"/>
64         <property name="mapperLocations" value="classpath*:mappers/*Mapper.xml"></property>
65 
66         <!-- 分页插件 -->
67         <property name="plugins">
68             <array>
69                 <bean class="com.github.pagehelper.PageHelper">
70                     <property name="properties">
71                         <value>
72                             dialect=mysql
73                         </value>
74                     </property>
75                 </bean>
76             </array>
77         </property>
78 
79     </bean>
80 
81     <!-- mybatis扫描dao层 -->
82     <bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
83         <property name="basePackage" value="com.mmall.dao"/>
84     </bean>
85 
86     <!-- 使用@Transactional进行声明式事务管理需要声明下面这行 -->
87     <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
88     <!-- 事务管理 -->
89     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
90         <property name="dataSource" ref="dataSource"/>
91         <property name="rollbackOnCommitFailure" value="true"/>
92     </bean>
93 
94 
95 </beans>
applicationContext-datasource.xml

 

(3)dataSource.properties

前面配置了数据库的连接信息,现在还要配置一些其他参数。

 1 db.driverLocation=E:/lyh/file/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
 2 db.driverClassName=com.mysql.jdbc.Driver
 3 db.url=jdbc:mysql://localhost:3306/mmall_learning?characterEncoding=utf-8
 4 db.username=root
 5 db.password=root
 6 
 7 
 8 db.initialSize = 20
 9 db.maxActive = 50
10 db.maxIdle = 20
11 db.minIdle = 10
12 db.maxWait = 10
13 db.defaultAutoCommit = true
14 db.minEvictableIdleTimeMillis = 3600000
dataSource.properties

 

(4)mmall.properties

这里是spring引用了ftp服务器的配置文件,后面详解。

 

1.13 spring mvc配置文件

 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" xmlns:p="http://www.springframework.org/schema/p"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
 6        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 7     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
 8     http://www.springframework.org/schema/mvc
 9     http://www.springframework.org/schema/mvc/spring-mvc.xsd">
10 
11     <!-- 扫描controller注解-->
12     <context:component-scan base-package="com.mmall" annotation-config="true"/>
13 
14     <mvc:annotation-driven>
15         <mvc:message-converters>
16             <bean class="org.springframework.http.converter.StringHttpMessageConverter">
17                 <property name="supportedMediaTypes">
18                     <list>
19                         <value>text/plain;charset=UTF-8</value>
20                         <value>text/html;charset=UTF-8</value>
21                     </list>
22                 </property>
23             </bean>
24             <!-- 自动反序列化时用到 @JsonBody-->
25             <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
26                 <property name="supportedMediaTypes">
27                     <list>
28                         <value>application/json;charset=UTF-8</value>
29                     </list>
30                 </property>
31             </bean>
32         </mvc:message-converters>
33     </mvc:annotation-driven>
34 
35     <!-- 文件上传 -->
36     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
37         <property name="maxUploadSize" value="10485760"/> <!-- 这里单位是字节,==10兆, -->
38         <property name="maxInMemorySize" value="4096" />
39         <property name="defaultEncoding" value="UTF-8"></property>
40     </bean>
41 
42 
43 </beans>
dispatcher-servlet.xml

 

 1.14 logback.xml配置文件

路径:src/main/resource/logback.xml。

注意几个log文件存放的位置。

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <configuration scan="true" scanPeriod="60 seconds" debug="false">
 3     <!-- 会打印到catalina.out文件上-->
 4     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
 5         <encoding>UTF-8</encoding>
 6         <encoder>
 7             <pattern>[%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n</pattern>
 8         </encoder>
 9         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
10             <!-- 大于debug的级别都会显示 -->
11             <level>DEBUG</level>
12         </filter>
13     </appender>
14 
15     <!-- 项目日志 -->
16     <appender name="mmall" class="ch.qos.logback.core.rolling.RollingFileAppender">
17         <!--日志存放位置-->
18         <File>e:/mmall_learning/logs/mmall.log</File>
19         <!--<File>/developer/apache-tomcat-7.0.73/logs/mmall.log</File>-->
20         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
21             <fileNamePattern>e:/mmall_learning/logs/mmall.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
22             <append>true</append>
23             <maxHistory>10</maxHistory>
24         </rollingPolicy>
25         <encoder>
26             <pattern>[%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n</pattern>
27         </encoder>
28     </appender>
29 
30 
31     <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
32         <!--错误日志存放位置-->
33         <File>e:/mmall_learning/logs/error.log</File>
34         <!--<File>/developer/apache-tomcat-7.0.73/logs/error.log</File>-->
35         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
36             <fileNamePattern>/devsoft/apache-tomcat-7.0.73/logs/error.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
37             <!--<fileNamePattern>d:/mmalllog/error.log.%d{yyyy-MM-dd}.gz</fileNamePattern>-->
38             <append>true</append>
39             <maxHistory>10</maxHistory>
40         </rollingPolicy>
41         <encoder>
42             <pattern>[%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n</pattern>
43         </encoder>
44         <filter class="ch.qos.logback.classic.filter.LevelFilter">
45             <level>ERROR</level>
46             <onMatch>ACCEPT</onMatch>
47             <onMismatch>DENY</onMismatch>
48         </filter>
49     </appender>
50 
51     <logger name="com.mmall" additivity="false" level="INFO" >
52         <appender-ref ref="mmall" />
53         <appender-ref ref="console"/>
54     </logger>
55 
56     <!-- 配置成DEBUG,打印dao层的sql语句 -->
57     <logger name="com.mmall.dao" level="DEBUG"/>
58 
59     <!--<logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" >-->
60     <!--<appender-ref ref="console"/>-->
61     <!--</logger>-->
62 
63     <!--<logger name="java.sql.Connection" level="DEBUG">-->
64     <!--<appender-ref ref="console"/>-->
65     <!--</logger>-->
66     <!--<logger name="java.sql.Statement" level="DEBUG">-->
67     <!--<appender-ref ref="console"/>-->
68     <!--</logger>-->
69 
70     <!--<logger name="java.sql.PreparedStatement" level="DEBUG">-->
71     <!--<appender-ref ref="console"/>-->
72     <!--</logger>-->
73 
74 
75     <root level="DEBUG">
76         <appender-ref ref="console"/>
77         <appender-ref ref="error"/>
78     </root>
79 
80 </configuration>
logback.xml

 

1.15 ftp服务器配置文件mmall.properties

前提:ftp服务器已经处理好。

1 ftp.server.ip=localhost
2 ftp.user=mmallftp
3 ftp.pass=ftppassword
4 ftp.server.http.prefix=http://img.happymmall.com/
mmall.properties

 

1.16 IDEA的一些补充配置

(1)实时编译

 

 

(2)因为使用的是spring自动扫描,有时候会有点问题,其实项目是正常的,但是IDEA会报错。因此把级别从error改成warning。

 

1.17 git命令提交项目

目前项目总览:

 

执行git命令:

git status

git add .

git commit -am 'project init commit'

git push

 

中间执行git commit的时候报了错:

 

那就配置下信息:

 

然后再执行push就ok了。远程仓库:

 

1.18 两个有用的chrome插件:restlet client和fe助手


猜你喜欢

转载自blog.csdn.net/qq_34857629/article/details/80619379
今日推荐