1.本項目包含框架:
springboot mybatis mysql druid
2.項目結構:
3.parent的pom
,這裡加個注釋,如果倉庫最好搭建一個私服,然後私服的id和引用的id需要一致,且替換中央倉庫,下面是我配置的私服mirror:
<mirror> <id>cqfac-maven</id> <name>CQFAC</name> <url>http://10.20.112.118:8081/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
以下是項目中引用私服和其餘配置,這樣就會大大加速jar包管理過程
<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.cqfae.boot</groupId> <artifactId>mina-parent</artifactId> <version>1.0.5-SNAPSHOT</version> <packaging>pom</packaging>
<name>mina-parent</name> <url>http://maven.apache.org</url>
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent>
<repositories> <repository> <id>cafac-maven</id> <name>CQFAC</name> <url>http://10.20.112.118:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories>
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <druid.version>1.1.10</druid.version> <mybatis.version>1.3.2</mybatis.version> <pagehelper.version>1.2.5</pagehelper.version> </properties>
<dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- hot boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies>
<modules> <module>mina-base</module> <module>mina-common</module> <module>mina-domain</module> <module>mina-service</module> <module>mina-service-dubbo</module> <module>mina-service-redis</module> <module>mina-service-shiro</module> <module>mina-service-solr</module> <module>mina-web</module> </modules>
<dependencyManagement> <dependencies> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-base</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-common</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-domain</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-dubbo</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-redis</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-shiro</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-solr</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-web</artifactId> <version>${project.version}</version> </dependency>
<!-- druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency>
<!-- mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>${pagehelper.version}</version> </dependency>
</dependencies> </dependencyManagement>
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
4.子項目之一domain:
此項目主要是對資料庫的交互,所以資料庫相關的東西都寫在這裡面的
pom:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.cqfae.boot</groupId> <artifactId>mina-parent</artifactId> <version>1.0.5-SNAPSHOT</version> </parent>
<artifactId>mina-domain</artifactId> <packaging>jar</packaging>
<name>mina-domain</name> <url>http://maven.apache.org</url>
<dependencies> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-base</artifactId> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-common</artifactId> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> </dependency> <!-- datasource --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> </dependency>
</dependencies> </project>
結構:
MapperConfig.java:,既然都分模塊了,配置什麼的也要寫進來
@Configuration @MapperScan(basePackages="com.cqfae.boot.mina.domain.dao") public class MapperConfig {
}
5.其餘子項目,除了web,配置都差不多,橫向擴展嘛6.web項目:
5.其餘子項目,除了web,配置都差不多,橫向擴展嘛
POM:
<artifactId>mina-web</artifactId> <packaging>war</packaging>
<name>mina-web</name> <url>http://maven.apache.org</url>
<dependencies> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service</artifactId> </dependency>
<!-- web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
<!-- UI template --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> </dependencies>
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 指定該Main Class為全局的唯一入口 --> <mainClass>com.cqfae.boot.mina.web.App</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal><!--可以把依賴的包都打包到生成的Jar包中--> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
項目結構:
啟動類:
package com.cqfae.boot.mina.web;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication @RestController @ComponentScan("com.cqfae.boot.mina") public class App {
public static void main(String[] args) { SpringApplication.run(App.class, args); } }
application.properties:
spring.profiles.active=dev
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.druid.db-type=mysql spring.datasource.druid.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.initial-size=5 spring.datasource.druid.max-active=10 spring.datasource.druid.min-idle=10 spring.datasource.druid.max-wait=10000 spring.datasource.druid.validation-query=SELECT 1 spring.datasource.druid.stat-view-servlet.enabled = true spring.datasource.druid.stat-view-servlet.url-pattern=/druid/* spring.datasource.druid.stat-view-servlet.login-username=druid spring.datasource.druid.stat-view-servlet.login-password=druid spring.datasource.druid.web-stat-filter.enabled = true spring.datasource.druid.web-stat-filter.url-pattern=/* spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/* spring.datasource.druid.filters=stat,wall,log4j spring.datasource.druid.aop-patterns=com.cqfae.boot.mina.service.*
#template engine spring.freemarker.allow-request-override=false spring.freemarker.cache=true spring.freemarker.check-template-location=true spring.freemarker.charset=UTF-8 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=false spring.freemarker.expose-session-attributes=false spring.freemarker.expose-spring-macro-helpers=false
#mybatis #entity掃描的包名 mybatis.type-aliases-package=com.cqfae.boot.mina.domain.entity #Mapper.xml所在的位置 mybatis.mapper-locations=classpath*:/mybaits/mapper/*.xml #mybatis擴展配置 @see https://blog.csdn.net/lovebosom/article/details/52584562 mybatis.configuration.cache-enabled=false mybatis.configuration.lazy-loading-enabled=true mybatis.configuration.aggressive-lazy-loading=true mybatis.configuration.multiple-result-sets-enabled=true mybatis.configuration.use-column-label=true mybatis.configuration.use-generated-keys=false mybatis.configuration.auto-mapping-behavior=FULL mybatis.configuration.default-executor-type=REUSE mybatis.configuration.default-statement-timeout=25 mybatis.configuration.safe-row-bounds-enabled=false mybatis.configuration.map-underscore-to-camel-case=true mybatis.configuration.local-cache-scope=SESSION mybatis.configuration.jdbc-type-for-null=OTHER mybatis.configuration.lazy-load-trigger-methods=equals,clone,hashCode,toString
#pagehelper分頁插件配置 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
application-dev.properties:
server.port=8099
spring.datasource.druid.url=jdbc:mysql://xxx:xxx?useSSL=false spring.datasource.druid.username=pdc_gdshz_datacenter spring.datasource.druid.password=Paic1234
logging.level.com.cqfae.boot=DEBUG
#spring.freemarker.cache = true #u751Fu4EA7u73AFu5883u8BBEu7F6Eu4E3Atrue #u5F00u53D1u73AFu5883u8BBEu7F6Eu4E3Afalse,u9ED8u8BA4false spring.freemarker.cache = false spring.thymeleaf.cache = false spring.mustache.cache = false spring.groovy.template.cache = false
# redis spring.redis.cluster.nodes=xxx:26279,xxx:26279,xxx:26279 spring.redis.password=password
mapper:
分頁插件就是好用,下面就是我一個簡單的分頁查詢:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.cqfae.boot.mina.domain.dao.HouseUseTypeDao" >
<select id="findPage" resultType="houseUseType" parameterType="com.cqfae.boot.mina.domain.vo.HouseUseTypeVo"> select * from pdc_gdshz_datacenter.busi_as_house_use_type_m </select>
</mapper>
7.service項目集成了所有service相關的服務,包括資料庫和其餘三方服務
<artifactId>mina-service</artifactId> <packaging>jar</packaging>
<name>mina-service</name> <url>http://maven.apache.org</url>
<dependencies> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-domain</artifactId> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-dubbo</artifactId> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-redis</artifactId> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-shiro</artifactId> </dependency> <dependency> <groupId>com.cqfae.boot</groupId> <artifactId>mina-service-solr</artifactId> </dependency>
其餘想加什麼服務自己再加,橫向擴展
8.附上幾句常用maven命令(在parent項目下運行):
a.批量修改版本號:versions:set -DnewVersion=1.0.5-SNAPSHOT
b.打包命令:clean package -Dmaven.test.skip=true
由於公司牆了所有的開源代碼託管平台,代碼就不提交了,需要的同學推薦按照上面的搭,很有利於熟悉項目構建
推薦閱讀: