Spring4 mvc+maven 框架搭建(1)
这篇博客其实很早就应该写,早在半年前,因为对SpringMVC感兴趣,便自学了一下Spring。一段时间的学习后,对Spring有了一个基本的了解,于是想着自己动手搭建一个SpringMvc的框架出来。搭建的过程中遇到了很多的问题,其实在网上有许多的SpringMvc的框架搭建教程,但使用那些教程搭建起来的框架往往有或多或少的问题,如jar包下载不完全、log日志无法使用等,经历了一段时间的尝试后终于将框架搭建了起来。
在搭建起来后就想着自己写一篇博客记录一下,以便日后需要的时候方便查找。
在这里,我使用的工具有:maven3.3.3、Eclipse luna、mysql 5、tomcat 8.0,使用的Spring为4.2版本
由于在框架的搭建过程中会使用到一些数据,所以在搭建框架前,首先将数据库设计好。下面是我从网上获取的一个数据库文件,将其导入mysql数据库中即可:
- -- MySQL dump 10.13 Distrib 5.6.25, for Win64 (x86_64)
- --
- -- Host: localhost Database: ebuy
- -- ------------------------------------------------------
- -- Server version 5.6.25
- /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
- /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
- /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
- /*!40101 SET NAMES utf8 */;
- /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
- /*!40103 SET TIME_ZONE='+00:00' */;
- /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
- /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
- /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
- /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
- --
- -- Table structure for table `firstsort`
- --
- DROP TABLE IF EXISTS `firstsort`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `firstsort` (
- `fid` int(11) NOT NULL AUTO_INCREMENT,
- `fname` varchar(20) NOT NULL,
- PRIMARY KEY (`fid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `firstsort`
- --
- LOCK TABLES `firstsort` WRITE;
- /*!40000 ALTER TABLE `firstsort` DISABLE KEYS */;
- /*!40000 ALTER TABLE `firstsort` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `goods`
- --
- DROP TABLE IF EXISTS `goods`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `goods` (
- `gid` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(20) NOT NULL,
- `description` varchar(50) NOT NULL,
- `image` varchar(100) NOT NULL,
- `alive` varchar(2) DEFAULT NULL,
- `recommend` varchar(1) DEFAULT NULL,
- `addtime` date DEFAULT NULL,
- `sid` int(11) NOT NULL,
- PRIMARY KEY (`gid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `goods`
- --
- LOCK TABLES `goods` WRITE;
- /*!40000 ALTER TABLE `goods` DISABLE KEYS */;
- /*!40000 ALTER TABLE `goods` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `leaveword`
- --
- DROP TABLE IF EXISTS `leaveword`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `leaveword` (
- `lid` int(11) NOT NULL AUTO_INCREMENT,
- `message` varchar(100) NOT NULL,
- `name` varchar(20) NOT NULL,
- `riqi` date NOT NULL,
- `gid` int(11) NOT NULL,
- PRIMARY KEY (`lid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `leaveword`
- --
- LOCK TABLES `leaveword` WRITE;
- /*!40000 ALTER TABLE `leaveword` DISABLE KEYS */;
- /*!40000 ALTER TABLE `leaveword` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `manager`
- --
- DROP TABLE IF EXISTS `manager`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `manager` (
- `mid` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(20) NOT NULL,
- `password` varchar(20) NOT NULL,
- PRIMARY KEY (`mid`)
- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `manager`
- --
- LOCK TABLES `manager` WRITE;
- /*!40000 ALTER TABLE `manager` DISABLE KEYS */;
- INSERT INTO `manager` VALUES (1,'superadmin','');
- /*!40000 ALTER TABLE `manager` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `middle`
- --
- DROP TABLE IF EXISTS `middle`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `middle` (
- `mid` int(11) NOT NULL,
- `pid` int(11) NOT NULL,
- PRIMARY KEY (`mid`,`pid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `middle`
- --
- LOCK TABLES `middle` WRITE;
- /*!40000 ALTER TABLE `middle` DISABLE KEYS */;
- INSERT INTO `middle` VALUES (1,1),(1,2),(1,3),(1,4),(1,5);
- /*!40000 ALTER TABLE `middle` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `news`
- --
- DROP TABLE IF EXISTS `news`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `news` (
- `nid` int(11) NOT NULL AUTO_INCREMENT,
- `title` varchar(50) NOT NULL,
- `content` varchar(1000) NOT NULL,
- `riqi` date NOT NULL,
- PRIMARY KEY (`nid`)
- ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `news`
- --
- LOCK TABLES `news` WRITE;
- /*!40000 ALTER TABLE `news` DISABLE KEYS */;
- 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');
- /*!40000 ALTER TABLE `news` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `orders`
- --
- DROP TABLE IF EXISTS `orders`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `orders` (
- `oid` int(11) NOT NULL,
- `ostate` varchar(1) NOT NULL,
- `name` varchar(20) NOT NULL,
- `address` varchar(50) NOT NULL,
- `tel` varchar(20) NOT NULL,
- `paytype` varchar(8) NOT NULL,
- `riqi` date NOT NULL,
- `money` double(10,3) NOT NULL,
- `userid` int(11) NOT NULL,
- PRIMARY KEY (`oid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `orders`
- --
- LOCK TABLES `orders` WRITE;
- /*!40000 ALTER TABLE `orders` DISABLE KEYS */;
- /*!40000 ALTER TABLE `orders` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `placard`
- --
- DROP TABLE IF EXISTS `placard`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `placard` (
- `placardid` int(11) NOT NULL AUTO_INCREMENT,
- `messages` varchar(300) NOT NULL,
- `riqi` date NOT NULL,
- PRIMARY KEY (`placardid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `placard`
- --
- LOCK TABLES `placard` WRITE;
- /*!40000 ALTER TABLE `placard` DISABLE KEYS */;
- /*!40000 ALTER TABLE `placard` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `purview`
- --
- DROP TABLE IF EXISTS `purview`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `purview` (
- `pid` int(11) NOT NULL AUTO_INCREMENT,
- `purview` char(1) NOT NULL,
- PRIMARY KEY (`pid`)
- ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `purview`
- --
- LOCK TABLES `purview` WRITE;
- /*!40000 ALTER TABLE `purview` DISABLE KEYS */;
- INSERT INTO `purview` VALUES (1,''),(2,''),(3,''),(4,''),(5,'');
- /*!40000 ALTER TABLE `purview` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `sale`
- --
- DROP TABLE IF EXISTS `sale`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `sale` (
- `saleid` int(11) NOT NULL AUTO_INCREMENT,
- `gid` int(11) NOT NULL,
- `scount` int(11) NOT NULL,
- `oid` int(11) NOT NULL,
- `saleprice` double(10,3) NOT NULL,
- `state` char(1) NOT NULL,
- `riqi` date NOT NULL,
- PRIMARY KEY (`saleid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `sale`
- --
- LOCK TABLES `sale` WRITE;
- /*!40000 ALTER TABLE `sale` DISABLE KEYS */;
- /*!40000 ALTER TABLE `sale` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `secondsort`
- --
- DROP TABLE IF EXISTS `secondsort`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `secondsort` (
- `sid` int(11) NOT NULL AUTO_INCREMENT,
- `sname` varchar(20) NOT NULL,
- `fid` int(11) NOT NULL,
- PRIMARY KEY (`sid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `secondsort`
- --
- LOCK TABLES `secondsort` WRITE;
- /*!40000 ALTER TABLE `secondsort` DISABLE KEYS */;
- /*!40000 ALTER TABLE `secondsort` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `storage`
- --
- DROP TABLE IF EXISTS `storage`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `storage` (
- `storageid` int(11) NOT NULL AUTO_INCREMENT,
- `gid` int(11) NOT NULL,
- `inprice` double(10,3) NOT NULL,
- `outprice` double(10,3) NOT NULL,
- `marketprice` double(10,3) NOT NULL,
- `count` int(11) NOT NULL,
- PRIMARY KEY (`storageid`)
- ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `storage`
- --
- LOCK TABLES `storage` WRITE;
- /*!40000 ALTER TABLE `storage` DISABLE KEYS */;
- /*!40000 ALTER TABLE `storage` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `transfer`
- --
- DROP TABLE IF EXISTS `transfer`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `transfer` (
- `tid` int(11) NOT NULL AUTO_INCREMENT,
- `account` char(19) NOT NULL,
- `password` char(6) NOT NULL,
- `balance` double(10,3) NOT NULL,
- PRIMARY KEY (`tid`)
- ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `transfer`
- --
- LOCK TABLES `transfer` WRITE;
- /*!40000 ALTER TABLE `transfer` DISABLE KEYS */;
- INSERT INTO `transfer` VALUES (1,'','',10000.000),(2,'','',10000.000),(3,'','',10000.000);
- /*!40000 ALTER TABLE `transfer` ENABLE KEYS */;
- UNLOCK TABLES;
- --
- -- Table structure for table `userinfo`
- --
- DROP TABLE IF EXISTS `userinfo`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `userinfo` (
- `userid` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(20) NOT NULL,
- `password` varchar(20) NOT NULL,
- `question` varchar(30) NOT NULL,
- `answer` varchar(30) NOT NULL,
- `realname` varchar(20) DEFAULT NULL,
- `sex` varchar(2) DEFAULT NULL,
- `email` varchar(20) NOT NULL,
- `id` char(18) NOT NULL,
- `postalcode` varchar(6) DEFAULT NULL,
- `address` varchar(30) DEFAULT NULL,
- `tel` varchar(11) DEFAULT NULL,
- `score` double(10,3) DEFAULT NULL,
- PRIMARY KEY (`userid`)
- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;
- /*!40101 SET character_set_client = @saved_cs_client */;
- --
- -- Dumping data for table `userinfo`
- --
- LOCK TABLES `userinfo` WRITE;
- /*!40000 ALTER TABLE `userinfo` DISABLE KEYS */;
- INSERT INTO `userinfo` VALUES (1,'ppp','','qqqqq','ddddd','rrrr','男','123@QQ.com','dd','dfdf','eeee','',123.100);
- /*!40000 ALTER TABLE `userinfo` ENABLE KEYS */;
- UNLOCK TABLES;
- /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
- /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
- /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
- /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
- /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
- -- 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包
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE generatorConfiguration
- PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
- "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
- <generatorConfiguration>
- <!-- 数据库驱动包位置 -->
- <classPathEntry location="E:\JavaSmallTools\myBi\mysql-connector-java-5.1.26-bin.jar" />
- <context id="DB2Tables" targetRuntime="MyBatis3">
- <commentGenerator>
- <property name="suppressDate" value="true" />
- </commentGenerator>
- <!-- 数据库链接URL、用户名、密码 -->
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://localhost/ebuy" userId="root" password="123456">
- </jdbcConnection>
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <!-- 生成模型的包名和位置 -->
- <javaModelGenerator targetPackage="com.welv.model"
- targetProject="E:\JavaSmallTools\myBi\com">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <!-- 生成的映射文件包名和位置 -->
- <sqlMapGenerator targetPackage="com.welv.mapping"
- targetProject="E:\JavaSmallTools\myBi\com">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <!-- 生成DAO的包名和位置 -->
- <javaClientGenerator type="XMLMAPPER"
- targetPackage="com.welv.dao" targetProject="E:\JavaSmallTools\myBi\com">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <!-- 数据库中需要生成java代码的表的映射关系 -->
- <table tableName="firstsort" domainObjectName="Firstsort" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="goods" domainObjectName="Goods" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="leaveword" domainObjectName="Leaveword" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="manager" domainObjectName="Manager" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="middle" domainObjectName="Middle" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="news" domainObjectName="News" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="orders" domainObjectName="Orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="placard" domainObjectName="Placard" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="purview" domainObjectName="Purview" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="sale" domainObjectName="Sale" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="secondsort" domainObjectName="Secondsort" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="transfer" domainObjectName="Transfer" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="userinfo" domainObjectName="Userinfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- <table tableName="storage" domainObjectName="Storage" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table>
- </context>
- </generatorConfiguration>
在该文件中,主要分为5部分,每部分的内容基本上在文件中都有说明,值得注意的是第五部分,也就是各个表的映射关系部分中,将大部分的值都赋false,其原因是,如果为true则会产生大量的无用文件,以及有用文件中产生大量的无用代码,全部使用false有利于generate clean code,便于后期的维护。
在修改完generator.xml文件后,将文件和工具(mybatis-generator-core-1.3.2)放在同一目录下。使用cmd命令,cd到该文件夹下,输入命令:
- 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)的更多相关文章
- Spring4 mvc+maven 框架搭建(3)
经过前面两个环节,spring mvc的原料已经准备好了,现在就可以正式开始搭建springmvc框架了. 首先先介绍介绍搭建的框架具有的功能: 1)集成log4j,配置好日志相关并可以打印出相关的日 ...
- Spring4 mvc+maven 框架搭建(2)
在上一篇博客中,数据库数据和mybatis相关的java代码已经生成,接下来就可以使用IDE工具来搭建框架了. 在这里,我使用maven构建和管理代码,使用jdk1.8环境. 首先打开Eclipse, ...
- (一)springmvc+spring+mybatis+maven框架搭建
(一)springmvc+spring+mybatis+maven框架搭建 1.说明 工作之余,为了学习点东西.先搭建个框架. 以后要往里面加东西,比如rabbitMQ.redis.shiro等. 也 ...
- Spring MVC + jpa框架搭建,及全面分析
一,hibernate与jpa的关系 首先明确一点jpa是什么?以前我就搞不清楚jpa和hibernate的关系. 1,JPA(Java Persistence API)是Sun官方提出的Java持久 ...
- SSM+Redis+Shiro+Maven框架搭建及集成应用
引文: 本文主要讲述项目框架搭建时的一些简单的使用配置,教你如何快速进行项目框架搭建. 技术: Spring+SpringMVC+Mybatis+Redis+Shiro+Maven ...
- 从零开始--Spring项目整合(1)使用maven框架搭建项目
这些年一直在用spring的框架搭建项目,现在开始我们从零开始利用Spring框架来搭建项目,目前我能想到有Spring.SpringMVC.SpringJDBC.Mybatis.WebSockt.R ...
- spring4+hibernate4+maven环境搭建
本文主要介绍利用maven搭建spring4+hibernate4开发环境. 首先我们创建一个maven项目,具体步骤就不详细介绍了,看看我们pom.xml文件 <project xmlns=& ...
- Spring MVC Maven 环境搭建与部署
本文简单演示了本地开发环境的搭建.项目出包.部署运行.HelloWorld,以及部分注意事项. 起初的玩法:先安装Eclipse,然后分别下载并安装Maven.spring的插件,再进行工程模式转换, ...
- Spring+Spring MVC+Hibernate框架搭建实例
前言:这里只是说明整个搭建流程,并不进行原理性的讲解 一 下面所需要用到的数据库配置: 数据库方面,使用mysql创建一个users表,具体代码如下: 1 2 3 4 5 6 7 8 9 10 11 ...
随机推荐
- myeclipse cannot connect to vm
启动tomcat时,tomcat可以直接运行,而debug时弹出 解决方法:打开360安全卫士的功能大全找到修复网络(LSP)点击立即修复就可以使用debug
- 第32章:MongoDB-索引--Capped固定集合
①Capped集合(固定集合) Capped集合的大小固定,性能好,如果空间用完了,新的对象会覆盖旧的对象. find时默认就是插入的顺序,Capped集合会自动维护. ②语法 db.createCo ...
- HDU 1517 A Multiplication Game (SG函数找规律)
题意:两个玩家玩一个游戏,从 p = 1,开始,然后依次轮流选择一个2 - 9的数乘以 p,问你谁先凑够 p >= n. 析:找规律,我先打了一下SG函数的表,然后就找到规律了 我找到的是: 1 ...
- Logging from multiple processes using log4net
When logging with log4net to a file (using the FileAppender), the FileAppender is holding an exclusi ...
- java中的中文字符转码技术
package com.yin.test; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; impor ...
- Hdu4185 Oil Skimming
Oil Skimming Problem Description Thanks to a certain "green" resources company, there is a ...
- idea2018.2.4的安装激活与热部署插件JRebel的激活方法
去Idea的官网下载如上版本的Idea安装文件 并且在网上搜索下载如下破解工具 放置在相应的Idea安装目录下 然后在Idea中输入激活码 { "licenseId": " ...
- shell 命令 查看本机ip
ifconfig 结果有很多,查看env0的inet,就是本机的ip地址
- scikit-FEM-例1-求解Possion边值问题
""" Author: kinnala Solve the problem -∇²u = 1 with zero boundary conditions on a uni ...
- [javascript-code-snippet]javascript代码段
<ul> <li>Picture 1</li> <li>Picture 2</li> <li>Picture 3</li& ...