搭建一个用于练习的CRM项目
1.pom.xml文件的配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cl</groupId>
<artifactId>crm</artifactId>
<version>1.0-SNAPSHOT</version>
<name>crm</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<dependencies>
<!-- web 环境 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- aop -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- 测试环境 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<!-- 分⻚插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
<!-- commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<!-- json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<!-- DevTools 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 如果没有该配置,热部署的devtools不⽣效 -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
2.application.yml文件的配置
## 端⼝号 上下⽂路径
server:
port: 9090
servlet:
context-path: /crm01
## 数据源配置
spring:
datasource:
type: com.mchange.v2.c3p0.ComboPooledDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/crm?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: 1234
## freemarker,注意它与datasource是同级的
freemarker:
suffix: .ftl
content-type: text/html
charset: UTF-8
template-loader-path: classpath:/views/
## 启⽤热部署
devtools:
restart:
enabled: true
additional-paths: src/main/java
## 设置返回格式乱码
http:
encoding:
charset: utf-8
force-response: true
## mybatis 配置
mybatis:
mapper-locations: classpath:/mappers/*.xml
type-aliases-package: com.cl.crm.vo;com.cl.crm.query;com.cl.crm.dto
configuration:
map-underscore-to-camel-case: true
## pageHelper 分⻚
pagehelper:
helper-dialect: mysql
## 设置 dao ⽇志打印级别
logging:
level:
com:
cl:
crm:
dao: debug
#F:\m2\repository\mysql\mysql-connector-java\8.0.18\mysql-connector-java-8.0.18.jar
3.generatorConfig.xml的配置
<?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>
<!-- 数据库驱动路径:在左侧project边栏的External Libraries中找到mysql的驱动,右键选择copy
path -->
<classPathEntry
location="F:\m2\repository\mysql\mysql-connector-java\8.0.18\mysql-connector-java-8.0.18.jar"/>
<!-- context 是逆向⼯程的主要配置信息,id:起个名字,targetRuntime:设置⽣成的⽂件适⽤于哪个
mybatis版本 -->
<context id="DB2Tables" targetRuntime="MyBatis3">
<!--optional,指在创建class时,对注释进⾏控制-->
<commentGenerator>
<!-- 是否去除⽇期那⾏注释 -->
<property name="suppressDate" value="true"/>
<!-- 是否去除⾃动⽣成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库链接地址账号密码 -->
<jdbcConnection
driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/crm?serverTimezone=GMT%2B8"
userId="root"
password="1234">
<!--Mysql如果不使用此属性,在生成时会报错-->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!--
java类型处理器
⽤于处理DB中的类型到Java中的类型,默认使⽤JavaTypeResolverDefaultImpl;
注意⼀点,默认会先尝试使⽤Integer,Long,Short等来对应DECIMAL和NUMERIC数据类
型;
true:使⽤ BigDecimal对应DECIMAL和NUMERIC数据类型
false:默认,把JDBC DECIMAL和NUMERIC类型解析为Integer
-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- ⽣成Model类存放位置 -->
<javaModelGenerator targetPackage="com.cl.crm.vo"
targetProject="src/main/java">
<!-- 在targetPackage的基础上,根据数据库的schema再⽣成⼀层package,⽣成的类放在这个
package下,默认为false -->
<property name="enableSubPackages" value="true"/>
<!-- 设置是否在getter⽅法中,对String类型字段调⽤trim()⽅法 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--⽣成映射⽂件存放位置-->
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--⽣成Dao类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.cl.crm.dao"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 数据库的表名与对应的实体类的名称,tableName是数据库中的表名,domainObjectName是⽣成
的JAVA模型名 -->
<table tableName="t_user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
逆向生成启动指令:mybatis-generator:generate -e
至此,项目的基本设置就配置完成了,接下来只需要根据需求添加相应的包和类就好了。