Commit 35fae6c4 by 朱瑞泽

add doc

parent f17889aa
# demo 工程说明
### 工程结构
![](gic-demo-helper/src/main/resources/snapshot_01.png)
### 生成 mybatis model mapper xml
gic-demo-helper工程,配置generatorConfig_test.xml。
```xml
<context id="testTables" targetRuntime="MyBatis3">
<!-- 配置数据库连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://xxxx:6634/test?characterEncoding=utf-8"
userId="userId"
password="password">
</jdbcConnection>
<!-- 配置Model生成 -->
<javaModelGenerator targetPackage="com.gic.demo.project.service.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaModelGenerator>
<!-- 配置 mapper xml 生成 -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 配置 mapper 对应接口 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.gic.demo.project.service.dao.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 指定数据库表 -->
<table tableName="tab_gic_demo_enterprise" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"/>
<table tableName="tab_gic_demo_store" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"/>
</context>
```
生成代码
```java
public class GeneratorStartUp {
public static void main(String[] args) {
try {
List<String> warnings = new ArrayList<>();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream("generatorConfig_test.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(is);
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
### 生成雪花id
未来 UniqueIdUtils 会集成到 gic-commons 4.x 里
```java
public class TestRun {
public static void main(String[] args) {
// 生成long型id
UniqueIdUtils.uniqueLong();
// 生成hex字符串型id
UniqueIdUtils.uniqueLongHex();
}
}
```
### sharding-jdbc 配置
1. 参照 sharding-jdbc 配置说明配置分表,保存到mongodb
2. 修改 Apollo配置 COMMON.sharding sharding.shardingId
3. 配置xml
```xml
<bean id="dataSource" class="com.gic.sharding.sdk.ShardingDatasource" init-method="init">
<property name="shardingId" value="${sharding.shardingId}"/>
<property name="maxSize" value="${jdbc.maxsize}"/>
<property name="urlType" value="${sharding.urlType:inner}"/>
</bean>
```
### dubbo 服务
参考 gic 3.x,com.alibaba.dubbo.container.Main 替换为 com.gic.commons.DubboMain 。
### web rest 服务
使用 spring boot 内嵌 tomcat 启动
```java
/**
* Spring Boot Web 启动类
*
* @author zhurz
*/
@SpringBootApplication
@ImportResource(value = {
// spring 配置初始化xml
"classpath*:gic-demo-init.xml",
// 通用 dubbo 配置
"classpath*:dubbo-setting.xml",
// dubbo api 配置
"classpath*:dubbo-gic-demo-web.xml",
// 拦截器配置
"classpath*:spring-interceptor.xml"
})
public class Main {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Main.class, args);
DubboContextUtil.setApplicationContext(context.getParent());
}
}
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment