1、后端自定义 数字 约束校验器
This commit is contained in:
parent
51d010bd9b
commit
a5cf6c5aea
|
|
@ -22,6 +22,7 @@
|
||||||
placeholder="请输入请求URL"
|
placeholder="请输入请求URL"
|
||||||
clearable
|
clearable
|
||||||
size="small"
|
size="small"
|
||||||
|
maxlength="100"
|
||||||
@keyup.enter.native="handleQuery"
|
@keyup.enter.native="handleQuery"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -32,6 +33,7 @@
|
||||||
placeholder="请输入请求参数"
|
placeholder="请输入请求参数"
|
||||||
clearable
|
clearable
|
||||||
size="small"
|
size="small"
|
||||||
|
maxlength="1000"
|
||||||
@keyup.enter.native="handleQuery"
|
@keyup.enter.native="handleQuery"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -42,6 +44,7 @@
|
||||||
placeholder="请输入响应参数"
|
placeholder="请输入响应参数"
|
||||||
clearable
|
clearable
|
||||||
size="small"
|
size="small"
|
||||||
|
maxlength="15000"
|
||||||
@keyup.enter.native="handleQuery"
|
@keyup.enter.native="handleQuery"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -134,7 +137,11 @@
|
||||||
<span>{{ scope.row.request !== "" ? scope.row.request : "-" }}</span>
|
<span>{{ scope.row.request !== "" ? scope.row.request : "-" }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="响应参数" align="center" prop="response" :show-overflow-tooltip="true"/>
|
<el-table-column label="响应参数" align="center" prop="response" :show-overflow-tooltip="true">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ scope.row.response !== "" ? scope.row.response : "-" }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
|
<el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
|
||||||
<el-table-column label="是否请求成功" align="center" prop="isSuccess" :show-overflow-tooltip="true">
|
<el-table-column label="是否请求成功" align="center" prop="isSuccess" :show-overflow-tooltip="true">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.xjs.validation.annotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义校验注解 :检查数字类型长度
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-18
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.xjs.validation.constraintValidator.CheckNumberConstraintValidator;
|
||||||
|
|
||||||
|
import javax.validation.Constraint;
|
||||||
|
import javax.validation.Payload;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
@Documented
|
||||||
|
@Inherited
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Constraint(validatedBy = {CheckNumberConstraintValidator.class })
|
||||||
|
public @interface CheckNumber {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述信息
|
||||||
|
* @return str
|
||||||
|
*/
|
||||||
|
String message() default "数值在指定范围之外!!!";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验数字 tip: [1,2]
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int [] num();
|
||||||
|
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.xjs.validation.constraintValidator;
|
||||||
|
|
||||||
|
import com.xjs.validation.annotation.CheckNumber;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintValidator;
|
||||||
|
import javax.validation.ConstraintValidatorContext;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字长度约束验证器
|
||||||
|
* @author xiejs
|
||||||
|
* @since 2022-02-18
|
||||||
|
*/
|
||||||
|
public class CheckNumberConstraintValidator implements ConstraintValidator<CheckNumber,Integer> {
|
||||||
|
|
||||||
|
private int[] num;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(CheckNumber constraintAnnotation) {
|
||||||
|
this.num = constraintAnnotation.num();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验
|
||||||
|
* @param value 属性值
|
||||||
|
* @param context context
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||||
|
|
||||||
|
if (Objects.nonNull(value)) {
|
||||||
|
for (int i : num) {
|
||||||
|
if (value == i) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//为空则直接过
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.xjs.validation;
|
package com.xjs.validation.group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加校验分组
|
* 添加校验分组
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.xjs.validation;
|
package com.xjs.validation.group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询校验分组
|
* 查询校验分组
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.xjs.validation;
|
package com.xjs.validation.group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改校验分组
|
* 修改校验分组
|
||||||
|
|
@ -7,9 +7,9 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||||
import com.ruoyi.common.log.annotation.Log;
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
import com.ruoyi.common.log.enums.BusinessType;
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||||
import com.xjs.validation.AddGroup;
|
import com.xjs.validation.group.AddGroup;
|
||||||
import com.xjs.validation.SelectGroup;
|
import com.xjs.validation.group.SelectGroup;
|
||||||
import com.xjs.validation.UpdateGroup;
|
import com.xjs.validation.group.UpdateGroup;
|
||||||
import com.xjs.web.MyBaseController;
|
import com.xjs.web.MyBaseController;
|
||||||
import com.xjs.word.domain.EnglishWord;
|
import com.xjs.word.domain.EnglishWord;
|
||||||
import com.xjs.word.service.IEnglishWordService;
|
import com.xjs.word.service.IEnglishWordService;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ package com.xjs.word.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
import com.xjs.validation.AddGroup;
|
import com.xjs.validation.group.AddGroup;
|
||||||
import com.xjs.validation.SelectGroup;
|
import com.xjs.validation.group.SelectGroup;
|
||||||
import com.xjs.validation.UpdateGroup;
|
import com.xjs.validation.group.UpdateGroup;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,11 @@ import com.ruoyi.common.log.enums.BusinessType;
|
||||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||||
import com.xjs.apilog.domain.ApiLog;
|
import com.xjs.apilog.domain.ApiLog;
|
||||||
import com.xjs.apilog.service.IApiLogService;
|
import com.xjs.apilog.service.IApiLogService;
|
||||||
|
import com.xjs.validation.group.SelectGroup;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
@ -37,7 +39,7 @@ public class ApiLogController extends BaseController {
|
||||||
public R<Object> saveApiLog(@RequestBody ApiLog apiLog) {
|
public R<Object> saveApiLog(@RequestBody ApiLog apiLog) {
|
||||||
|
|
||||||
boolean save = apiLogService.save(apiLog);
|
boolean save = apiLogService.save(apiLog);
|
||||||
return save?R.ok():R.fail();
|
return save ? R.ok() : R.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -58,7 +60,7 @@ public class ApiLogController extends BaseController {
|
||||||
@RequiresPermissions("log:apilog:list")
|
@RequiresPermissions("log:apilog:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("查询日志列表")
|
@ApiOperation("查询日志列表")
|
||||||
public TableDataInfo list(ApiLog apiLog) {
|
public TableDataInfo list(@Validated({SelectGroup.class}) ApiLog apiLog) {
|
||||||
startPage();
|
startPage();
|
||||||
List<ApiLog> list = apiLogService.selectApiLogList(apiLog);
|
List<ApiLog> list = apiLogService.selectApiLogList(apiLog);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,12 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
|
import com.xjs.validation.annotation.CheckNumber;
|
||||||
|
import com.xjs.validation.group.SelectGroup;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
@ -28,26 +31,32 @@ public class ApiLog implements Serializable
|
||||||
|
|
||||||
/** 接口名称 */
|
/** 接口名称 */
|
||||||
@Excel(name = "接口名称")
|
@Excel(name = "接口名称")
|
||||||
|
@Size(max = 20, message = "请控制接口名称长度在20字符", groups = { SelectGroup.class})
|
||||||
private String apiName;
|
private String apiName;
|
||||||
|
|
||||||
/** 请求API的url */
|
/** 请求API的url */
|
||||||
@Excel(name = "请求API的url")
|
@Excel(name = "请求API的url")
|
||||||
|
@Size(max = 100, message = "请控制请求API的url长度在100字符", groups = { SelectGroup.class})
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
/** 请求API的方法 */
|
/** 请求API的方法 */
|
||||||
@Excel(name = "请求API的方法")
|
@Excel(name = "请求API的方法")
|
||||||
|
@Size(max = 10, message = "请控制请求API的方法长度在10字符", groups = { SelectGroup.class})
|
||||||
private String method;
|
private String method;
|
||||||
|
|
||||||
/** 请求request */
|
/** 请求request */
|
||||||
@Excel(name = "请求request")
|
@Excel(name = "请求request")
|
||||||
|
@Size(max = 1000, message = "请控制请求request长度在1000字符", groups = { SelectGroup.class})
|
||||||
private String request;
|
private String request;
|
||||||
|
|
||||||
/** 响应体 */
|
/** 响应体 */
|
||||||
@Excel(name = "响应体")
|
@Excel(name = "响应体")
|
||||||
|
@Size(max = 15000, message = "请控制响应体长度在15000字符", groups = { SelectGroup.class})
|
||||||
private String response;
|
private String response;
|
||||||
|
|
||||||
/** 是否请求成功 */
|
/** 是否请求成功 */
|
||||||
@Excel(name = "是否请求成功",readConverterExp = "1=成功,2=失败")
|
@Excel(name = "是否请求成功",readConverterExp = "1=成功,2=失败")
|
||||||
|
@CheckNumber(num= {1, 2}, groups = { SelectGroup.class})
|
||||||
private Integer isSuccess;
|
private Integer isSuccess;
|
||||||
|
|
||||||
@Excel(name = "创建时间" ,dateFormat = "yyyy-MM-dd HH:mm:ss")
|
@Excel(name = "创建时间" ,dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public class SinaNewsTask {
|
||||||
|
|
||||||
@ReptileLog(name = "新浪新闻", url = URL)
|
@ReptileLog(name = "新浪新闻", url = URL)
|
||||||
public Long reptileSinaNews() {
|
public Long reptileSinaNews() {
|
||||||
|
Long thisCount = 0L;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String html = httpUtils.doGetHtml(URL);
|
String html = httpUtils.doGetHtml(URL);
|
||||||
|
|
@ -46,10 +47,15 @@ public class SinaNewsTask {
|
||||||
Document document = Jsoup.parse(html);
|
Document document = Jsoup.parse(html);
|
||||||
|
|
||||||
this.parse(document);
|
this.parse(document);
|
||||||
|
|
||||||
|
thisCount = count;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
//执行完初始化
|
||||||
|
this.count = 0L;
|
||||||
}
|
}
|
||||||
return count;
|
return thisCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -172,7 +178,6 @@ public class SinaNewsTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sinaNewsService.saveBatch(sinaNewsList, 30);
|
sinaNewsService.saveBatch(sinaNewsList, 30);
|
||||||
|
|
||||||
//删除重复
|
//删除重复
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue