common-netty

project auto plugins

License

License

Categories

Categories

Net Netty Networking
GroupId

GroupId

top.wboost
ArtifactId

ArtifactId

common-netty
Last Version

Last Version

3.2.1.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

common-netty
project auto plugins

Download common-netty

How to add to project

<!-- https://jarcasting.com/artifacts/top.wboost/common-netty/ -->
<dependency>
    <groupId>top.wboost</groupId>
    <artifactId>common-netty</artifactId>
    <version>3.2.1.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/top.wboost/common-netty/
implementation 'top.wboost:common-netty:3.2.1.RELEASE'
// https://jarcasting.com/artifacts/top.wboost/common-netty/
implementation ("top.wboost:common-netty:3.2.1.RELEASE")
'top.wboost:common-netty:jar:3.2.1.RELEASE'
<dependency org="top.wboost" name="common-netty" rev="3.2.1.RELEASE">
  <artifact name="common-netty" type="jar" />
</dependency>
@Grapes(
@Grab(group='top.wboost', module='common-netty', version='3.2.1.RELEASE')
)
libraryDependencies += "top.wboost" % "common-netty" % "3.2.1.RELEASE"
[top.wboost/common-netty "3.2.1.RELEASE"]

Dependencies

compile (2)

Group / Artifact Type Version
top.wboost : common-base jar 3.2.1.RELEASE
io.netty : netty-all jar 4.1.33.Final

Project Modules

There are no modules declared in this project.

QUICK DEV SUPPORT

Home Page | 官方主页 | 中文说明 | 文档手册

Packagist

Packagist Packagist Packagist

引入说明


传统web架构项目与springboot项目切换

<properties>
<tools-group-id>top.wboost</tools-group-id>
<tools-group-version>3.1.9-SNAPSHOT</tools-group-version>
</properties>
根据项目类型引入
  • 传统web
<dependency>
    <groupId>${tools-group-id}</groupId>
    <version>${tools-group-version}</version>
    <artifactId>common-boost</artifactId>
</dependency>
  • springboot
<dependency>
    <groupId>${tools-group-id}</groupId>
    <version>${tools-group-version}</version>
    <artifactId>common-boot</artifactId>
</dependency>

boot项目自动扫描top.wboost.common,com.chinaoly及SpringApplication类下目录


统一参数验证机制,可复用,自由规则

默认提供@NotNull(不能为空)与@NotEmpty(不能为空且不能为空字符串)注解

  • 新建校验注解文件LowerThan,注解上增加@top.wboost.common.annotation.parameter.ParameterConfig
// Integer、Long小于指定数据校验实例
@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ParameterConfig
public @interface LowerThan {
    int value();
}
  • 新建校验器LowerThanChecker类,并注入ioc(@AutoWebApplicationConfig),且实现top.wboost.common.annotation.parameter.ParameterConfigChecker接口
@AutoWebApplicationConfig
public class LowerThanChecker implements ParameterConfigChecker {

    @Override
    public Boolean check(Object source, Object... argName) {
        return true;
    }

    private void throwException(String argName, int big) {
        SystemCodeException e = new SystemCodeException(SystemCode.PROMPT);
        e.setPromptMessage(argName + "参数值不能大于" + big);
        throw e;
    }

    // 验证方法 source:参数 annotation:注解 args: 参数名
    @Override
    public Boolean check(Object source, Annotation annotation, Object... args) {
        LowerThan lowerThan = (LowerThan) annotation;
        if (source instanceof Integer) {
            int param = (int) source;
            if (param > lowerThan.value()) {
                throwException(args[0].toString(), lowerThan.value());
            }
        }
        return true;
    }

    //校验器对应注解
    @Override
    public Class<? extends Annotation> getAnnotation() {
        return LowerThan.class;
    }

}
  • 使用
@GetMapping("/example")
@Explain(systemCode = SystemCode.DO_FAIL, value = "example")
public ResultEntity callTimeResult(
        @ApiParam(required = true, value = "演示参数不为空且小于指定数字") @NotNull @LowerThan(20) Integer segmentNum) {
    return ResultEntity.success(SystemCode.DO_OK).setData(segmentNum).build();
}
  • 返回数据
curl localhost:8080/example
{"info":{"code":10902,"message":"segmentNum 为空"},"status":1}
curl localhost:8080/example?segmentNum=21
{"info":{"code":10913,"message":"segmentNum参数值不能大于20","systemCode":"PROMPT"},"status":1}
curl localhost:8080/example?segmentNum=10
{"data":10,"info":{"code":10906,"message":"执行成功","systemCode":"DO_OK"},"status":0}

待续.

Versions

Version
3.2.1.RELEASE
3.2.0.RELEASE
3.1.9.RELEASE
3.1.8.RELEASE
3.1.7.RELEASE
3.1.6.RELEASE
3.1.4.RELEASE
3.1.3.RELEASE
3.1.2.RELEASE