項(xiàng)目環(huán)境
操作系統(tǒng):Window10痒留,IDE:IDEA前硫,服務(wù)器:Centos7.0
項(xiàng)目初始化
數(shù)據(jù)庫
Navicat連接線上數(shù)據(jù)庫,新建數(shù)據(jù)庫mmall捧书,導(dǎo)入表結(jié)構(gòu)運(yùn)行sql文件,結(jié)果如下:
創(chuàng)建項(xiàng)目
打開IDEA選擇骤星,create new project经瓷,選擇maven,勾選create from a'rchetype洞难,如下圖選擇:選擇next舆吮,GroupId填com,ArtifactId填mmall,點(diǎn)擊next歪泳,繼續(xù)點(diǎn)擊next萝勤,Project name填mmall露筒,點(diǎn)擊finsh呐伞,項(xiàng)目自動(dòng)生成,如下圖:
配置tomcat server蕾盯,選擇deployment,點(diǎn)擊+號(hào)選擇mmall:war蓝丙,點(diǎn)擊OK级遭。
啟動(dòng)tomcat,web訪問localhost:8080渺尘,顯示hello world挫鸽,如下圖:
Git
創(chuàng)建README.md文件,創(chuàng)建.gitignore文件并在文件里設(shè)置要忽略的文件
*.class
#package file
*.war
*.ear
#maven
out/
target/
#idea
.idea/
/idea/
*.ipr
*.iml
*.iws
#temp file
*.log
*.cache
*.diff
*.patch
*.tmp
#mac system ignore
.DS_Store
Thumbs.db
而后連接遠(yuǎn)程倉庫鸥跟,push項(xiàng)目到master分支上
git init
git commit -am "你的注釋"
git remote add origin git@*****你的遠(yuǎn)程倉庫地址
git push -u origin master
而后再創(chuàng)建并切換到V1.0分支丢郊,同步到遠(yuǎn)程倉庫
git checkout -b v1.0 origin/master
git push origin HEAD -u
項(xiàng)目包結(jié)構(gòu)
在main包下java包里創(chuàng)建com.mmall,在mmall包里繼續(xù)創(chuàng)建common controller dao pojo service util vo
Mybatis三劍客
mybatis-generator配置
在pom.xml文件<build>....</build>里加入如下配置就加載了需要的jar包
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
如下圖
在resources包下医咨,新建generatorConfig.xml配置文件枫匾,datasource.properties文件,在datasource.properties里編寫如下代碼拟淮,
db.driverLocation=你的mysql連接驅(qū)動(dòng)所在位置
db.driverClassName=com.mysql.jdbc.Driver
#db.url=jdbc:mysql://192.1.1.1:3306/mmall?characterEncoding=utf-8
db.url=你的數(shù)據(jù)庫連接地址和數(shù)據(jù)庫名干茉,格式如注釋
db.username=你的登錄名
db.password=你的登錄密碼
generatorConfig.xml里的配置,可下載generatorConfig.xml文件參考惩歉,然后點(diǎn)擊IDEA右側(cè)maven project等脂,雙擊plugin下的mybatis-generator:generate,命令開始執(zhí)行撑蚌,可以看到終端提示Build Success時(shí)上遥,看一下dao層和pojo層和mappers,對(duì)應(yīng)接口争涌,類粉楚,實(shí)現(xiàn)文件生成成功。
接下來,把mapper下每個(gè)mapper文件里的create time 和 update time 交給DB生成模软,找到insert伟骨,把create time,update time的value改為now()燃异,now()是mysql內(nèi)置函數(shù)携狭,獲取本地時(shí)間
update操作中只需把update time 修改為now()
修改完所有的mapper,注意不要修改錯(cuò)回俐,分清字段和value逛腿,修改的目的是更新時(shí)間不在業(yè)務(wù)代碼里實(shí)現(xiàn),用數(shù)據(jù)庫的內(nèi)置函數(shù)來填寫仅颇。
mybatis-plugin
破解以及下載mybatis-plugin參考以下博客
https://www.awei.org/2017/11/08/idea-mybatis-plugin-3-21-po-jie-fang-fa/
mybatis-pageHelper
先在pom.xml加載
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>x.x.x</version>
</dependency>
spring配置
從官方demo中拉取配置文件applicationContext.xml单默,applicationContext-datasource.xml到resources包中再新建mmall.properties文件,如鏈接內(nèi)配置ftp服務(wù)器地址忘瓦,拉取dispatcher-servlet.xml搁廓,web.xml到WEB-INF里