Skip to content

Commit

Permalink
17.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
FirokOtaku committed Nov 8, 2021
1 parent b4f9f0f commit 6bef7d2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
60 changes: 44 additions & 16 deletions readme-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ can generate whole set of MVC CRUD code for SpringBoot during compiling.

### How to customize generation templates

Just edit `xxxTemplate` value in `@MVCIntrospective`.
`@MVCIntrospective` has multiple configurable fields. Each of them has detailed description at [Javadoc](/src/main/java/firok/spring/mvci/MVCIntrospective.java).

> Resetting any of those values to `firok.spring.mvci.Constants.DISABLE` (`"##DISABLE##"`) will disable generating that code
Most of those fields are annotated with `@AvailableValues` annotation, which describes the acceptable values of the relevant fields. A field can take any custom value (usually for a template string), if `Constants.CUSTOM` is listed in a `@AvailableValues`. Or any other non-listed values would cause compile error.

> If you do not want to write a long string template for many times, you could define that value as a `public static final String` field and use it in annotation.
`PREFER_XXX` values means that those values could be overrided by upper configs. `DEFAULT` means the default value (usually a default template string) would be taken.

Default templates are stored in `firok.spring.mvci.internal.DefaultXXXTemplate`.
`@MVCIntrospective` can be annotated on `class` or `package`.
When generating for a bean class, we would search from children packages to parent packages to find any `@MVCIntrospective`. Then decide each value of fields.

> Hope you know what is `package-info.java`
### Replacing-key-value-pair for templates

You could adjust templates by editing `templateXXX` fields in `@MVCIntrospective`.

> default templates are stored in `resources` folder
When customizing templates, keys below will be replaced:

Expand All @@ -42,26 +51,45 @@ Key | Meaning | Example
`##SERVICE_IMPL_PACKAGE##` | service impl package | `firok.spring.demo.service.impl`
`##CONTROLLER_PACKAGE##` | controller package | `firok.spring.demo.controller`

### How to customize generation names
Most of **replacing-value** of **replacing-key** are generated from templates. However, we do not guarantee the order in which the **replacing-values** are generated.

Editing `xxxPackage` of `@MVCIntrospective` would change the package to generate; Editing `xxxName` would change the name to generate.
An extra replacement would be taken when generating `XXX_PACKAGE##`, which would replace the `\.entity|bean\.` to `.mapper.`, `.service.`, `.service_impl.` or `.controller.`.

> For a bean class `a.b.c.entity.d.e.TestEntity`,
> package for controller should be `a.b.c.controller.d.e`
Except default replacing-key-value-pairs, you could create custom ones by editing `extraParams` of `@MVCIntrospective`. If multiple configs contain the same **replacing-key**, the **replacing-value** closer to bean class definition would be adopted.

> `a.b``##TEST## = "test"`
> `a.b.c``##TEST## = "test2"`,
> `a.b.c.TestBean``##TEST## = "test3"`,
> `a.b.c.TestBean``##TEST## = "test3"`,
> `a.b.c.Test2Bean``##TEST## = "test2"`,
> `a.b.DemoBean``##TEST## = "test"`
## Something else

**MVCI itself** is not based on SpringBoot and MybatisPlus. But **the default templates used by MVCI** is based on SpringBoot and MybatisPlus.
By default, you should import them as dependencies, or the project will not pass the compilation.

A usable maven dependency is:
In addition, you need to properly import dependencies such as database drivers, or your project may not work properly.

```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.2</version>
</dependency>
```
MVCI has only passed testing under **Java17**. It may work in lower version of Java. But you may need to edit the `@SupportedSourceVersion` value of `firok.spring.mvci.MVCIntrospectProcessor` and some code of MVCI.

In addition, you need to properly import dependencies such as database drivers, or your project may not work properly.
## Changelog

### 17.1.1

* minor code improvements

### 17.1.0

* now we could adjust generation on package level

### 17.0.0

* increased supported JDK version to 17

MVCI has only passed testing under **Java16**. It may work in lower version of Java. But you may need to edit the `@SupportedSourceVersion` value of `firok.spring.mvci.MVCIntrospectProcessor` and some code of MVCI.
### 1.0.0

* implemented base functions
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
为 SpringBoot 生成一整套 MVC CRUD 结构.
(包含 mapper, service, service impl, controller)

[Readme - English](readme-en.md) (尚未更新至17.1.x)
[Readme - English](readme-en.md)

## 使用方式

Expand All @@ -22,7 +22,7 @@

`@MVCIntrospective` 有多个字段可供配置, 各字段配置含义在 [Javadoc 中](/src/main/java/firok/spring/mvci/MVCIntrospective.java) 有详细描述.

大部分字段标注了 `@AvailableValues`注解, 这描述了相关字段可接受的值.
大部分字段标注了 `@AvailableValues` 注解, 这描述了相关字段可接受的值.
如果 `@AvailableValues` 中包含 `Constants.CUSTOM`, 则表示此字段可以提供任意自定义值 (一般是自定义模板字符串);
否则只能为此字段提供预设值之一, 提供其它值会使得代码无法通过编译.

Expand All @@ -38,7 +38,7 @@

修改 `@MVCIntrospective` 注解中的 `templateXXX` 值即可调整相关的生成模板.

默认的模板存放在 `resources` 目录下.
> 默认的模板存放在 `resources` 目录下
根据模板生成内容时, 如下键会被替换:

Expand All @@ -56,7 +56,7 @@
`##SERVICE_IMPL_PACKAGE##` | Service Impl 位置 | `firok.spring.demo.service.impl`
`##CONTROLLER_PACKAGE##` | Controller 位置 | `firok.spring.demo.controller`

虽然大部分 **替换键****替换值** 也是根据模板生成的, 但我们不对生成相关 **替换值** 的顺序做任何保证, 在调整这些 **替换键模板** 时请 **不要** 使用除了 `##BEAN_NAME_FULL##`, `##BEAN_NAME_SHORT##``##BEAN_PACKAGE##` 之外的 **替换键**.
大部分 **替换键****替换值** 也是根据模板生成的, 但我们不对生成相关 **替换值** 的顺序做任何保证, 在调整这些 **替换键模板** 时请 **不要** 使用除了 `##BEAN_NAME_FULL##`, `##BEAN_NAME_SHORT##``##BEAN_PACKAGE##` 之外的 **替换键**.

生成各 `##XXX_PACKAGE##` 替换值时, 会多执行一次额外替换, 替换内容是将 `\.entity|bean\.` 替换为 `.mapper.`, `.service.`, `.service_impl.``.controller.`.

Expand All @@ -67,7 +67,7 @@

> 假如在 `a.b` 包上指定了 `##TEST## = "test"`,
> 假如在 `a.b.c` 包上指定了 `##TEST## = "test2"`,
> `a.b.c.TestBean` 上指定了 `##TEST## = "test3"`,
> 假如在 `a.b.c.TestBean` 上指定了 `##TEST## = "test3"`,
> 生成 `a.b.c.TestBean` 实体时将使用 `##TEST## = "test3"`,
> 生成 `a.b.c.Test2Bean` 实体时将使用 `##TEST## = "test2"`,
> 生成 `a.b.DemoBean` 实体时将使用 `##TEST## = "test"`
Expand Down

0 comments on commit 6bef7d2

Please sign in to comment.