这篇博客其实很早就应该写,早在半年前,因为对SpringMVC感兴趣,便自学了一下Spring。一段时间的学习后,对Spring有了一个基本的了解,于是想着自己动手搭建一个SpringMvc的框架出来。搭建的过程中遇到了很多的问题,其实在网上有许多的SpringMvc的框架搭建教程,但使用那些教程搭建起来的框架往往有或多或少的问题,如jar包下载不完全、log日志无法使用等,经历了一段时间的尝试后终于将框架搭建了起来。

在搭建起来后就想着自己写一篇博客记录一下,以便日后需要的时候方便查找。

在这里,我使用的工具有:maven3.3.3、Eclipse luna、mysql 5、tomcat 8.0,使用的Spring为4.2版本

由于在框架的搭建过程中会使用到一些数据,所以在搭建框架前,首先将数据库设计好。下面是我从网上获取的一个数据库文件,将其导入mysql数据库中即可:

ebuy.sql

  1. -- MySQL dump 10.13 Distrib 5.6.25, for Win64 (x86_64)
  2. --
  3. -- Host: localhost Database: ebuy
  4. -- ------------------------------------------------------
  5. -- Server version 5.6.25
  6.  
  7. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  8. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  9. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  10. /*!40101 SET NAMES utf8 */;
  11. /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
  12. /*!40103 SET TIME_ZONE='+00:00' */;
  13. /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
  14. /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
  15. /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
  16. /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
  17.  
  18. --
  19. -- Table structure for table `firstsort`
  20. --
  21.  
  22. DROP TABLE IF EXISTS `firstsort`;
  23. /*!40101 SET @saved_cs_client = @@character_set_client */;
  24. /*!40101 SET character_set_client = utf8 */;
  25. CREATE TABLE `firstsort` (
  26. `fid` int(11) NOT NULL AUTO_INCREMENT,
  27. `fname` varchar(20) NOT NULL,
  28. PRIMARY KEY (`fid`)
  29. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  30. /*!40101 SET character_set_client = @saved_cs_client */;
  31.  
  32. --
  33. -- Dumping data for table `firstsort`
  34. --
  35.  
  36. LOCK TABLES `firstsort` WRITE;
  37. /*!40000 ALTER TABLE `firstsort` DISABLE KEYS */;
  38. /*!40000 ALTER TABLE `firstsort` ENABLE KEYS */;
  39. UNLOCK TABLES;
  40.  
  41. --
  42. -- Table structure for table `goods`
  43. --
  44.  
  45. DROP TABLE IF EXISTS `goods`;
  46. /*!40101 SET @saved_cs_client = @@character_set_client */;
  47. /*!40101 SET character_set_client = utf8 */;
  48. CREATE TABLE `goods` (
  49. `gid` int(11) NOT NULL AUTO_INCREMENT,
  50. `name` varchar(20) NOT NULL,
  51. `description` varchar(50) NOT NULL,
  52. `image` varchar(100) NOT NULL,
  53. `alive` varchar(2) DEFAULT NULL,
  54. `recommend` varchar(1) DEFAULT NULL,
  55. `addtime` date DEFAULT NULL,
  56. `sid` int(11) NOT NULL,
  57. PRIMARY KEY (`gid`)
  58. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  59. /*!40101 SET character_set_client = @saved_cs_client */;
  60.  
  61. --
  62. -- Dumping data for table `goods`
  63. --
  64.  
  65. LOCK TABLES `goods` WRITE;
  66. /*!40000 ALTER TABLE `goods` DISABLE KEYS */;
  67. /*!40000 ALTER TABLE `goods` ENABLE KEYS */;
  68. UNLOCK TABLES;
  69.  
  70. --
  71. -- Table structure for table `leaveword`
  72. --
  73.  
  74. DROP TABLE IF EXISTS `leaveword`;
  75. /*!40101 SET @saved_cs_client = @@character_set_client */;
  76. /*!40101 SET character_set_client = utf8 */;
  77. CREATE TABLE `leaveword` (
  78. `lid` int(11) NOT NULL AUTO_INCREMENT,
  79. `message` varchar(100) NOT NULL,
  80. `name` varchar(20) NOT NULL,
  81. `riqi` date NOT NULL,
  82. `gid` int(11) NOT NULL,
  83. PRIMARY KEY (`lid`)
  84. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  85. /*!40101 SET character_set_client = @saved_cs_client */;
  86.  
  87. --
  88. -- Dumping data for table `leaveword`
  89. --
  90.  
  91. LOCK TABLES `leaveword` WRITE;
  92. /*!40000 ALTER TABLE `leaveword` DISABLE KEYS */;
  93. /*!40000 ALTER TABLE `leaveword` ENABLE KEYS */;
  94. UNLOCK TABLES;
  95.  
  96. --
  97. -- Table structure for table `manager`
  98. --
  99.  
  100. DROP TABLE IF EXISTS `manager`;
  101. /*!40101 SET @saved_cs_client = @@character_set_client */;
  102. /*!40101 SET character_set_client = utf8 */;
  103. CREATE TABLE `manager` (
  104. `mid` int(11) NOT NULL AUTO_INCREMENT,
  105. `name` varchar(20) NOT NULL,
  106. `password` varchar(20) NOT NULL,
  107. PRIMARY KEY (`mid`)
  108. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
  109. /*!40101 SET character_set_client = @saved_cs_client */;
  110.  
  111. --
  112. -- Dumping data for table `manager`
  113. --
  114.  
  115. LOCK TABLES `manager` WRITE;
  116. /*!40000 ALTER TABLE `manager` DISABLE KEYS */;
  117. INSERT INTO `manager` VALUES (1,'superadmin','');
  118. /*!40000 ALTER TABLE `manager` ENABLE KEYS */;
  119. UNLOCK TABLES;
  120.  
  121. --
  122. -- Table structure for table `middle`
  123. --
  124.  
  125. DROP TABLE IF EXISTS `middle`;
  126. /*!40101 SET @saved_cs_client = @@character_set_client */;
  127. /*!40101 SET character_set_client = utf8 */;
  128. CREATE TABLE `middle` (
  129. `mid` int(11) NOT NULL,
  130. `pid` int(11) NOT NULL,
  131. PRIMARY KEY (`mid`,`pid`)
  132. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  133. /*!40101 SET character_set_client = @saved_cs_client */;
  134.  
  135. --
  136. -- Dumping data for table `middle`
  137. --
  138.  
  139. LOCK TABLES `middle` WRITE;
  140. /*!40000 ALTER TABLE `middle` DISABLE KEYS */;
  141. INSERT INTO `middle` VALUES (1,1),(1,2),(1,3),(1,4),(1,5);
  142. /*!40000 ALTER TABLE `middle` ENABLE KEYS */;
  143. UNLOCK TABLES;
  144.  
  145. --
  146. -- Table structure for table `news`
  147. --
  148.  
  149. DROP TABLE IF EXISTS `news`;
  150. /*!40101 SET @saved_cs_client = @@character_set_client */;
  151. /*!40101 SET character_set_client = utf8 */;
  152. CREATE TABLE `news` (
  153. `nid` int(11) NOT NULL AUTO_INCREMENT,
  154. `title` varchar(50) NOT NULL,
  155. `content` varchar(1000) NOT NULL,
  156. `riqi` date NOT NULL,
  157. PRIMARY KEY (`nid`)
  158. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=gbk;
  159. /*!40101 SET character_set_client = @saved_cs_client */;
  160.  
  161. --
  162. -- Dumping data for table `news`
  163. --
  164.  
  165. LOCK TABLES `news` WRITE;
  166. /*!40000 ALTER TABLE `news` DISABLE KEYS */;
  167. INSERT INTO `news` VALUES (1,'索爱W8 真正的Walkman Android音乐手机','一直传闻索爱发布Walkman加上Android的手机,这次终于成真了--索爱W8正式发布。索爱W8不但是Walkman品牌的音乐手机,也是Android 2.1版系统智能手机,提供有蓝色、红色、橙色三种颜色。','2011-04-23'),(2,'尼康D5100 新一代可翻转LCD的中端数码单反','虽然日本地震影响了不少3C厂商的新品发布计划,但尼康最近依然推出最新一代中端数码单反D5100。这款尼康D5100十分给力,带有3英寸的可翻转的大屏幕LCD,若含AF-S DX Zoom-NIKKOR 18-55mm f/3.5-5.6G ED VR镜头,套机售价约899美元。','2011-04-13'),(3,'iPad降价!价格暴跌到2888元','随着iPad 2的上市,旧款iPad开始降价促销,清理库存。虽然,iPad 2在国内上市时间没有公布,或许遇到某些问题,也因此未来较长时间还是只会继续销售iPad了。但庆幸的是,iPad降价没有漏到,iPad一代WIFI 16GB版本价格暴跌到2888元人民币,即便是3G版本的iPad价格也不过是3888元人民币,简直就是横扫千军,相信就算是旧款iPad,也会买断市了。','2011-03-03'),(4,'NEC N-04C 7.7mm的全球最薄手机','NEC最近在日本发布了一款拥有全球最薄称号的手机,型号就是NEC N-04C,这款全球最薄手机拥有7.7mm的机身,而且是预装Andorid操作系统,相信凭着如此性感的身材,必然能俘获不少的时尚粉丝。','2011-02-20'),(5,'摩托罗拉XOOM 首款平板电脑登场','摩托罗拉最近正式推出了首款平板电脑“MOTO XOOM”,一发布就获得了媒体极大的聚焦。作为摩托罗拉的第一款平板电脑,摩托罗拉XOOM预装了最新的Android 3.0操作系统,3G/4G版本售价为799美元,而WiFi版本,不支持3G网络的Xoom售价为600美元。','2011-03-03'),(6,'创新ZEN Touch 2 内置Android系统的播放器','Android系统越来越受追捧,创新就将Android系统引入到旗下的播放器中,推出了新款创新ZEN Touch 2,就是采用了Android 2.1系统,有8GB和16GB容量,售价约1600元','2010-12-10');
  168. /*!40000 ALTER TABLE `news` ENABLE KEYS */;
  169. UNLOCK TABLES;
  170.  
  171. --
  172. -- Table structure for table `orders`
  173. --
  174.  
  175. DROP TABLE IF EXISTS `orders`;
  176. /*!40101 SET @saved_cs_client = @@character_set_client */;
  177. /*!40101 SET character_set_client = utf8 */;
  178. CREATE TABLE `orders` (
  179. `oid` int(11) NOT NULL,
  180. `ostate` varchar(1) NOT NULL,
  181. `name` varchar(20) NOT NULL,
  182. `address` varchar(50) NOT NULL,
  183. `tel` varchar(20) NOT NULL,
  184. `paytype` varchar(8) NOT NULL,
  185. `riqi` date NOT NULL,
  186. `money` double(10,3) NOT NULL,
  187. `userid` int(11) NOT NULL,
  188. PRIMARY KEY (`oid`)
  189. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  190. /*!40101 SET character_set_client = @saved_cs_client */;
  191.  
  192. --
  193. -- Dumping data for table `orders`
  194. --
  195.  
  196. LOCK TABLES `orders` WRITE;
  197. /*!40000 ALTER TABLE `orders` DISABLE KEYS */;
  198. /*!40000 ALTER TABLE `orders` ENABLE KEYS */;
  199. UNLOCK TABLES;
  200.  
  201. --
  202. -- Table structure for table `placard`
  203. --
  204.  
  205. DROP TABLE IF EXISTS `placard`;
  206. /*!40101 SET @saved_cs_client = @@character_set_client */;
  207. /*!40101 SET character_set_client = utf8 */;
  208. CREATE TABLE `placard` (
  209. `placardid` int(11) NOT NULL AUTO_INCREMENT,
  210. `messages` varchar(300) NOT NULL,
  211. `riqi` date NOT NULL,
  212. PRIMARY KEY (`placardid`)
  213. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  214. /*!40101 SET character_set_client = @saved_cs_client */;
  215.  
  216. --
  217. -- Dumping data for table `placard`
  218. --
  219.  
  220. LOCK TABLES `placard` WRITE;
  221. /*!40000 ALTER TABLE `placard` DISABLE KEYS */;
  222. /*!40000 ALTER TABLE `placard` ENABLE KEYS */;
  223. UNLOCK TABLES;
  224.  
  225. --
  226. -- Table structure for table `purview`
  227. --
  228.  
  229. DROP TABLE IF EXISTS `purview`;
  230. /*!40101 SET @saved_cs_client = @@character_set_client */;
  231. /*!40101 SET character_set_client = utf8 */;
  232. CREATE TABLE `purview` (
  233. `pid` int(11) NOT NULL AUTO_INCREMENT,
  234. `purview` char(1) NOT NULL,
  235. PRIMARY KEY (`pid`)
  236. ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=gbk;
  237. /*!40101 SET character_set_client = @saved_cs_client */;
  238.  
  239. --
  240. -- Dumping data for table `purview`
  241. --
  242.  
  243. LOCK TABLES `purview` WRITE;
  244. /*!40000 ALTER TABLE `purview` DISABLE KEYS */;
  245. INSERT INTO `purview` VALUES (1,''),(2,''),(3,''),(4,''),(5,'');
  246. /*!40000 ALTER TABLE `purview` ENABLE KEYS */;
  247. UNLOCK TABLES;
  248.  
  249. --
  250. -- Table structure for table `sale`
  251. --
  252.  
  253. DROP TABLE IF EXISTS `sale`;
  254. /*!40101 SET @saved_cs_client = @@character_set_client */;
  255. /*!40101 SET character_set_client = utf8 */;
  256. CREATE TABLE `sale` (
  257. `saleid` int(11) NOT NULL AUTO_INCREMENT,
  258. `gid` int(11) NOT NULL,
  259. `scount` int(11) NOT NULL,
  260. `oid` int(11) NOT NULL,
  261. `saleprice` double(10,3) NOT NULL,
  262. `state` char(1) NOT NULL,
  263. `riqi` date NOT NULL,
  264. PRIMARY KEY (`saleid`)
  265. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  266. /*!40101 SET character_set_client = @saved_cs_client */;
  267.  
  268. --
  269. -- Dumping data for table `sale`
  270. --
  271.  
  272. LOCK TABLES `sale` WRITE;
  273. /*!40000 ALTER TABLE `sale` DISABLE KEYS */;
  274. /*!40000 ALTER TABLE `sale` ENABLE KEYS */;
  275. UNLOCK TABLES;
  276.  
  277. --
  278. -- Table structure for table `secondsort`
  279. --
  280.  
  281. DROP TABLE IF EXISTS `secondsort`;
  282. /*!40101 SET @saved_cs_client = @@character_set_client */;
  283. /*!40101 SET character_set_client = utf8 */;
  284. CREATE TABLE `secondsort` (
  285. `sid` int(11) NOT NULL AUTO_INCREMENT,
  286. `sname` varchar(20) NOT NULL,
  287. `fid` int(11) NOT NULL,
  288. PRIMARY KEY (`sid`)
  289. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  290. /*!40101 SET character_set_client = @saved_cs_client */;
  291.  
  292. --
  293. -- Dumping data for table `secondsort`
  294. --
  295.  
  296. LOCK TABLES `secondsort` WRITE;
  297. /*!40000 ALTER TABLE `secondsort` DISABLE KEYS */;
  298. /*!40000 ALTER TABLE `secondsort` ENABLE KEYS */;
  299. UNLOCK TABLES;
  300.  
  301. --
  302. -- Table structure for table `storage`
  303. --
  304.  
  305. DROP TABLE IF EXISTS `storage`;
  306. /*!40101 SET @saved_cs_client = @@character_set_client */;
  307. /*!40101 SET character_set_client = utf8 */;
  308. CREATE TABLE `storage` (
  309. `storageid` int(11) NOT NULL AUTO_INCREMENT,
  310. `gid` int(11) NOT NULL,
  311. `inprice` double(10,3) NOT NULL,
  312. `outprice` double(10,3) NOT NULL,
  313. `marketprice` double(10,3) NOT NULL,
  314. `count` int(11) NOT NULL,
  315. PRIMARY KEY (`storageid`)
  316. ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
  317. /*!40101 SET character_set_client = @saved_cs_client */;
  318.  
  319. --
  320. -- Dumping data for table `storage`
  321. --
  322.  
  323. LOCK TABLES `storage` WRITE;
  324. /*!40000 ALTER TABLE `storage` DISABLE KEYS */;
  325. /*!40000 ALTER TABLE `storage` ENABLE KEYS */;
  326. UNLOCK TABLES;
  327.  
  328. --
  329. -- Table structure for table `transfer`
  330. --
  331.  
  332. DROP TABLE IF EXISTS `transfer`;
  333. /*!40101 SET @saved_cs_client = @@character_set_client */;
  334. /*!40101 SET character_set_client = utf8 */;
  335. CREATE TABLE `transfer` (
  336. `tid` int(11) NOT NULL AUTO_INCREMENT,
  337. `account` char(19) NOT NULL,
  338. `password` char(6) NOT NULL,
  339. `balance` double(10,3) NOT NULL,
  340. PRIMARY KEY (`tid`)
  341. ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=gbk;
  342. /*!40101 SET character_set_client = @saved_cs_client */;
  343.  
  344. --
  345. -- Dumping data for table `transfer`
  346. --
  347.  
  348. LOCK TABLES `transfer` WRITE;
  349. /*!40000 ALTER TABLE `transfer` DISABLE KEYS */;
  350. INSERT INTO `transfer` VALUES (1,'','',10000.000),(2,'','',10000.000),(3,'','',10000.000);
  351. /*!40000 ALTER TABLE `transfer` ENABLE KEYS */;
  352. UNLOCK TABLES;
  353.  
  354. --
  355. -- Table structure for table `userinfo`
  356. --
  357.  
  358. DROP TABLE IF EXISTS `userinfo`;
  359. /*!40101 SET @saved_cs_client = @@character_set_client */;
  360. /*!40101 SET character_set_client = utf8 */;
  361. CREATE TABLE `userinfo` (
  362. `userid` int(11) NOT NULL AUTO_INCREMENT,
  363. `name` varchar(20) NOT NULL,
  364. `password` varchar(20) NOT NULL,
  365. `question` varchar(30) NOT NULL,
  366. `answer` varchar(30) NOT NULL,
  367. `realname` varchar(20) DEFAULT NULL,
  368. `sex` varchar(2) DEFAULT NULL,
  369. `email` varchar(20) NOT NULL,
  370. `id` char(18) NOT NULL,
  371. `postalcode` varchar(6) DEFAULT NULL,
  372. `address` varchar(30) DEFAULT NULL,
  373. `tel` varchar(11) DEFAULT NULL,
  374. `score` double(10,3) DEFAULT NULL,
  375. PRIMARY KEY (`userid`)
  376. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
  377. /*!40101 SET character_set_client = @saved_cs_client */;
  378.  
  379. --
  380. -- Dumping data for table `userinfo`
  381. --
  382.  
  383. LOCK TABLES `userinfo` WRITE;
  384. /*!40000 ALTER TABLE `userinfo` DISABLE KEYS */;
  385. INSERT INTO `userinfo` VALUES (1,'ppp','','qqqqq','ddddd','rrrr','男','123@QQ.com','dd','dfdf','eeee','',123.100);
  386. /*!40000 ALTER TABLE `userinfo` ENABLE KEYS */;
  387. UNLOCK TABLES;
  388. /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
  389.  
  390. /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
  391. /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
  392. /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
  393. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  394. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  395. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  396. /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
  397.  
  398. -- Dump completed on 2016-01-27 22:18:32

在该项目中,我是用的持久化工具是mybatis,而mybatis有一个工具(mybatis-generator-core-1.3.2),可以自动将数据库中的表映射成相对应的dao、model、model-db xml文件。

在使用该工具时,需要配置一份xml文件(generator.xml)以及一个数据库的驱动jar包

generator.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. <classPathEntry location="E:\JavaSmallTools\myBi\mysql-connector-java-5.1.26-bin.jar" />
  9.  
  10. <context id="DB2Tables" targetRuntime="MyBatis3">
  11.  
  12. <commentGenerator>
  13. <property name="suppressDate" value="true" />
  14. </commentGenerator>
  15.  
  16. <!-- 数据库链接URL、用户名、密码 -->
  17. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  18. connectionURL="jdbc:mysql://localhost/ebuy" userId="root" password="123456">
  19. </jdbcConnection>
  20.  
  21. <javaTypeResolver>
  22. <property name="forceBigDecimals" value="false" />
  23. </javaTypeResolver>
  24.  
  25. <!-- 生成模型的包名和位置 -->
  26. <javaModelGenerator targetPackage="com.welv.model"
  27. targetProject="E:\JavaSmallTools\myBi\com">
  28. <property name="enableSubPackages" value="true" />
  29. <property name="trimStrings" value="true" />
  30. </javaModelGenerator>
  31.  
  32. <!-- 生成的映射文件包名和位置 -->
  33. <sqlMapGenerator targetPackage="com.welv.mapping"
  34. targetProject="E:\JavaSmallTools\myBi\com">
  35. <property name="enableSubPackages" value="true" />
  36. </sqlMapGenerator>
  37.  
  38. <!-- 生成DAO的包名和位置 -->
  39. <javaClientGenerator type="XMLMAPPER"
  40. targetPackage="com.welv.dao" targetProject="E:\JavaSmallTools\myBi\com">
  41. <property name="enableSubPackages" value="true" />
  42. </javaClientGenerator>
  43.  
  44. <!-- 数据库中需要生成java代码的表的映射关系 -->
  45. <table tableName="firstsort" domainObjectName="Firstsort" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  46. <table tableName="goods" domainObjectName="Goods" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  47. <table tableName="leaveword" domainObjectName="Leaveword" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  48. <table tableName="manager" domainObjectName="Manager" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  49. <table tableName="middle" domainObjectName="Middle" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  50. <table tableName="news" domainObjectName="News" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  51. <table tableName="orders" domainObjectName="Orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  52. <table tableName="placard" domainObjectName="Placard" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  53. <table tableName="purview" domainObjectName="Purview" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  54. <table tableName="sale" domainObjectName="Sale" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  55. <table tableName="secondsort" domainObjectName="Secondsort" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  56. <table tableName="transfer" domainObjectName="Transfer" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  57. <table tableName="userinfo" domainObjectName="Userinfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  58. <table tableName="storage" domainObjectName="Storage" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
  59.  
  60. </context>
  61. </generatorConfiguration>

在该文件中,主要分为5部分,每部分的内容基本上在文件中都有说明,值得注意的是第五部分,也就是各个表的映射关系部分中,将大部分的值都赋false,其原因是,如果为true则会产生大量的无用文件,以及有用文件中产生大量的无用代码,全部使用false有利于generate clean code,便于后期的维护。

在修改完generator.xml文件后,将文件和工具(mybatis-generator-core-1.3.2)放在同一目录下。使用cmd命令,cd到该文件夹下,输入命令:

  1. java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

命令执行完后,打开预先设置好的文件夹,可看到一下目录:

从该目录中可看出,dao、mapping、model都已经生成,并且通过该工具生成的代码,其依赖关系也已经关联好,不需要在修改。

值得注意的是,通过该方式生成的dao文件均为interface,即接口类型。而具体的sql实现均在mapping的xml文件中实现,并且在生成的dao中只包含基本的增删改查,所以很多的方法需要自己添加,而添加新的方法需要在dao和mapping中同时进行修改。

至此,基本的持久化层代码已经生成,留在以便待用,接下去便可以开始搭建框架了。

Spring4 mvc+maven 框架搭建(1)的更多相关文章

  1. Spring4 mvc+maven 框架搭建(3)

    经过前面两个环节,spring mvc的原料已经准备好了,现在就可以正式开始搭建springmvc框架了. 首先先介绍介绍搭建的框架具有的功能: 1)集成log4j,配置好日志相关并可以打印出相关的日 ...

  2. Spring4 mvc+maven 框架搭建(2)

    在上一篇博客中,数据库数据和mybatis相关的java代码已经生成,接下来就可以使用IDE工具来搭建框架了. 在这里,我使用maven构建和管理代码,使用jdk1.8环境. 首先打开Eclipse, ...

  3. (一)springmvc+spring+mybatis+maven框架搭建

    (一)springmvc+spring+mybatis+maven框架搭建 1.说明 工作之余,为了学习点东西.先搭建个框架. 以后要往里面加东西,比如rabbitMQ.redis.shiro等. 也 ...

  4. Spring MVC + jpa框架搭建,及全面分析

    一,hibernate与jpa的关系 首先明确一点jpa是什么?以前我就搞不清楚jpa和hibernate的关系. 1,JPA(Java Persistence API)是Sun官方提出的Java持久 ...

  5. SSM+Redis+Shiro+Maven框架搭建及集成应用

    引文: 本文主要讲述项目框架搭建时的一些简单的使用配置,教你如何快速进行项目框架搭建. 技术: Spring+SpringMVC+Mybatis+Redis+Shiro+Maven          ...

  6. 从零开始--Spring项目整合(1)使用maven框架搭建项目

    这些年一直在用spring的框架搭建项目,现在开始我们从零开始利用Spring框架来搭建项目,目前我能想到有Spring.SpringMVC.SpringJDBC.Mybatis.WebSockt.R ...

  7. spring4+hibernate4+maven环境搭建

    本文主要介绍利用maven搭建spring4+hibernate4开发环境. 首先我们创建一个maven项目,具体步骤就不详细介绍了,看看我们pom.xml文件 <project xmlns=& ...

  8. Spring MVC Maven 环境搭建与部署

    本文简单演示了本地开发环境的搭建.项目出包.部署运行.HelloWorld,以及部分注意事项. 起初的玩法:先安装Eclipse,然后分别下载并安装Maven.spring的插件,再进行工程模式转换, ...

  9. Spring+Spring MVC+Hibernate框架搭建实例

    前言:这里只是说明整个搭建流程,并不进行原理性的讲解 一 下面所需要用到的数据库配置: 数据库方面,使用mysql创建一个users表,具体代码如下: 1 2 3 4 5 6 7 8 9 10 11 ...

随机推荐

  1. myeclipse cannot connect to vm

    启动tomcat时,tomcat可以直接运行,而debug时弹出 解决方法:打开360安全卫士的功能大全找到修复网络(LSP)点击立即修复就可以使用debug

  2. 第32章:MongoDB-索引--Capped固定集合

    ①Capped集合(固定集合) Capped集合的大小固定,性能好,如果空间用完了,新的对象会覆盖旧的对象. find时默认就是插入的顺序,Capped集合会自动维护. ②语法 db.createCo ...

  3. HDU 1517 A Multiplication Game (SG函数找规律)

    题意:两个玩家玩一个游戏,从 p = 1,开始,然后依次轮流选择一个2 - 9的数乘以 p,问你谁先凑够 p >= n. 析:找规律,我先打了一下SG函数的表,然后就找到规律了 我找到的是: 1 ...

  4. Logging from multiple processes using log4net

    When logging with log4net to a file (using the FileAppender), the FileAppender is holding an exclusi ...

  5. java中的中文字符转码技术

    package com.yin.test; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; impor ...

  6. Hdu4185 Oil Skimming

    Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...

  7. idea2018.2.4的安装激活与热部署插件JRebel的激活方法

    去Idea的官网下载如上版本的Idea安装文件 并且在网上搜索下载如下破解工具 放置在相应的Idea安装目录下 然后在Idea中输入激活码 { "licenseId": " ...

  8. shell 命令 查看本机ip

    ifconfig 结果有很多,查看env0的inet,就是本机的ip地址

  9. scikit-FEM-例1-求解Possion边值问题

    """ Author: kinnala Solve the problem -∇²u = 1 with zero boundary conditions on a uni ...

  10. [javascript-code-snippet]javascript代码段

    <ul> <li>Picture 1</li> <li>Picture 2</li> <li>Picture 3</li& ...