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
这里就不一一解释了。
1 <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 <!-- geelynote 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。
(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 <columnOverride column="detail" jdbcType="VARCHAR" /> 81 <columnOverride column="sub_images" jdbcType="VARCHAR" /> 82 </table> 83 <table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> 84 85 86 <!-- geelynote mybatis插件的搭建 --> 87 </context> 88 </generatorConfiguration>
(3)datasource.properties
时间: 2024-10-13 07:40:28