Skip to content

Commit

Permalink
17.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FirokOtaku committed Oct 18, 2022
1 parent 2d5c75e commit e075c59
Show file tree
Hide file tree
Showing 19 changed files with 786 additions and 316 deletions.
39 changes: 39 additions & 0 deletions doc/changelog-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Changelog

## 17.6.0

* add more runtime helper class
* add Java module support
* add more docs

## 17.5.0

* now source files would be included when compiling

## 17.4.0

* minor code improvements

## 17.3.0

* now structures will be generated at correct place

## 17.2.0

* now MVCI would generate some classes store bean information and structure information

## 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

## 1.0.0

* implemented base functions
39 changes: 39 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 变更日志

## 17.6.0

* 新增运行时数据类用于收集 mapper, service, service impl, controller
* 新增 Java 模块化支持
* 新增更多文档

## 17.5.0

* 现在打包时会附带源码等内容

## 17.4.0

* 细微代码改动

## 17.3.0

* 现在各种结构会生成于正确包下

## 17.2.0

* 现在 MVCI 将会额外生成数个包含生成数据的信息的类

## 17.1.1

* 细微代码改动

## 17.1.0

* 调整配置方式, 现在可以以包为级别批量调整生成

## 17.0.0

* 提升JDK支持版本至17

## 1.0.0

* 实现基本功能
153 changes: 153 additions & 0 deletions doc/config-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Configuration

All configurable items are listed as fields of `@MVCIntrospective`.

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.

`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.

`@MVCIntrospective` can be annotated on `class` or `package` ([see below](#do-not-generate-controller-for-all-bean-in-a-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`
## Configurable items

* base package path when generating structures:
`basePackage`
* name of bean:
`beanNameShort`, `beanNameFull`
* whether generate some structures:
`generate XXX`
* templates used to generate name of structures:
`template XXX Name`
* templates used to generate content of structures:
`template XXX Content`
* templates used to generate package path of structures:
`template XXX Package`
* customized replacements for templates:
`extraParams`

## Examples

### do not generate service impl for a bean

bean/UserBean.java

```java
import lombok.Data;
import firok.spring.mvci.Constants;
import firok.spring.mvci.MVCIntrospective;

@Data
@MVCIntrospective(
generateServiceImpl = Constants.FALSE
)
public class UserBean
{
String username;
String password;
}
```

### do not generate controller for all bean in a package

bean/package-info.java

```java
@MVCIntrospective(
generateController = Constants.FALSE
)
package firok.demo.spring.bean;

import firok.spring.mvci.Constants;
import firok.spring.mvci.MVCIntrospective;
```

### modify names of structures

bean/UserBean.java

```java
import firok.spring.mvci.MVCIntrospective;
import lombok.Data;

@Data
@MVCIntrospective(
beanNameShort = "UserInfo",
beanNameFull = "UserInfoBean"
)
public class UserBean
{
String username;
String password;
}
```

Structure names for `UserBean` will become:
`UserInfoMapper`, `UserInfoService`...

### modify template used to generate controller

bean/UserBeanTemplate.java

```java
public class UserBeanTemplate
{
public static final String TEMPLATE = """
package ##CONTROLLER_PACKAGE##;
import org.springframework.web.bind.annotation.*;
import ##BEAN_PACKAGE##.##BEAN_NAME_FULL##;
import ##MAPPER_PACKAGE##.##MAPPER_NAME##;
@RestController
@RequestMapping("/##BEAN_NAME_FULL##")
public class ##CONTROLLER_NAME## {
@RequestMapping("/test")
public String testMethod()
{
return "##TEST_METHOD_DATA##";
}
}
""";
}
```

bean/UserBean.java

```java
import firok.spring.mvci.MVCIntrospective;
import firok.spring.mvci.Param;
import lombok.Data;

@Data
@MVCIntrospective(
templateControllerContent = UserBeanTemplate.TEMPLATE,
extraParams = {
@Param(
key = "##TEST_METHOD_DATA##",
value = "test-data"
)
}
)
public class UserBean
{
String username;
String password;
}
```

Then the `UserController` will only have one method `testMethod`
with return value `"test-data"`.
148 changes: 148 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 配置生成

所有配置项都作为 `@MVCIntrospective` 注解的字段列出并提供了详细的注释.

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

预设值中的 `PREFER_XXX` 表示此值可以被上层配置值覆盖, 否则使用指定值;
`DEFAULT` 值则表示此字段强制使用 MVCI 给定的默认值 (一般是默认模板).

`@MVCIntrospective` 注解也可以 [标注在包上](#不为某个包下的实体类生成-controller),
以此快速调整某包内所有实体类的生成配置.
生成一个实体时, 会按照从子包到父包的顺序,
依次向上寻找有无 **包级** 配置注解, 最后决定每个配置字段的值.

> 希望你知道 `package-info.java` 这玩意
## 配置项

* 生成结构时的基础包路径:
`basePackage`
* 实体类名称:
`beanNameShort`, `beanNameFull`
* 是否生成某个结构:
`generate XXX`
* 生成某结构时使用的名称模板:
`template XXX Name`
* 生成某结构时使用的内容模板:
`template XXX Content`
* 生成某结构时使用的包路径模板:
`template XXX Package`
* 自定义模板替换内容:
`extraParams`

## 示例

### 不为指定类生成 service impl

bean/UserBean.java

```java
import lombok.Data;
import firok.spring.mvci.Constants;
import firok.spring.mvci.MVCIntrospective;

@Data
@MVCIntrospective(
generateServiceImpl = Constants.FALSE
)
public class UserBean
{
String username;
String password;
}
```

### 不为某个包下的实体类生成 controller

bean/package-info.java

```java
@MVCIntrospective(
generateController = Constants.FALSE
)
package firok.demo.spring.bean;

import firok.spring.mvci.Constants;
import firok.spring.mvci.MVCIntrospective;
```

### 调整为某实体类生成结构时使用的名称

bean/UserBean.java

```java
import firok.spring.mvci.MVCIntrospective;
import lombok.Data;

@Data
@MVCIntrospective(
beanNameShort = "UserInfo",
beanNameFull = "UserInfoBean"
)
public class UserBean
{
String username;
String password;
}
```

`UserBean` 生成结构的名称将变为:
`UserInfoMapper`, `UserInfoService`...

### 调整生成 controller 模板

bean/UserBeanTemplate.java

```java
public class UserBeanTemplate
{
public static final String TEMPLATE = """
package ##CONTROLLER_PACKAGE##;
import org.springframework.web.bind.annotation.*;
import ##BEAN_PACKAGE##.##BEAN_NAME_FULL##;
import ##MAPPER_PACKAGE##.##MAPPER_NAME##;
@RestController
@RequestMapping("/##BEAN_NAME_FULL##")
public class ##CONTROLLER_NAME## {
@RequestMapping("/test")
public String testMethod()
{
return "##TEST_METHOD_DATA##";
}
}
""";
}
```

bean/UserBean.java

```java
import firok.spring.mvci.MVCIntrospective;
import firok.spring.mvci.Param;
import lombok.Data;

@Data
@MVCIntrospective(
templateControllerContent = UserBeanTemplate.TEMPLATE,
extraParams = {
@Param(
key = "##TEST_METHOD_DATA##",
value = "test-data"
)
}
)
public class UserBean
{
String username;
String password;
}
```

此时生成的 `UserController` 便只包含一个 `testMethod`,
其返回值是 `"test-data"`.
Loading

0 comments on commit e075c59

Please sign in to comment.