新增邮件发送功能,统一接口数据验证,大量代码优化,更新SQL文件

This commit is contained in:
郑杰
2018-09-29 09:23:18 +08:00
parent bc40550ffc
commit 2efc1094a0
37 changed files with 1272 additions and 203 deletions
@@ -15,9 +15,7 @@ public class CommonController {
@Log("访问swagger页面")
@GetMapping(value = "/swagger/index")
public ModelAndView swagger(){
public ModelAndView swaggerIndex(){
return new ModelAndView("/system/api/index");
}
}
@@ -21,6 +21,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@@ -115,7 +116,7 @@ public class MenuController {
@Log("新增菜单")
@RequiresPermissions (value={"admin", "menu:all","menu:add"}, logical= Logical.OR)
@PostMapping(value = "/inster")
public ResponseEntity inster(@RequestBody Menu menu,@RequestParam String roles){
public ResponseEntity inster(@Validated(Menu.New.class) @RequestBody Menu menu, @RequestParam String roles){
log.warn("REST request to inster menu");
User user = (User) SecurityUtils.getSubject().getPrincipal();
Menu topMenu = null;
@@ -155,7 +156,7 @@ public class MenuController {
@Log("更新菜单")
@RequiresPermissions (value={"admin", "menu:all","menu:update"}, logical= Logical.OR)
@PutMapping(value = "/update")
public ResponseEntity update(@RequestBody Menu menu,@RequestParam String roles) {
public ResponseEntity update(@Validated(Menu.Update.class) @RequestBody Menu menu,@RequestParam String roles) {
log.warn("REST request to update");
menuService.update(menu,menuService.findById(menu.getId()),roles);
return ResponseEntity.ok();
@@ -97,7 +97,7 @@ public class PermissionController {
@Log("新增权限")
@RequiresPermissions (value={"admin", "permission:all","permission:add"}, logical= Logical.OR)
@PostMapping(value = "/inster")
public ResponseEntity inster(@RequestBody Permission permission) {
public ResponseEntity inster(@Validated(Permission.New.class) @RequestBody Permission permission) {
log.warn("REST request to insterPermission");
permissionService.inster(permission);
return ResponseEntity.ok();
@@ -131,7 +131,7 @@ public class PermissionController {
@Log("更新权限")
@RequiresPermissions (value={"admin", "permission:all","permission:update"}, logical= Logical.OR)
@PutMapping(value = "/update")
public ResponseEntity update(@RequestBody Permission permission) {
public ResponseEntity update(@Validated(Permission.New.class) @RequestBody Permission permission) {
log.warn("REST request to insterUser");
permissionService.update(permission);
return ResponseEntity.ok();
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@@ -93,7 +94,7 @@ public class RoleController {
@Log("新增角色")
@RequiresPermissions (value={"admin", "role:all","role:add"}, logical= Logical.OR)
@PostMapping(value = "/inster")
public ResponseEntity inster(@RequestBody Role role,@RequestParam String permissions) {
public ResponseEntity inster(@Validated(Role.New.class) @RequestBody Role role, @RequestParam String permissions) {
log.warn("REST request to insterRoles");
roleService.inster(role,permissions);
return ResponseEntity.ok();
@@ -128,7 +129,7 @@ public class RoleController {
@Log("更新角色")
@RequiresPermissions (value={"admin", "role:all","role:update"}, logical= Logical.OR)
@PutMapping(value = "/update")
public ResponseEntity update(@RequestBody Role role,@RequestParam String permissions) {
public ResponseEntity update(@Validated(Role.Update.class) @RequestBody Role role,@RequestParam String permissions) {
log.warn("REST request to insterUser");
roleService.update(role,permissions);
return ResponseEntity.ok();
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@@ -95,7 +96,7 @@ public class UserController {
@Log("新增用户")
@RequiresPermissions (value={"admin", "user:all","user:add"}, logical= Logical.OR)
@PostMapping(value = "/inster")
public ResponseEntity inster(@RequestBody User user, @RequestParam String roles) {
public ResponseEntity inster(@Validated(User.New.class) @RequestBody User user, @RequestParam String roles) {
log.warn("REST request to insterUser");
if(StrUtil.hasEmpty(roles)){
return ResponseEntity.error(HttpStatus.HTTP_NOT_FOUND,"角色为空,请至少为其分配一个角色");
@@ -132,7 +133,7 @@ public class UserController {
@Log("更新用户")
@RequiresPermissions (value={"admin", "user:all","user:update"}, logical= Logical.OR)
@PutMapping(value = "/update")
public ResponseEntity update(@RequestBody User user, @RequestParam String roles) {
public ResponseEntity update(@Validated(User.Update.class) @RequestBody User user, @RequestParam String roles) {
log.warn("REST request to insterUser");
if(StrUtil.hasEmpty(roles)){
return ResponseEntity.error(HttpStatus.HTTP_NOT_FOUND,"角色为空,请至少为其分配一个角色");
@@ -0,0 +1,48 @@
package me.aurora.app.rest.utils;
import me.aurora.annotation.Log;
import me.aurora.domain.ResponseEntity;
import me.aurora.domain.utils.EmailConfig;
import me.aurora.domain.vo.EmailVo;
import me.aurora.service.EmailService;
import me.aurora.util.HttpContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
/**
* 发送邮件
* @author 郑杰
* @date 2018/09/28 6:55:53
*/
@RestController
@RequestMapping("email")
public class EmailController {
@Autowired
private EmailService emailService;
@GetMapping(value = "/index")
public ModelAndView emailIndex(){
EmailConfig emailConfig = emailService.findById(1L);
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
request.setAttribute("email",emailConfig);
return new ModelAndView("/utils/email/index");
}
@Log("配置邮件")
@PostMapping(value = "/config")
public ResponseEntity emailConfig(@RequestBody @Validated(EmailConfig.Update.class) EmailConfig emailConfig){
emailService.updateConfig(emailConfig);
return ResponseEntity.ok();
}
@Log("发送邮件")
@PostMapping(value = "send")
public ResponseEntity send(@Validated(EmailVo.New.class) @RequestBody EmailVo emailVo) throws Exception {
emailService.send(emailVo,emailService.findById(1L));
return ResponseEntity.ok();
}
}
@@ -40,7 +40,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity handleException(Exception e){
log.error(e.getMessage());
return ResponseEntity.error("操作失败!");
return ResponseEntity.error(e.getMessage());
}
/**
@@ -62,6 +62,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e){
log.error(e.getMessage());
return ResponseEntity.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
String str[] = e.getBindingResult().getAllErrors().get(0).getCodes()[1].split("\\.");
StringBuffer msg = new StringBuffer(str[1]+":");
msg.append(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
return ResponseEntity.error(msg.toString());
}
}
@@ -6,7 +6,7 @@ import me.aurora.domain.Role;
import me.aurora.domain.User;
import me.aurora.service.PermissionService;
import me.aurora.service.UserService;
import me.aurora.util.EmailUtil;
import me.aurora.util.ValidationUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
@@ -67,7 +67,7 @@ public class ShiroRealm extends AuthorizingRealm {
String password = new String((char[]) token.getCredentials());
log.warn("=====>>>>>用户" + username + "认证");
User user = null;
if(EmailUtil.isEmail(username)){
if(ValidationUtil.isEmail(username)){
user = userService.findByEmail(username);
} else {
user = userService.findByUsername(username);
+5 -3
View File
@@ -40,21 +40,18 @@ public class Menu implements Serializable {
* 上级菜单ID
*/
@Column(name = "pid",nullable = false)
@NotBlank(groups = {New.class,Update.class})
private Integer pid;
/**
* 菜单类目
*/
@Column(nullable = false)
@NotBlank(groups = {New.class,Update.class})
private Integer level;
/**
* 子菜单数量
*/
@Column(name = "level_number",nullable = false)
@NotBlank(groups = {New.class,Update.class})
private Integer levelNum = 0;
/**
@@ -62,6 +59,11 @@ public class Menu implements Serializable {
*/
private Boolean iframe = false;
/**
* 系统菜单
*/
private Boolean sys = false;
@ManyToMany
@JoinTable(name = "zj_menus_roles", joinColumns = {@JoinColumn(name = "menu_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")})
private Set<Role> roles;
@@ -36,9 +36,10 @@ public class Permission implements Serializable{
* 上级类目
*/
@Column(name = "pid",nullable = false)
@NotBlank(groups = {New.class,Update.class})
private Integer pid;
@NotBlank(groups = {New.class,Update.class})
@Column(nullable = false)
private String remark;
@JsonIgnore
+2 -1
View File
@@ -31,6 +31,8 @@ public class User implements Serializable {
@NotBlank(groups = {New.class,Update.class})
private String username;
@NotBlank(groups = {New.class,Update.class})
@Column(nullable = false)
private String password;
@NotBlank(groups = {New.class,Update.class})
@@ -39,7 +41,6 @@ public class User implements Serializable {
private Integer enabled=1;
@NotBlank(groups = {New.class,Update.class})
@Column(nullable = false)
private String avatar;
@@ -0,0 +1,50 @@
package me.aurora.domain.utils;
import lombok.Data;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* 邮件配置类,数据存覆盖式存入数据存
*/
@Entity
@Data
@Table(name = "zj_email_config")
public class EmailConfig implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
*邮件服务器SMTP地址
*/
@NotBlank(groups = Update.class)
private String host;
/**
* 邮件服务器SMTP端口
*/
@NotBlank(groups = Update.class)
private String port;
@NotBlank(groups = Update.class)
private String user;
@NotBlank(groups = Update.class)
private String pass;
/**
* 发件人
*/
@NotBlank(groups = Update.class)
private String fromUser;
/**
* 是否开启ssl
*/
private Boolean sslEnable;
public interface Update {}
}
@@ -0,0 +1,43 @@
package me.aurora.domain.vo;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
/**
* 发送邮件时,接收参数的类
* @author 郑杰
* @date 2018/09/28 12:02:14
*/
@Data
public class EmailVo {
/**
* 收件人,支持多个收件人,用逗号分隔
*/
@NotBlank(groups = New.class)
private String tos;
@NotBlank(groups = New.class)
private String subject;
@NotBlank(groups = New.class)
private String content;
/**
* 是否为html,默认为true
*/
private Boolean isHtml = true;
public ArrayList<String> getTos() {
String str[] = this.tos.split("[,,;;]");
ArrayList<String> list = new ArrayList<>();
for (String s : str) {
list.add(s);
}
return list;
}
public interface New {}
}
@@ -0,0 +1,11 @@
package me.aurora.repository;
import me.aurora.domain.utils.EmailConfig;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @author 郑杰
* @date 2018/09/28 7:12:43
*/
public interface EmailRepo extends JpaRepository<EmailConfig,Long> {
}
@@ -0,0 +1,37 @@
package me.aurora.service;
import me.aurora.domain.utils.EmailConfig;
import me.aurora.domain.vo.EmailVo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
/**
* @author 郑杰
* @date 2018/09/28 7:11:23
*/
@CacheConfig(cacheNames = "email")
public interface EmailService {
/**
* 更新邮件配置
* @param emailConfig
*/
@CacheEvict(allEntries = true)
EmailConfig updateConfig(EmailConfig emailConfig);
/**
* 根据ID查询配置
* @param id
* @return
*/
@Cacheable(key = "#p0")
EmailConfig findById(Long id);
/**
* 发送邮件
* @param emailVo
* @param emailConfig
*/
void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception;
}
@@ -0,0 +1,78 @@
package me.aurora.service.impl;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import cn.hutool.http.HttpStatus;
import me.aurora.config.exception.AuroraException;
import me.aurora.domain.utils.EmailConfig;
import me.aurora.domain.vo.EmailVo;
import me.aurora.repository.EmailRepo;
import me.aurora.service.EmailService;
import me.aurora.util.EncryptHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author 郑杰
* @date 2018/09/28 7:11:56
*/
@Service
public class EmailServiceImpl implements EmailService {
@Autowired
private EmailRepo emailRepo;
@Override
public EmailConfig updateConfig(EmailConfig emailConfig) {
emailConfig.setId(1L);
try {
emailConfig.setPass(EncryptHelper.desEncrypt(emailConfig.getPass()));
} catch (Exception e) {
e.printStackTrace();
}
emailRepo.saveAndFlush(emailConfig);
return emailConfig;
}
@Override
public EmailConfig findById(Long id) {
EmailConfig emailConfig = emailRepo.findById(id).get();
return emailConfig;
}
@Override
public void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception {
/**
* 封装
*/
MailAccount account = new MailAccount();
account.setHost(emailConfig.getHost());
account.setPort(Integer.parseInt(emailConfig.getPort()));
account.setAuth(true);
account.setPass(EncryptHelper.desDecrypt(emailConfig.getPass()));
/**
* 判断是否为ssl形式发送
*/
if(emailConfig.getSslEnable()){
account.setFrom(emailConfig.getUser()+"<"+emailConfig.getFromUser()+">");
} else {
account.setFrom(emailConfig.getFromUser());
account.setUser(emailConfig.getUser());
}
//是否ssl方式发送
account.setStartttlsEnable(emailConfig.getSslEnable());
/**
* 发送
*/
try {
MailUtil.send(account,
emailVo.getTos(),
emailVo.getSubject(),
emailVo.getContent(),
emailVo.getIsHtml());
}catch (Exception e){
throw new AuroraException(HttpStatus.HTTP_INTERNAL_ERROR,e.getMessage());
}
}
}
@@ -107,6 +107,9 @@ public class MenuServiceImpl implements MenuService {
@Override
@Transactional(rollbackFor = Throwable.class)
public void delete(Menu menu) {
if(menu.getSys()){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"系统菜单,不可删除");
}
if(menu.getLevelNum() == 0){
try {
Optional<Menu> optionalMenu = menuRepo.findById(menu.getPid().longValue());
@@ -42,9 +42,6 @@ public class PermissionServiceImpl implements PermissionService {
@Override
public void inster(Permission permission) throws AuroraException {
if(StrUtil.hasEmpty(permission.getPerms())){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"权限名称不能为空");
}
if(permissionRepo.findByPerms(permission.getPerms())!=null){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"权限已存在");
}
@@ -63,9 +60,6 @@ public class PermissionServiceImpl implements PermissionService {
if(null == permission.getId()){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"权限ID不能为空");
}
if(StrUtil.isEmpty(permission.getPerms())){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"权限名称不能为空");
}
Permission old = permissionRepo.findByPerms(permission.getPerms());
if(old !=null && !old.getId().equals(permission.getId())){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"权限已存在");
@@ -59,9 +59,6 @@ public class RoleServiceImpl implements RoleService {
@Override
public void inster(Role role, String permissions) {
if(StrUtil.hasEmpty(role.getName())){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"角色名称不能为空");
}
if(roleRepo.findByName(role.getName())!=null){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"角色已存在");
}
@@ -81,9 +78,6 @@ public class RoleServiceImpl implements RoleService {
if(role.getId() == null){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"角色ID不能为空");
}
if(StrUtil.hasEmpty(role.getName())){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"角色名称不能为空");
}
Role old = roleRepo.findByName(role.getName());
if(old!=null && !role.getId().equals(old.getId())){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"角色已存在");
@@ -74,6 +74,9 @@ public class SysLogServiceImpl implements SysLogService {
}
params += " " + paramNames[i] + ": " + args[i];
}
if (params.length() > 255){
params = params.substring(0,254);
}
sysLog.setParams(params);
}
// 获取request
@@ -73,20 +73,13 @@ public class UserServiceImpl implements UserService {
@Override
public void inster(User user, String roles) {
if(StrUtil.hasEmpty(user.getUsername())||StrUtil.hasEmpty(user.getEmail())){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"请检查是否提交了空的内容");
}
if(userRepo.findByUsername(user.getUsername())!=null){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"用户名已存在");
}
if(userRepo.findByEmail(user.getEmail())!=null){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"用户邮箱已存在");
}
if(!StrUtil.hasEmpty(user.getPassword())){
user.setPassword(MD5Utils.encrypt(user.getPassword()));
} else {
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"用户密码不能为空");
}
user.setPassword(MD5Utils.encrypt(user.getPassword()));
Set<Role> roleSet = new HashSet<>();
for(String roleId:roles.split(",")){
Role role = new Role();
@@ -100,9 +93,6 @@ public class UserServiceImpl implements UserService {
@Override
public void update(User user, String roles) {
if(StrUtil.hasEmpty(user.getUsername())||StrUtil.hasEmpty(user.getEmail())){
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,"请检查是否提交了空的内容");
}
User old = userRepo.findByUsername(user.getUsername());
if(old!=null&&!old.getId().equals(user.getId())){
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"用户名已存在");
@@ -112,10 +102,7 @@ public class UserServiceImpl implements UserService {
throw new AuroraException(HttpStatus.HTTP_BAD_REQUEST,"用户邮箱已存在");
}
old = userRepo.findById(user.getId()).get();
if(!StrUtil.hasEmpty(user.getPassword())){
old.setPassword(MD5Utils.encrypt(user.getPassword()));
}
old.setPassword(MD5Utils.encrypt(user.getPassword()));
old.setUsername(user.getUsername());
old.setEmail(user.getEmail());
@@ -1,19 +0,0 @@
package me.aurora.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author 郑杰
* @date 2018/08/23 11:54:10
*/
public class EmailUtil {
public static boolean isEmail(String string) {
if (string == null){
return false;
}
String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
return string.matches(regEx1);
}
}
@@ -0,0 +1,90 @@
package me.aurora.util;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
/**
* @date 2017/10/26.
* Github Breakeval13
* @author blog firsh.me
*/
public class EncryptHelper {
private static String strKey = "Passw0rd", strParam = "Passw0rd";
public static String desEncrypt(String source) throws Exception {
if (source == null || source.length() == 0){
return null;
}
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(strKey.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(strParam.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
return byte2hex(
cipher.doFinal(source.getBytes("UTF-8"))).toUpperCase();
}
public static String byte2hex(byte[] inStr) {
String stmp;
StringBuffer out = new StringBuffer(inStr.length * 2);
for (int n = 0; n < inStr.length; n++) {
stmp = Integer.toHexString(inStr[n] & 0xFF);
if (stmp.length() == 1) {
// 如果是0至F的单位字符串,则添加0
out.append("0" + stmp);
} else {
out.append(stmp);
}
}
return out.toString();
}
public static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0){
throw new IllegalArgumentException("长度不是偶数");
}
byte[] b2 = new byte[b.length / 2];
for (int n = 0; n < b.length; n += 2) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}
public static String desDecrypt(String source) throws Exception {
if (source == null || source.length() == 0){
return null;
}
byte[] src = hex2byte(source.getBytes());
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(strKey.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(strParam.getBytes("UTF-8"));
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] retByte = cipher.doFinal(src);
return new String(retByte);
}
public static String formatKey(String key){
// 固定长度
int length=8;
// 自动补位
return key+String.format("%1$0"+(length-key.length())+"d",0);
}
public static void main(String[] args) throws Exception {
System.out.println(EncryptHelper.desDecrypt("53c8927a4dd1e9b6f44c9d53af92c794"));
System.out.println(EncryptHelper.desEncrypt("Hello World!"));
}
}
@@ -20,4 +20,17 @@ public class ValidationUtil {
throw new AuroraException(HttpStatus.HTTP_NOT_FOUND,msg);
}
}
/**
* 验证是否为邮箱
* @param string
* @return
*/
public static boolean isEmail(String string) {
if (string == null){
return false;
}
String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
return string.matches(regEx1);
}
}