项目环境
操作系统:Window10,IDE:IDEA,服务器:Centos7.0
项目初始化
数据库
Navicat连接线上数据库,新建数据库mmall,导入表结构运行sql文件,结果如下:
创建项目
打开IDEA选择,create new project,选择maven,勾选create from a'rchetype,如下图选择:选择next,GroupId填com,ArtifactId填mmall,点击next,继续点击next,Project name填mmall,点击finsh,项目自动生成,如下图:
配置tomcat server,选择deployment,点击+号选择mmall:war,点击OK。
启动tomcat,web访问localhost:8080,显示hello world,如下图:
Git
创建README.md文件,创建.gitignore文件并在文件里设置要忽略的文件
*.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
而后连接远程仓库,push项目到master分支上
git init
git commit -am "你的注释"
git remote add origin git@*****你的远程仓库地址
git push -u origin master
而后再创建并切换到V1.0分支,同步到远程仓库
git checkout -b v1.0 origin/master
git push origin HEAD -u
项目包结构
在main包下java包里创建com.mmall,在mmall包里继续创建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连接驱动所在位置
db.driverClassName=com.mysql.jdbc.Driver
#db.url=jdbc:mysql://192.1.1.1:3306/mmall?characterEncoding=utf-8
db.url=你的数据库连接地址和数据库名,格式如注释
db.username=你的登录名
db.password=你的登录密码
generatorConfig.xml里的配置,可下载generatorConfig.xml文件参考,然后点击IDEA右侧maven project,双击plugin下的mybatis-generator:generate,命令开始执行,可以看到终端提示Build Success时,看一下dao层和pojo层和mappers,对应接口,类,实现文件生成成功。
接下来,把mapper下每个mapper文件里的create time 和 update time 交给DB生成,找到insert,把create time,update time的value改为now(),now()是mysql内置函数,获取本地时间
update操作中只需把update time 修改为now()
修改完所有的mapper,注意不要修改错,分清字段和value,修改的目的是更新时间不在业务代码里实现,用数据库的内置函数来填写。
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文件,如链接内配置ftp服务器地址,拉取dispatcher-servlet.xml,web.xml到WEB-INF里