commit
cf419fbe92
@ -0,0 +1,54 @@
|
||||
package com.luoo.cms;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
import util.IdWorker;
|
||||
import util.JwtUtil;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class CmsApplication {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CmsApplication.class);
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException {
|
||||
ConfigurableApplicationContext application = SpringApplication.run(CmsApplication.class, args);
|
||||
|
||||
Environment env = application.getEnvironment();
|
||||
|
||||
logger.info("\n----------------------------------------------------------\n\t"
|
||||
+ "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://localhost:{}\n\t"
|
||||
+ "External: \thttp://{}:{}\n\t" + "Doc: \thttp://{}:{}/doc.html\n\t"
|
||||
+ "Version: \tversion={},profiles={}\n" + "----------------------------------------------------------",
|
||||
env.getProperty("spring.application.name"), env.getProperty("server.port"),
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),
|
||||
env.getProperty("api.version"),env.getProperty("spring.profiles.active"));
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtUtil jwtUtil(){
|
||||
return new JwtUtil();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IdWorker idWorkker(){
|
||||
return new IdWorker(1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.luoo.cms.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@EnableSwagger2
|
||||
@Configuration
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment configurableEnvironment;
|
||||
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.luoo.cms"))
|
||||
.paths(PathSelectors.any())
|
||||
.build().directModelSubstitute(LocalTime.class, String.class)
|
||||
.directModelSubstitute(LocalDate.class, String.class);
|
||||
String appName = configurableEnvironment.getProperty("spring.application.name");
|
||||
if (appName != null){
|
||||
docket.pathMapping(String.format("/%s", appName));
|
||||
}
|
||||
return docket;
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfo info = new ApiInfoBuilder()
|
||||
.title("通用CMS")
|
||||
.description("通用CMS")
|
||||
.version("0.0.1")
|
||||
.contact(new Contact("通用CMS", "", ""))
|
||||
.build();
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.luoo.cms.controller;
|
||||
|
||||
|
||||
import api.Result;
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import com.luoo.cms.service.BannerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "banner轮播图")
|
||||
@RestController
|
||||
@RequestMapping("/banner")
|
||||
public class BannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerService bannerService;
|
||||
|
||||
@ApiOperation("通过id查询一个banner")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Banner> findById(@PathVariable String id){
|
||||
return Result.success(bannerService.findById(id));
|
||||
}
|
||||
|
||||
@ApiOperation("banner列表")
|
||||
@GetMapping("/list")
|
||||
public Result<List<Banner>> findById(){
|
||||
return Result.success(bannerService.bannerList());
|
||||
}
|
||||
|
||||
@ApiOperation("添加一个banner")
|
||||
@PostMapping
|
||||
public Result<Void> add(@RequestBody Banner banner){
|
||||
bannerService.add(banner);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation("通过id删除banner")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> delete(@PathVariable String id ){
|
||||
bannerService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.luoo.cms.controller;
|
||||
|
||||
|
||||
import api.Result;
|
||||
import com.luoo.cms.pojo.Agreement;
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import com.luoo.cms.service.AgreementService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Api(tags = "通用CMS")
|
||||
@RestController
|
||||
@RequestMapping("/cms")
|
||||
public class CmsController {
|
||||
|
||||
@Autowired
|
||||
private AgreementService agreementService;
|
||||
|
||||
@ApiOperation("通过key查询")
|
||||
@GetMapping("/agreement/{key}")
|
||||
public Result<Agreement> findById(@PathVariable String key){
|
||||
return Result.success(agreementService.findByKey(key));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.luoo.cms.dao;
|
||||
|
||||
import com.luoo.cms.pojo.Agreement;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface AgreementDao extends JpaRepository<Agreement,String> {
|
||||
|
||||
@Query("select a from Agreement a where a.key = ?1")
|
||||
Optional<Agreement> findByKey(String key);
|
||||
|
||||
Optional<Agreement> findByKeyAndState(@NonNull String key, int state);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.luoo.cms.dao;
|
||||
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface BannerDao extends JpaRepository<Banner,String> {
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.luoo.cms.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "tb_agreement")
|
||||
@ApiModel(value = "协议")
|
||||
public class Agreement implements Serializable {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "url别名")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private int state = 0;
|
||||
|
||||
@Column(name = "create_time")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
protected LocalDateTime createTime = LocalDateTime.now();
|
||||
|
||||
@Column(name = "update_time")
|
||||
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
protected LocalDateTime updateTime = LocalDateTime.now();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.luoo.cms.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "tb_banner")
|
||||
@ApiModel(value = "banner轮播图")
|
||||
public class Banner implements Serializable {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "图片地址")
|
||||
private String imgUrl;
|
||||
|
||||
@ApiModelProperty(value = "点击跳转地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private int state = 0;
|
||||
|
||||
@Column(name = "create_time")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
protected LocalDateTime createTime = LocalDateTime.now();
|
||||
|
||||
@Column(name = "update_time")
|
||||
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
protected LocalDateTime updateTime = LocalDateTime.now();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.luoo.cms.service;
|
||||
|
||||
import com.luoo.cms.dao.AgreementDao;
|
||||
import com.luoo.cms.pojo.Agreement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class AgreementService {
|
||||
|
||||
@Autowired
|
||||
private AgreementDao agreementDao;
|
||||
|
||||
public Agreement findByKey1(String key) {
|
||||
Agreement agreement = new Agreement();
|
||||
agreement.setKey(key);
|
||||
Example<Agreement> example = Example.of(agreement);
|
||||
return agreementDao.findOne(example).get();
|
||||
}
|
||||
|
||||
|
||||
public Agreement findByKey(String key) {
|
||||
//agreementDao.findByKeyAndState(key,0);
|
||||
return agreementDao.findByKey(key).get();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.luoo.cms.service;
|
||||
|
||||
import com.luoo.cms.dao.BannerDao;
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import util.IdWorker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class BannerService {
|
||||
|
||||
@Autowired
|
||||
private BannerDao bannerDao;
|
||||
|
||||
@Autowired
|
||||
private IdWorker idWorker;
|
||||
|
||||
public Banner findById(String id) {
|
||||
return bannerDao.findById(id).get();
|
||||
}
|
||||
|
||||
public void add(Banner banner) {
|
||||
banner.setId(idWorker.nextId()+"");
|
||||
bannerDao.save(banner);
|
||||
}
|
||||
|
||||
public void deleteById(String id) {
|
||||
bannerDao.deleteById(id);
|
||||
}
|
||||
|
||||
public List<Banner> bannerList() {
|
||||
return bannerDao.findAll();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
name: cms
|
||||
profile: dev
|
||||
label: master
|
||||
uri: http://116.62.145.60:12000
|
||||
# uri: http://127.0.0.1:12000
|
@ -0,0 +1,12 @@
|
||||
package com.luoo.user.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface GlobalInterceptor {
|
||||
boolean checkParam() default true;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.luoo.user.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.luoo.user.enums.VerifyRegexEnum;
|
||||
@Target({ElementType.PARAMETER,ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface VerifyParam {
|
||||
VerifyRegexEnum regex() default VerifyRegexEnum.NO;
|
||||
int min() default -1;
|
||||
int max() default -1;
|
||||
boolean required() default false;
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.luoo.user.aspect;
|
||||
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.luoo.user.annotation.GlobalInterceptor;
|
||||
import com.luoo.user.annotation.VerifyParam;
|
||||
import com.luoo.user.util.StringTools;
|
||||
import com.luoo.user.util.VerifyUtils;
|
||||
|
||||
import api.StatusCode;
|
||||
import exception.BizException;
|
||||
|
||||
@Aspect
|
||||
@Component("operationAspect")
|
||||
public class OperationAspect {
|
||||
static Logger logger= LoggerFactory.getLogger(OperationAspect.class);
|
||||
private static final String[] BASE_TYPE_ARRAY=new String[] {"java.lang.String","java.lang.Integer","java.lang.Long"};
|
||||
@Before("@annotation(com.luoo.user.annotation.GlobalInterceptor)")
|
||||
public void interceptorDo(JoinPoint point) {
|
||||
Object[] arguments=point.getArgs();
|
||||
Method method=((MethodSignature)point.getSignature()).getMethod();
|
||||
GlobalInterceptor interceptor=method.getAnnotation(GlobalInterceptor.class);
|
||||
if(null==interceptor) {
|
||||
return;
|
||||
}
|
||||
if(interceptor.checkParam()) {
|
||||
validateParams(method,arguments);
|
||||
}
|
||||
}
|
||||
private void validateParams(Method method, Object[] arguments) {
|
||||
Parameter[] parameters=method.getParameters();
|
||||
for(int i=0;i<parameters.length;i++) {
|
||||
Parameter parameter=parameters[i];
|
||||
Object value=arguments[i];
|
||||
VerifyParam verifyParam=parameter.getAnnotation(VerifyParam.class);
|
||||
if(null==verifyParam) {
|
||||
continue;
|
||||
}
|
||||
String paramTypeName=parameter.getParameterizedType().getTypeName();
|
||||
if(ArrayUtils.contains(BASE_TYPE_ARRAY, paramTypeName)) {
|
||||
checkValue(value,verifyParam);
|
||||
}else {
|
||||
checkObjValue(parameter,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void checkObjValue(Parameter parameter,Object value) {
|
||||
try {
|
||||
String typeName=parameter.getParameterizedType().getTypeName();
|
||||
Class<?> clazz=Class.forName(typeName);
|
||||
Field[] fields= clazz.getDeclaredFields();
|
||||
for(Field field:fields) {
|
||||
VerifyParam fieldVerifyParam=field.getAnnotation(VerifyParam.class);
|
||||
if(null==fieldVerifyParam) {
|
||||
continue;
|
||||
}
|
||||
field.setAccessible(true);
|
||||
Object resultValue=field.get(value);
|
||||
checkValue(resultValue,fieldVerifyParam);
|
||||
}
|
||||
|
||||
}catch(Exception e) {
|
||||
logger.error(StatusCode.VALIDATE_FAILED.getMessage(),e.getMessage());
|
||||
throw new BizException(StatusCode.VALIDATE_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkValue(Object value, VerifyParam verifyParam) {
|
||||
boolean isEmpty= null==value||StringTools.isEmpty(value.toString());
|
||||
int length= null==value?0:value.toString().length();
|
||||
if(isEmpty&&verifyParam.required()) {
|
||||
throw new BizException(StatusCode.VALIDATE_FAILED);
|
||||
}
|
||||
if(!isEmpty&&(-1!=verifyParam.max()&&verifyParam.max()<length||-1!=verifyParam.min()&&verifyParam.min()>length)) {
|
||||
throw new BizException(StatusCode.VALIDATE_FAILED);
|
||||
}
|
||||
if(!isEmpty&&!StringTools.isEmpty(verifyParam.regex().getRegex())&&!VerifyUtils.verify(verifyParam.regex(), String.valueOf(value))) {
|
||||
throw new BizException(StatusCode.VALIDATE_FAILED);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.luoo.user.constants;
|
||||
|
||||
public class Constants {
|
||||
public static final String IMAGE_CHECK_CODE_KEY="image_check_code_key";
|
||||
|
||||
public static final String REDIS_KEY_IMAGE_CHECK_CODE="redis_key_image_check_code_";
|
||||
public static final String REDIS_KEY_MOBILE_CHECK_CODE="redis_key_mobile_check_code_";
|
||||
}
|
@ -1,19 +1,32 @@
|
||||
package com.luoo.user.controller;
|
||||
|
||||
import exception.BizException;
|
||||
import api.Result;
|
||||
import api.StatusCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 统一异常处理类
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class BaseExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Result<Void> error(Exception e){
|
||||
e.printStackTrace();
|
||||
return Result.failed(StatusCode.USER_COMMON_FAILED);
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Result<Void> error(Exception e) {
|
||||
log.error("执行出错", e);
|
||||
return Result.failed(StatusCode.USER_COMMON_FAILED, e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = BizException.class)
|
||||
@ResponseBody
|
||||
public Result<String> error(BizException e) {
|
||||
log.info("业务错误:{}", e.getMessage());
|
||||
StatusCode statusCode = null == e.getCodeEnum() ? StatusCode.USER_COMMON_FAILED : e.getCodeEnum();
|
||||
return Result.failed(statusCode, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.luoo.user.enums;
|
||||
|
||||
public enum VerifyRegexEnum {
|
||||
NO("", "不校验"),
|
||||
MOBILE("(1[0-9])\\d{9}$", "手机号码"),
|
||||
MOBILE_CHECK_CODE("\\d{6}$", "手机短信验证号码"),
|
||||
PASSWORD("^(?=.*\\d)(?=.*[a-zA-Z])[\\da-zA-Z~!@#$%^&*_]{8,}$", "只能是数字,字母,特殊字符 8-18位");
|
||||
|
||||
private String regex;
|
||||
private String desc;
|
||||
|
||||
VerifyRegexEnum(String regex, String desc) {
|
||||
this.regex = regex;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getRegex() {
|
||||
return regex;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.luoo.user.util;
|
||||
|
||||
import com.apifan.common.random.RandomSource;
|
||||
|
||||
public class NickNameUtil {
|
||||
public static String getRandomNickName() {
|
||||
String rawNickName=RandomSource.personInfoSource().randomChineseNickName(3);
|
||||
if(rawNickName.length()>3) {
|
||||
return rawNickName.substring(0, 3);
|
||||
}
|
||||
return rawNickName;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.luoo.user.util;
|
||||
|
||||
public class StringTools {
|
||||
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
if (null == str || "".equals(str) || "null".equals(str) || "\u0000".equals(str)) {
|
||||
return true;
|
||||
} else if ("".equals(str.trim())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.luoo.user.util;
|
||||
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.luoo.user.enums.VerifyRegexEnum;
|
||||
|
||||
/**
|
||||
* @ClassName VerifyUtils
|
||||
* @Description TODO
|
||||
* @Author Administrator
|
||||
* @Date 2023/8/30 21:59
|
||||
*/
|
||||
public class VerifyUtils {
|
||||
|
||||
public static boolean verify(String regex,String value){
|
||||
if(StringTools.isEmpty(value)){
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(value);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static boolean verify(VerifyRegexEnum regexEnum,String value){
|
||||
return verify(regexEnum.getRegex(),value);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue