zoukankan      html  css  js  c++  java
  • 开源mall学习

     https://github.com/macrozheng/mall

    学习知识点

    1、Spring Security

    2、@Aspect

    3、logstash

    4、 es

    crud

    templete

    5、@Validated

    ConstraintValidator 
    BindingResult

    1、定义注解
    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.FIELD,ElementType.PARAMETER})
    @Constraint(validatedBy = FlagValidatorClass.class)
    public @interface FlagValidator {
        String[] value() default {};
    
        String message() default "flag is not found";
    
        Class<?>[] groups() default {};
    
        Class<? extends Payload>[] payload() default {};
    }
    
    
    2、定义校验器
    public class FlagValidatorClass implements ConstraintValidator<FlagValidator,Integer> {
        private String[] values;
        @Override
        public void initialize(FlagValidator flagValidator) {
            this.values = flagValidator.value();
        }
    
        @Override
        public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
            boolean isValid = false;
            if(value==null){
                //当状态为空时使用默认值
                return true;
            }
            for(int i=0;i<values.length;i++){
                if(values[i].equals(String.valueOf(value))){
                    isValid = true;
                    break;
                }
            }
            return isValid;
        }
    }
    
    
    3、model定义
    @FlagValidator(value = {"0","1"},message = "状态只能为0或1")
    private Integer showStatus;
    
    4、控制器controller
    @ApiOperation("创建商品")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public Object create(@RequestBody PmsProductParam productParam, BindingResult bindingResult) {
    int count = productService.create(productParam);
    if (count > 0) {
    return new CommonResult().success(count);
    } else {
    return new CommonResult().failed();
    }
    }

    5、错误处理 @Aspect @Component @Order(2) public class BindingResultAspect { @Pointcut("execution(public * com.macro.mall.controller.*.*(..))") public void BindingResult() { } @Around("BindingResult()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); for (Object arg : args) { if (arg instanceof BindingResult) { BindingResult result = (BindingResult) arg; if (result.hasErrors()) { return new CommonResult().validateFailed(result); } } } return joinPoint.proceed(); } }
    
    
    
    
    

    6、Swagger

    @Configuration
    @EnableSwagger2

    @ConditionalOnExpression("'${swagger.enable}' == 'true'")
    public class Swagger2Config { @Bean public Docket createRestApi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.macro.mall.search.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("mall搜索系统") .description("mall搜索模块") .contact("macro") .version("1.0") .build(); } }

    7、线程池初始化

    @Configuration
    public class ThreadConfig {
    
        @Value("${concurrent.core.size}")
        private int coreSize ;
    
        @Value("${concurrent.max.size}")
        private int maxSize ;
    
        @Value("${concurrent.blockqueue.size}")
        private int blockQueueSize;
    
    
    
        @Bean(value = "concurrentTestThread")
        public ExecutorService build(){
            ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                    .setNameFormat("concurrent-thread-%d").build();
            ThreadPoolExecutor executorServicePool = new ThreadPoolExecutor(coreSize, maxSize, 0L, TimeUnit.MILLISECONDS,
                    new ArrayBlockingQueue<Runnable>(blockQueueSize), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
    
            return executorServicePool ;
        }
    
    }


    @Resource(name = "concurrentTestThread")
    private ExecutorService executorService;
     

    ref:

    https://www.cnblogs.com/softidea/p/5991897.html

    https://www.cnblogs.com/cjsblog/p/9459781.html

  • 相关阅读:
    spring事务在web环境中失效的问题
    oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )
    查询Oracle正在执行的sql语句及kill被锁的表
    oracle last_value使用过程中的一个细节
    oracle查询历史执行语句
    前端PHP入门-020-重点日期函数之获取时期时间信息函数
    前端PHP入门-019-内置函数之数学函数-很重要
    前端PHP入门-016-静态变量
    前端PHP入门-017-系统内置函数-会查阅API
    ajax跨域调用webservice例子
  • 原文地址:https://www.cnblogs.com/huilei/p/10616382.html
Copyright © 2011-2022 走看看