From 09f15cb8262a650d2681be1153f5715aa297e1cb Mon Sep 17 00:00:00 2001 From: springboot-plus Date: Sat, 5 Oct 2019 18:01:05 +0800 Subject: [PATCH] :cn: 1.3.0.RELEASE shiro+jwt --- .../common/entity/BaseEntity.java | 1 + .../cache/impl/LoginRedisServiceImpl.java | 3 +- .../shiro/convert/ShiroMapstructConvert.java | 10 --- .../springbootplus/shiro/jwt/JwtRealm.java | 2 +- .../shiro/service/impl/LoginServiceImpl.java | 35 ++++++--- .../springbootplus/shiro/util/SaltUtil.java | 13 ++++ .../system/convert/SysUserConvert.java | 46 ++++++++++++ .../springbootplus/system/entity/SysLog.java | 9 +-- .../springbootplus/system/entity/SysUser.java | 32 +++++---- .../system/mapper/SysLogMapper.java | 8 ++- .../system/mapper/SysUserMapper.java | 17 ++++- .../system/service/SysLogService.java | 8 ++- .../system/service/SysUserService.java | 8 ++- .../service/impl/SysLogServiceImpl.java | 14 ++-- .../service/impl/SysUserServiceImpl.java | 14 ++-- .../web/controller/SysLogController.java | 63 ++++++++-------- .../web/controller/SysUserController.java | 65 ++++++++--------- .../system/web/param/SysLogQueryParam.java | 6 +- .../system/web/param/SysUserQueryParam.java | 6 +- .../system/web/vo/SysLogQueryVo.java | 8 ++- .../system/web/vo/SysUserQueryVo.java | 33 +++++---- .../springbootplus/util/PasswordUtil.java | 23 +++--- src/main/resources/config/application.yml | 3 +- .../resources/mapper/system/SysLogMapper.xml | 8 ++- .../resources/mapper/system/SysUserMapper.xml | 17 ++++- .../springbootplus/test/CodeGenerator.java | 71 +++++++++++-------- .../springbootplus/test/PasswordUtilTest.java | 30 ++++++++ .../springbootplus/test/SaltUtilTest.java | 28 ++++++++ .../resources/templates/controller.java.vm | 40 +++++------ src/test/resources/templates/entity.java.vm | 8 +-- src/test/resources/templates/mapper.java.vm | 2 + src/test/resources/templates/mapper.xml.vm | 8 ++- .../resources/templates/queryParam.java.vm | 6 +- src/test/resources/templates/queryVo.java.vm | 8 ++- src/test/resources/templates/service.java.vm | 2 + .../resources/templates/serviceImpl.java.vm | 8 +-- 36 files changed, 432 insertions(+), 231 deletions(-) create mode 100644 src/main/java/io/geekidea/springbootplus/system/convert/SysUserConvert.java create mode 100644 src/test/java/io/geekidea/springbootplus/test/PasswordUtilTest.java create mode 100644 src/test/java/io/geekidea/springbootplus/test/SaltUtilTest.java diff --git a/src/main/java/io/geekidea/springbootplus/common/entity/BaseEntity.java b/src/main/java/io/geekidea/springbootplus/common/entity/BaseEntity.java index 96efc84f..b3b47335 100644 --- a/src/main/java/io/geekidea/springbootplus/common/entity/BaseEntity.java +++ b/src/main/java/io/geekidea/springbootplus/common/entity/BaseEntity.java @@ -21,6 +21,7 @@ import java.io.Serializable; /** + * 实体父类 * @author geekidea * @date 2018-11-08 */ diff --git a/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java b/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java index c38f5bbb..40e013dd 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/cache/impl/LoginRedisServiceImpl.java @@ -22,6 +22,7 @@ import io.geekidea.springbootplus.shiro.vo.JwtTokenRedisVo; import io.geekidea.springbootplus.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.shiro.vo.LoginSysUserVo; +import io.geekidea.springbootplus.system.convert.SysUserConvert; import io.geekidea.springbootplus.util.ClientInfoUtil; import io.geekidea.springbootplus.util.HttpServletRequestUtil; import org.apache.commons.codec.digest.DigestUtils; @@ -84,7 +85,7 @@ public void cacheLoginInfo(JwtToken jwtToken, LoginSysUserVo loginSysUserVo, boo // Redis缓存登陆用户信息 // 将LoginSysUserVo对象复制到LoginSysUserRedisVo,使用mapstruct进行对象属性复制 - LoginSysUserRedisVo loginSysUserRedisVo = ShiroMapstructConvert.INSTANCE.loginSysUserVoToLoginSysUserRedisVo(loginSysUserVo); + LoginSysUserRedisVo loginSysUserRedisVo = SysUserConvert.INSTANCE.loginSysUserVoToLoginSysUserRedisVo(loginSysUserVo); loginSysUserRedisVo.setSalt(salt); loginSysUserRedisVo.setClientInfo(clientInfo); diff --git a/src/main/java/io/geekidea/springbootplus/shiro/convert/ShiroMapstructConvert.java b/src/main/java/io/geekidea/springbootplus/shiro/convert/ShiroMapstructConvert.java index aa161dae..a498889e 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/convert/ShiroMapstructConvert.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/convert/ShiroMapstructConvert.java @@ -15,8 +15,6 @@ import io.geekidea.springbootplus.shiro.jwt.JwtToken; import io.geekidea.springbootplus.shiro.vo.JwtTokenRedisVo; -import io.geekidea.springbootplus.shiro.vo.LoginSysUserRedisVo; -import io.geekidea.springbootplus.shiro.vo.LoginSysUserVo; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -32,14 +30,6 @@ public interface ShiroMapstructConvert { ShiroMapstructConvert INSTANCE = Mappers.getMapper(ShiroMapstructConvert.class); - /** - * LoginSysUserVo对象转换成LoginSysUserRedisVo - * - * @param loginSysUserVo - * @return - */ - LoginSysUserRedisVo loginSysUserVoToLoginSysUserRedisVo(LoginSysUserVo loginSysUserVo); - /** * JwtToken对象转换成JwtTokenRedisVo * diff --git a/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java b/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java index 64c33e68..4a7f8686 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/jwt/JwtRealm.java @@ -28,7 +28,7 @@ import org.apache.shiro.subject.PrincipalCollection; /** - * Shiro JST授权认证 + * Shiro 授权认证 * * @author geekidea * @date 2019-09-27 diff --git a/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java b/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java index eb181c92..d7493802 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/service/impl/LoginServiceImpl.java @@ -30,6 +30,10 @@ import io.geekidea.springbootplus.shiro.util.SaltUtil; import io.geekidea.springbootplus.shiro.vo.LoginSysUserRedisVo; import io.geekidea.springbootplus.shiro.vo.LoginSysUserVo; +import io.geekidea.springbootplus.system.convert.SysUserConvert; +import io.geekidea.springbootplus.system.entity.SysUser; +import io.geekidea.springbootplus.system.mapper.SysUserMapper; +import io.geekidea.springbootplus.util.PasswordUtil; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.SetUtils; @@ -67,25 +71,36 @@ public class LoginServiceImpl implements LoginService { @Autowired private JwtProperties jwtProperties; + @Autowired + private SysUserMapper sysUserMapper; + @Override public ApiResult login(LoginParam loginParam, HttpServletResponse response) { String username = loginParam.getUsername(); - // TODO 从数据库中获取登陆用户信息 - LoginSysUserVo loginSysUserVo = new LoginSysUserVo() - .setId(1L) - .setUsername(loginParam.getUsername()) - .setSalt("666") // 可选 - .setRoles(SetUtils.hashSet("admin")); - - if (loginSysUserVo == null) { + // 从数据库中获取登陆用户信息 + SysUser sysUser = sysUserMapper.getSysUserByUsername(username); + if (sysUser == null) { log.error("登陆失败,loginParam:{}", loginParam); return ApiResult.fail(ApiCode.LOGIN_EXCEPTION); } + // 实际项目中,前端传过来的密码应先加密 + // 原始密码:123456 + // 加密规则:sha256(666666+123456) = 751ade2f90ceb660cb2460f12cc6fe08268e628e4607bdb88a00605b3d66973c + String encryptPassword = PasswordUtil.encrypt(loginParam.getPassword()); + if (!encryptPassword.equals(sysUser.getPassword())) { + log.error("用户名或密码错误"); + return ApiResult.fail(ApiCode.LOGIN_EXCEPTION); + } + // 将系统用户对象转换成登陆用户对象 + LoginSysUserVo loginSysUserVo = SysUserConvert.INSTANCE.sysUserToLoginSysUserVo(sysUser); + // TODO 从数据库中获取登陆用户角色权限信息 + loginSysUserVo.setRoles(SetUtils.hashSet("admin")); + String newSalt; - if (jwtProperties.isSaltCheck()){ + if (jwtProperties.isSaltCheck()) { // 包装盐值 newSalt = SaltUtil.getSalt(jwtProperties.getSecret(), loginSysUserVo.getSalt()); - }else{ + } else { newSalt = jwtProperties.getSecret(); } // 删除登陆用户盐值,盐值保存到后台Redis缓存中 diff --git a/src/main/java/io/geekidea/springbootplus/shiro/util/SaltUtil.java b/src/main/java/io/geekidea/springbootplus/shiro/util/SaltUtil.java index 6fcc0bd5..d9478b6c 100644 --- a/src/main/java/io/geekidea/springbootplus/shiro/util/SaltUtil.java +++ b/src/main/java/io/geekidea/springbootplus/shiro/util/SaltUtil.java @@ -14,7 +14,9 @@ package io.geekidea.springbootplus.shiro.util; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.crypto.SecureRandomNumberGenerator; /** * 盐值包装工具类 @@ -40,4 +42,15 @@ public static String getSalt(String secret, String salt) { String newSalt = DigestUtils.sha256Hex(secret + salt); return newSalt; } + + /** + * 生成32位随机盐 + * + * @return + */ + public static String generateSalt() { + return new SecureRandomNumberGenerator().nextBytes(16).toHex(); + } + } + diff --git a/src/main/java/io/geekidea/springbootplus/system/convert/SysUserConvert.java b/src/main/java/io/geekidea/springbootplus/system/convert/SysUserConvert.java new file mode 100644 index 00000000..820cb331 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/convert/SysUserConvert.java @@ -0,0 +1,46 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.system.convert; + +import io.geekidea.springbootplus.shiro.vo.LoginSysUserRedisVo; +import io.geekidea.springbootplus.shiro.vo.LoginSysUserVo; +import io.geekidea.springbootplus.system.entity.SysUser; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author geekidea + * @date 2019-10-05 + **/ +@Mapper +public interface SysUserConvert { + + SysUserConvert INSTANCE = Mappers.getMapper(SysUserConvert.class); + + /** + * 系统用户实体对象转换成登陆用户VO对象 + * @param sysUser + * @return + */ + LoginSysUserVo sysUserToLoginSysUserVo(SysUser sysUser); + + /** + * LoginSysUserVo对象转换成LoginSysUserRedisVo + * + * @param loginSysUserVo + * @return + */ + LoginSysUserRedisVo loginSysUserVoToLoginSysUserRedisVo(LoginSysUserVo loginSysUserVo); + +} diff --git a/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java b/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java index 3279f6f9..53182b81 100644 --- a/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java +++ b/src/main/java/io/geekidea/springbootplus/system/entity/SysLog.java @@ -1,14 +1,14 @@ package io.geekidea.springbootplus.system.entity; import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; import com.baomidou.mybatisplus.annotation.TableId; import io.geekidea.springbootplus.common.entity.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; - -import java.util.Date; +import lombok.experimental.Accessors; /** *

@@ -16,11 +16,12 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-05 */ @Data +@Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -@ApiModel(value="SysLog对象", description="系统日志") +@ApiModel(value = "SysLog对象", description = "系统日志") public class SysLog extends BaseEntity { private static final long serialVersionUID = 1L; diff --git a/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java b/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java index 6e411c64..3a8d100c 100644 --- a/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java +++ b/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java @@ -8,8 +8,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; - -import java.util.Date; +import lombok.experimental.Accessors; /** *

@@ -17,35 +16,42 @@ *

* * @author geekidea - * @since 2019-08-26 + * @since 2019-10-05 */ @Data +@Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -@ApiModel(value="SysUser对象", description="SystemUser") +@ApiModel(value = "SysUser对象", description = "SystemUser") public class SysUser extends BaseEntity { private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "id") + @ApiModelProperty(value = "主键") @TableId(value = "id", type = IdType.ID_WORKER) private Long id; - @ApiModelProperty(value = "name") - private String name; + @ApiModelProperty(value = "用户名") + private String username; - @ApiModelProperty(value = "account") - private String account; + @ApiModelProperty(value = "昵称") + private String nickname; - @ApiModelProperty(value = "password") - private String pwd; + @ApiModelProperty(value = "密码") + private String password; + + @ApiModelProperty(value = "盐值") + private String salt; @ApiModelProperty(value = "remark") private String remark; - @ApiModelProperty(value = "create time") + @ApiModelProperty(value = "状态,0:禁用,1:启用") + private Integer status; + + @ApiModelProperty(value = "创建时间") private Date createTime; - @ApiModelProperty(value = "update time") + @ApiModelProperty(value = "修改时间") private Date updateTime; } diff --git a/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java b/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java index 4b3e6810..6ce40336 100644 --- a/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java +++ b/src/main/java/io/geekidea/springbootplus/system/mapper/SysLogMapper.java @@ -17,13 +17,14 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-05 */ @Repository public interface SysLogMapper extends BaseMapper { /** * 根据ID获取查询对象 + * * @param id * @return */ @@ -31,10 +32,11 @@ public interface SysLogMapper extends BaseMapper { /** * 获取分页对象 + * * @param page - * @param sysLogQueryParam + * @param SysLogQueryParam * @return */ - IPage getSysLogPageList(@Param("page") Page page, @Param("param") SysLogQueryParam sysLogQueryParam); + IPage getSysLogPageList(@Param("page") Page page, @Param("param") SysLogQueryParam SysLogQueryParam); } diff --git a/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java b/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java index 42cce5ba..f8d94f2d 100644 --- a/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java +++ b/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.geekidea.springbootplus.shiro.vo.LoginSysUserVo; import io.geekidea.springbootplus.system.entity.SysUser; import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; @@ -17,13 +18,14 @@ *

* * @author geekidea - * @since 2019-08-26 + * @since 2019-10-05 */ @Repository public interface SysUserMapper extends BaseMapper { /** * 根据ID获取查询对象 + * * @param id * @return */ @@ -31,10 +33,19 @@ public interface SysUserMapper extends BaseMapper { /** * 获取分页对象 + * * @param page - * @param sysUserQueryParam + * @param SysUserQueryParam * @return */ - IPage getSysUserPageList(@Param("page") Page page, @Param("param") SysUserQueryParam sysUserQueryParam); + IPage getSysUserPageList(@Param("page") Page page, @Param("param") SysUserQueryParam SysUserQueryParam); + + /** + * 根据用户名获取用户信息 + * + * @param username + * @return + */ + SysUser getSysUserByUsername(String username); } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java b/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java index 1faad51d..4de04280 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/SysLogService.java @@ -14,12 +14,13 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-05 */ public interface SysLogService extends BaseService { /** * 根据ID获取查询对象 + * * @param id * @return */ @@ -27,9 +28,10 @@ public interface SysLogService extends BaseService { /** * 获取分页对象 - * @param sysLogQueryParam + * + * @param SysLogQueryParam * @return */ - Paging getSysLogPageList(SysLogQueryParam sysLogQueryParam) throws Exception; + Paging getSysLogPageList(SysLogQueryParam SysLogQueryParam) throws Exception; } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java b/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java index 8c38e5ac..cfcf4bcb 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/SysUserService.java @@ -14,12 +14,13 @@ *

* * @author geekidea - * @since 2019-08-26 + * @since 2019-10-05 */ public interface SysUserService extends BaseService { /** * 根据ID获取查询对象 + * * @param id * @return */ @@ -27,9 +28,10 @@ public interface SysUserService extends BaseService { /** * 获取分页对象 - * @param sysUserQueryParam + * + * @param SysUserQueryParam * @return */ - Paging getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception; + Paging getSysUserPageList(SysUserQueryParam SysUserQueryParam) throws Exception; } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java index 02a97c18..9bfd7f89 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysLogServiceImpl.java @@ -24,7 +24,7 @@ *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-05 */ @Slf4j @Service @@ -32,17 +32,17 @@ public class SysLogServiceImpl extends BaseServiceImpl implements SysLogService { @Autowired - private SysLogMapper sysLogMapper; + private SysLogMapper SysLogMapper; @Override - public SysLogQueryVo getSysLogById(Serializable id) throws Exception{ - return sysLogMapper.getSysLogById(id); + public SysLogQueryVo getSysLogById(Serializable id) throws Exception { + return SysLogMapper.getSysLogById(id); } @Override - public Paging getSysLogPageList(SysLogQueryParam sysLogQueryParam) throws Exception{ - Page page = setPageParam(sysLogQueryParam,OrderItem.desc("create_time")); - IPage iPage = sysLogMapper.getSysLogPageList(page,sysLogQueryParam); + public Paging getSysLogPageList(SysLogQueryParam SysLogQueryParam) throws Exception { + Page page = setPageParam(SysLogQueryParam, OrderItem.desc("create_time")); + IPage iPage = SysLogMapper.getSysLogPageList(page, SysLogQueryParam); return new Paging(iPage); } diff --git a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java index 6415c665..e0dd3587 100644 --- a/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java +++ b/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java @@ -24,7 +24,7 @@ *

* * @author geekidea - * @since 2019-08-26 + * @since 2019-10-05 */ @Slf4j @Service @@ -32,17 +32,17 @@ public class SysUserServiceImpl extends BaseServiceImpl implements SysUserService { @Autowired - private SysUserMapper sysUserMapper; + private SysUserMapper SysUserMapper; @Override - public SysUserQueryVo getSysUserById(Serializable id) throws Exception{ - return sysUserMapper.getSysUserById(id); + public SysUserQueryVo getSysUserById(Serializable id) throws Exception { + return SysUserMapper.getSysUserById(id); } @Override - public Paging getSysUserPageList(SysUserQueryParam sysUserQueryParam) throws Exception{ - Page page = setPageParam(sysUserQueryParam,OrderItem.desc("create_time")); - IPage iPage = sysUserMapper.getSysUserPageList(page,sysUserQueryParam); + public Paging getSysUserPageList(SysUserQueryParam SysUserQueryParam) throws Exception { + Page page = setPageParam(SysUserQueryParam, OrderItem.desc("create_time")); + IPage iPage = SysUserMapper.getSysUserPageList(page, SysUserQueryParam); return new Paging(iPage); } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java b/src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java index 4c629b9f..d2124213 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java +++ b/src/main/java/io/geekidea/springbootplus/system/web/controller/SysLogController.java @@ -1,13 +1,11 @@ package io.geekidea.springbootplus.system.web.controller; -import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.common.web.controller.BaseController; -import io.geekidea.springbootplus.common.web.param.IdParam; -import io.geekidea.springbootplus.common.web.vo.Paging; import io.geekidea.springbootplus.system.entity.SysLog; import io.geekidea.springbootplus.system.service.SysLogService; import io.geekidea.springbootplus.system.web.param.SysLogQueryParam; import io.geekidea.springbootplus.system.web.vo.SysLogQueryVo; +import io.geekidea.springbootplus.common.api.ApiResult; +import io.geekidea.springbootplus.common.web.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -19,70 +17,73 @@ import javax.validation.Valid; +import io.geekidea.springbootplus.common.web.vo.Paging; +import io.geekidea.springbootplus.common.web.param.IdParam; + /** *

* 系统日志 前端控制器 *

* * @author geekidea - * @since 2019-08-04 + * @since 2019-10-05 */ @Slf4j @RestController -@RequestMapping("/sysLog") +@RequestMapping("/SysLog") @Api("系统日志 API") public class SysLogController extends BaseController { @Autowired - private SysLogService sysLogService; + private SysLogService SysLogService; /** - * 添加系统日志 - */ + * 添加系统日志 + */ @PostMapping("/add") - @ApiOperation(value = "添加SysLog对象",notes = "添加系统日志",response = ApiResult.class) - public ApiResult addSysUser(@Valid @RequestBody SysLog sysLog) throws Exception{ - boolean flag = sysLogService.save(sysLog); + @ApiOperation(value = "添加SysLog对象", notes = "添加系统日志", response = ApiResult.class) + public ApiResult addSysLog(@Valid @RequestBody SysLog SysLog) throws Exception { + boolean flag = SysLogService.save(SysLog); return ApiResult.result(flag); } /** - * 修改系统日志 - */ + * 修改系统日志 + */ @PostMapping("/update") - @ApiOperation(value = "修改SysLog对象",notes = "修改系统日志",response = ApiResult.class) - public ApiResult updateSysUser(@Valid @RequestBody SysLog sysLog) throws Exception{ - boolean flag = sysLogService.updateById(sysLog); + @ApiOperation(value = "修改SysLog对象", notes = "修改系统日志", response = ApiResult.class) + public ApiResult updateSysLog(@Valid @RequestBody SysLog SysLog) throws Exception { + boolean flag = SysLogService.updateById(SysLog); return ApiResult.result(flag); } /** - * 删除系统日志 - */ + * 删除系统日志 + */ @PostMapping("/delete") - @ApiOperation(value = "删除SysLog对象",notes = "删除系统日志",response = ApiResult.class) - public ApiResult deleteSysUser(@Valid @RequestBody IdParam idParam) throws Exception{ - boolean flag = sysLogService.removeById(idParam.getId()); + @ApiOperation(value = "删除SysLog对象", notes = "删除系统日志", response = ApiResult.class) + public ApiResult deleteSysLog(@Valid @RequestBody IdParam idParam) throws Exception { + boolean flag = SysLogService.removeById(idParam.getId()); return ApiResult.result(flag); } /** - * 获取系统日志 - */ + * 获取系统日志 + */ @PostMapping("/info") - @ApiOperation(value = "获取SysLog对象详情",notes = "查看系统日志",response = SysLogQueryVo.class) - public ApiResult getSysUser(@Valid @RequestBody IdParam idParam) throws Exception{ - SysLogQueryVo sysLogQueryVo = sysLogService.getSysLogById(idParam.getId()); - return ApiResult.ok(sysLogQueryVo); + @ApiOperation(value = "获取SysLog对象详情", notes = "查看系统日志", response = SysLogQueryVo.class) + public ApiResult getSysLog(@Valid @RequestBody IdParam idParam) throws Exception { + SysLogQueryVo SysLogQueryVo = SysLogService.getSysLogById(idParam.getId()); + return ApiResult.ok(SysLogQueryVo); } /** * 系统日志分页列表 */ @PostMapping("/getPageList") - @ApiOperation(value = "获取SysLog分页列表",notes = "系统日志分页列表",response = SysLogQueryVo.class) - public ApiResult> getSysLogPageList(@Valid @RequestBody(required = false) SysLogQueryParam sysLogQueryParam) throws Exception{ - Paging paging = sysLogService.getSysLogPageList(sysLogQueryParam); + @ApiOperation(value = "获取SysLog分页列表", notes = "系统日志分页列表", response = SysLogQueryVo.class) + public ApiResult> getSysLogPageList(@Valid @RequestBody(required = false) SysLogQueryParam SysLogQueryParam) throws Exception { + Paging paging = SysLogService.getSysLogPageList(SysLogQueryParam); return ApiResult.ok(paging); } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java b/src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java index 06a9104f..19c0aae6 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java +++ b/src/main/java/io/geekidea/springbootplus/system/web/controller/SysUserController.java @@ -1,13 +1,11 @@ package io.geekidea.springbootplus.system.web.controller; -import io.geekidea.springbootplus.common.api.ApiResult; -import io.geekidea.springbootplus.common.web.controller.BaseController; -import io.geekidea.springbootplus.common.web.param.IdParam; -import io.geekidea.springbootplus.common.web.vo.Paging; import io.geekidea.springbootplus.system.entity.SysUser; import io.geekidea.springbootplus.system.service.SysUserService; import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; +import io.geekidea.springbootplus.common.api.ApiResult; +import io.geekidea.springbootplus.common.web.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -19,70 +17,73 @@ import javax.validation.Valid; +import io.geekidea.springbootplus.common.web.vo.Paging; +import io.geekidea.springbootplus.common.web.param.IdParam; + /** *

* SystemUser 前端控制器 *

* * @author geekidea - * @since 2019-08-26 + * @since 2019-10-05 */ @Slf4j @RestController -@RequestMapping("/sysUser") +@RequestMapping("/SysUser") @Api("SystemUser API") public class SysUserController extends BaseController { @Autowired - private SysUserService sysUserService; + private SysUserService SysUserService; /** - * Save SystemUser - */ + * 添加SystemUser + */ @PostMapping("/add") - @ApiOperation(value = "Save SysUser",notes = "Save SystemUser",response = ApiResult.class) - public ApiResult addSysUser(@Valid @RequestBody SysUser sysUser) throws Exception{ - boolean flag = sysUserService.save(sysUser); + @ApiOperation(value = "添加SysUser对象", notes = "添加SystemUser", response = ApiResult.class) + public ApiResult addSysUser(@Valid @RequestBody SysUser SysUser) throws Exception { + boolean flag = SysUserService.save(SysUser); return ApiResult.result(flag); } /** - * Update SystemUser - */ + * 修改SystemUser + */ @PostMapping("/update") - @ApiOperation(value = "Update SysUser",notes = "Update SystemUser",response = ApiResult.class) - public ApiResult updateSysUser(@Valid @RequestBody SysUser sysUser) throws Exception{ - boolean flag = sysUserService.updateById(sysUser); + @ApiOperation(value = "修改SysUser对象", notes = "修改SystemUser", response = ApiResult.class) + public ApiResult updateSysUser(@Valid @RequestBody SysUser SysUser) throws Exception { + boolean flag = SysUserService.updateById(SysUser); return ApiResult.result(flag); } /** - * Delete SystemUser - */ + * 删除SystemUser + */ @PostMapping("/delete") - @ApiOperation(value = "Delete SysUser",notes = "Delete SystemUser",response = ApiResult.class) - public ApiResult deleteSysUser(@Valid @RequestBody IdParam idParam) throws Exception{ - boolean flag = sysUserService.removeById(idParam.getId()); + @ApiOperation(value = "删除SysUser对象", notes = "删除SystemUser", response = ApiResult.class) + public ApiResult deleteSysUser(@Valid @RequestBody IdParam idParam) throws Exception { + boolean flag = SysUserService.removeById(idParam.getId()); return ApiResult.result(flag); } /** - * Get SystemUser - */ + * 获取SystemUser + */ @PostMapping("/info") - @ApiOperation(value = "Get SysUser Detail",notes = "SystemUser Info",response = SysUserQueryVo.class) - public ApiResult getSysUser(@Valid @RequestBody IdParam idParam) throws Exception{ - SysUserQueryVo sysUserQueryVo = sysUserService.getSysUserById(idParam.getId()); - return ApiResult.ok(sysUserQueryVo); + @ApiOperation(value = "获取SysUser对象详情", notes = "查看SystemUser", response = SysUserQueryVo.class) + public ApiResult getSysUser(@Valid @RequestBody IdParam idParam) throws Exception { + SysUserQueryVo SysUserQueryVo = SysUserService.getSysUserById(idParam.getId()); + return ApiResult.ok(SysUserQueryVo); } /** - * SystemUser Pagination + * SystemUser分页列表 */ @PostMapping("/getPageList") - @ApiOperation(value = "Get SysUserPagination",notes = "SystemUser Pagination",response = SysUserQueryVo.class) - public ApiResult> getSysUserPageList(@Valid @RequestBody(required = false) SysUserQueryParam sysUserQueryParam) throws Exception{ - Paging paging = sysUserService.getSysUserPageList(sysUserQueryParam); + @ApiOperation(value = "获取SysUser分页列表", notes = "SystemUser分页列表", response = SysUserQueryVo.class) + public ApiResult> getSysUserPageList(@Valid @RequestBody(required = false) SysUserQueryParam SysUserQueryParam) throws Exception { + Paging paging = SysUserService.getSysUserPageList(SysUserQueryParam); return ApiResult.ok(paging); } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java index 0f70df35..04caee4d 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java +++ b/src/main/java/io/geekidea/springbootplus/system/web/param/SysLogQueryParam.java @@ -3,6 +3,7 @@ import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; import io.geekidea.springbootplus.common.web.param.QueryParam; @@ -12,11 +13,12 @@ *

* * @author geekidea - * @date 2019-08-04 + * @date 2019-10-05 */ @Data +@Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -@ApiModel(value="SysLogQueryParam对象", description="系统日志查询参数") +@ApiModel(value = "SysLogQueryParam对象", description = "系统日志查询参数") public class SysLogQueryParam extends QueryParam { private static final long serialVersionUID = 1L; } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java b/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java index 5210ef69..aa622979 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java +++ b/src/main/java/io/geekidea/springbootplus/system/web/param/SysUserQueryParam.java @@ -3,6 +3,7 @@ import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; import io.geekidea.springbootplus.common.web.param.QueryParam; @@ -12,11 +13,12 @@ *

* * @author geekidea - * @date 2019-08-26 + * @date 2019-10-05 */ @Data +@Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -@ApiModel(value="SysUserQueryParam对象", description="SystemUser查询参数") +@ApiModel(value = "SysUserQueryParam对象", description = "SystemUser查询参数") public class SysUserQueryParam extends QueryParam { private static final long serialVersionUID = 1L; } diff --git a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java index 3bcdc16d..e6b4df95 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java +++ b/src/main/java/io/geekidea/springbootplus/system/web/vo/SysLogQueryVo.java @@ -3,6 +3,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.experimental.Accessors; import java.io.Serializable; import java.util.Date; @@ -13,11 +14,12 @@ *

* * @author geekidea - * @date 2019-08-04 + * @date 2019-10-05 */ @Data -@ApiModel(value="SysLogQueryVo对象", description="系统日志查询参数") -public class SysLogQueryVo implements Serializable{ +@Accessors(chain = true) +@ApiModel(value = "SysLogQueryVo对象", description = "系统日志查询参数") +public class SysLogQueryVo implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "主键") diff --git a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java index d04063ec..8c97056a 100644 --- a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java +++ b/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java @@ -3,6 +3,8 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.experimental.Accessors; + import java.io.Serializable; import java.util.Date; @@ -13,32 +15,39 @@ *

* * @author geekidea - * @date 2019-08-26 + * @date 2019-10-05 */ @Data -@ApiModel(value="SysUserQueryVo对象", description="SystemUser查询参数") -public class SysUserQueryVo implements Serializable{ +@Accessors(chain = true) +@ApiModel(value = "SysUserQueryVo对象", description = "SystemUser查询参数") +public class SysUserQueryVo implements Serializable { private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "id") + @ApiModelProperty(value = "主键") private Long id; - @ApiModelProperty(value = "name") - private String name; + @ApiModelProperty(value = "用户名") + private String username; + + @ApiModelProperty(value = "昵称") + private String nickname; - @ApiModelProperty(value = "account") - private String account; + @ApiModelProperty(value = "密码") + private String password; - @ApiModelProperty(value = "password") - private String pwd; + @ApiModelProperty(value = "盐值") + private String salt; @ApiModelProperty(value = "remark") private String remark; - @ApiModelProperty(value = "create time") + @ApiModelProperty(value = "状态,0:禁用,1:启用") + private Integer status; + + @ApiModelProperty(value = "创建时间") private Date createTime; - @ApiModelProperty(value = "update time") + @ApiModelProperty(value = "修改时间") private Date updateTime; } \ No newline at end of file diff --git a/src/main/java/io/geekidea/springbootplus/util/PasswordUtil.java b/src/main/java/io/geekidea/springbootplus/util/PasswordUtil.java index 49d22225..b0be2e12 100644 --- a/src/main/java/io/geekidea/springbootplus/util/PasswordUtil.java +++ b/src/main/java/io/geekidea/springbootplus/util/PasswordUtil.java @@ -1,12 +1,12 @@ /** * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,22 +22,19 @@ /** * 密码加密工具类 + * * @author geekidea * @date 2018-11-08 */ @Slf4j public class PasswordUtil { - private static final String KEY = "io.geekidea.springbootplus.springbootplus.pwd.key"; - public static String encrypt(String pwd){ - if (StringUtils.isBlank(pwd)){ + private static final String KEY = "666666"; + + public static String encrypt(String pwd) { + if (StringUtils.isBlank(pwd)) { return null; } - pwd = pwd + KEY; - String newPwd = DigestUtils.sha256Hex(pwd) + DigestUtils.md5Hex(pwd); - return newPwd; + return DigestUtils.sha256Hex(KEY + pwd); } - public static void main(String[] args) { - log.debug(encrypt("7c4a8d09ca3762af61e59520943dc26494f8941b")); - } } diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 64fc13ce..5c3e4ff9 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -183,7 +183,8 @@ spring: test-on-return: false test-while-idle: true time-between-eviction-runs-millis: 60000 - validation-query: SELECT 1 FROM DUAL + validation-query: SELECT 1 + validation-query-timeout: 60000 type: com.alibaba.druid.pool.DruidDataSource ############################### DRUID数据源配置 end ################################ diff --git a/src/main/resources/mapper/system/SysLogMapper.xml b/src/main/resources/mapper/system/SysLogMapper.xml index 2c769fd3..82f43ad8 100644 --- a/src/main/resources/mapper/system/SysLogMapper.xml +++ b/src/main/resources/mapper/system/SysLogMapper.xml @@ -8,11 +8,15 @@ diff --git a/src/main/resources/mapper/system/SysUserMapper.xml b/src/main/resources/mapper/system/SysUserMapper.xml index 100c3e7c..b43e7b58 100644 --- a/src/main/resources/mapper/system/SysUserMapper.xml +++ b/src/main/resources/mapper/system/SysUserMapper.xml @@ -4,15 +4,26 @@ - id, name, account, pwd, remark, create_time, update_time + id, username, nickname, password, salt, remark, status, create_time, update_time + + diff --git a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java index 2398450a..ed403b29 100644 --- a/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +++ b/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java @@ -1,12 +1,12 @@ /** * Copyright 2019-2029 geekidea(https://github.com/geekidea) - * + *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,6 +33,7 @@ /** * spring-boot-plus代码生成器入口类 + * * @author geekidea * @date 2018-11-08 */ @@ -59,9 +60,9 @@ public class CodeGenerator { // 作者 private static final String AUTHOR = "geekidea"; // 生成的表名称 - private static final String TABLE_NAME = "sys_log"; + private static final String TABLE_NAME = "sys_user"; // 主键数据库列名称 - private static final String PK_ID_COLUMN_NAME = "log_id"; + private static final String PK_ID_COLUMN_NAME = "id"; // 代码生成策略 true:All/false:SIMPLE private static final boolean GENERATOR_STRATEGY = true; // 分页列表查询是否排序 true:有排序参数/false:无 @@ -108,36 +109,48 @@ public static void main(String[] args) { InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { - Map map = new HashMap(); + + String pascalTableName = underlineToPascal(TABLE_NAME); + + Map map = new HashMap<>(); map.put("customField", "Hello " + this.getConfig().getGlobalConfig().getAuthor()); // 查询参数包路径 - map.put("queryParamPath",PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".web.param." + underlineToPascal(TABLE_NAME) + "QueryParam"); + String queryParamPackage = PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".web.param"; + map.put("queryParamPackage", queryParamPackage); + // 查询参数类路径 + map.put("queryParamPath", queryParamPackage + StringPool.DOT + pascalTableName + "QueryParam"); // 查询参数共公包路径 - map.put("queryParamCommonPath",PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "QueryParam"); + map.put("queryParamCommonPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "QueryParam"); // 查询参数共公包路径 - map.put("idParamPath",PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "IdParam"); + map.put("idParamPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "IdParam"); // 响应结果包路径 - map.put("queryVoPath",PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".web.vo." + underlineToPascal(TABLE_NAME) + "QueryVo"); + String queryVoPackage = PARENT_PACKAGE + StringPool.DOT + pc.getModuleName() + ".web.vo"; + map.put("queryVoPackage", queryVoPackage); + // 响应结果类路径 + map.put("queryVoPath", queryVoPackage + StringPool.DOT + pascalTableName + "QueryVo"); // 实体对象名称 - map.put("entityObjectName",underlineToCamel(TABLE_NAME)); + map.put("entityObjectName", pascalTableName); // service对象名称 - map.put("serviceObjectName",underlineToCamel(TABLE_NAME) + "Service"); + map.put("serviceObjectName", pascalTableName + "Service"); // mapper对象名称 - map.put("mapperObjectName",underlineToCamel(TABLE_NAME) + "Mapper"); + map.put("mapperObjectName", pascalTableName + "Mapper"); // 主键ID列名 - map.put("pkIdColumnName",PK_ID_COLUMN_NAME); + map.put("pkIdColumnName", PK_ID_COLUMN_NAME); // 主键ID驼峰名称 - map.put("pkIdCamelName",underlineToCamel(PK_ID_COLUMN_NAME)); + map.put("pkIdCamelName", underlineToCamel(PK_ID_COLUMN_NAME)); // 导入分页类 - map.put("paging",PARENT_PACKAGE + ".common.web.vo.Paging"); + map.put("paging", PARENT_PACKAGE + ".common.web.vo.Paging"); // 导入排序枚举 - map.put("orderEnum",PARENT_PACKAGE + ".common.enums.OrderEnum"); + map.put("orderEnum", PARENT_PACKAGE + ".common.enums.OrderEnum"); + // ApiResult + // io.geekidea.springbootplus.common.api.ApiResult; + map.put("apiResult", PARENT_PACKAGE + ".common.api.ApiResult"); // 分页列表查询是否排序 - map.put("pageListOrder",PAGE_LIST_ORDER); + map.put("pageListOrder", PAGE_LIST_ORDER); // 导入排序查询参数类 - map.put("orderQueryParamPath",PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "OrderQueryParam"); + map.put("orderQueryParamPath", PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "OrderQueryParam"); // 代码生成策略 - map.put("generatorStrategy",GENERATOR_STRATEGY); + map.put("generatorStrategy", GENERATOR_STRATEGY); this.setMap(map); } }; @@ -155,7 +168,7 @@ public String outputFile(TableInfo tableInfo) { focList.add(new FileOutConfig("/templates/queryParam.java.vm") { @Override public String outputFile(TableInfo tableInfo) { - return projectPath + "/src/main/java/"+ PROJECT_PACKAGE_PATH +"/" + pc.getModuleName() + "/web/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA; + return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA; } }); @@ -163,11 +176,11 @@ public String outputFile(TableInfo tableInfo) { focList.add(new FileOutConfig("/templates/queryVo.java.vm") { @Override public String outputFile(TableInfo tableInfo) { - return projectPath + "/src/main/java/"+ PROJECT_PACKAGE_PATH +"/" + pc.getModuleName() + "/web/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA; + return projectPath + "/src/main/java/" + PROJECT_PACKAGE_PATH + "/" + pc.getModuleName() + "/web/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA; } }); - - + + cfg.setFileOutConfigList(focList); mpg.setCfg(cfg); mpg.setTemplate(new TemplateConfig().setXml(null)); @@ -195,15 +208,15 @@ public String outputFile(TableInfo tableInfo) { mpg.execute(); } - public static String underlineToCamel(String underline){ - if (StringUtils.isNotBlank(underline)){ + public static String underlineToCamel(String underline) { + if (StringUtils.isNotBlank(underline)) { return NamingStrategy.underlineToCamel(underline); } return null; } - public static String underlineToPascal(String underline){ - if (StringUtils.isNotBlank(underline)){ + public static String underlineToPascal(String underline) { + if (StringUtils.isNotBlank(underline)) { return NamingStrategy.capitalFirst(NamingStrategy.underlineToCamel(underline)); } return null; diff --git a/src/test/java/io/geekidea/springbootplus/test/PasswordUtilTest.java b/src/test/java/io/geekidea/springbootplus/test/PasswordUtilTest.java new file mode 100644 index 00000000..2e32904a --- /dev/null +++ b/src/test/java/io/geekidea/springbootplus/test/PasswordUtilTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.test; + +import io.geekidea.springbootplus.util.PasswordUtil; + +/** + * 密码工具测试类 + * @author geekidea + * @date 2019-10-05 + **/ +public class PasswordUtilTest { + public static void main(String[] args) { + String password = "123456"; + String encryptPassword = PasswordUtil.encrypt(password); + System.out.println(encryptPassword); + System.out.println(encryptPassword.length()); + } +} diff --git a/src/test/java/io/geekidea/springbootplus/test/SaltUtilTest.java b/src/test/java/io/geekidea/springbootplus/test/SaltUtilTest.java new file mode 100644 index 00000000..dc99eb7e --- /dev/null +++ b/src/test/java/io/geekidea/springbootplus/test/SaltUtilTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2019-2029 geekidea(https://github.com/geekidea) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.geekidea.springbootplus.test; + +import io.geekidea.springbootplus.shiro.util.SaltUtil; + +/** + * @author geekidea + * @date 2019-10-05 + **/ +public class SaltUtilTest { + public static void main(String[] args) { + String salt = SaltUtil.generateSalt(); + System.out.println(salt); + System.out.println(salt.length()); + } +} diff --git a/src/test/resources/templates/controller.java.vm b/src/test/resources/templates/controller.java.vm index 4f81d861..7930f041 100644 --- a/src/test/resources/templates/controller.java.vm +++ b/src/test/resources/templates/controller.java.vm @@ -4,11 +4,11 @@ import ${package.Entity}.${entity}; import ${package.Service}.${table.serviceName}; import ${cfg.queryParamPath}; import ${cfg.queryVoPath}; +import ${cfg.apiResult}; #if(${superControllerClassPackage}) import ${superControllerClassPackage}; #end -import io.geekidea.springbootplus.common.api.ApiResult; - #if(${swagger2}) +#if(${swagger2}) import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; #end @@ -59,41 +59,41 @@ public class ${table.controllerName} { #if(${cfg.generatorStrategy}) /** - * 添加$!{table.comment} - */ + * 添加$!{table.comment} + */ @PostMapping("/add") - @ApiOperation(value = "添加${entity}对象",notes = "添加$!{table.comment}",response = ApiResult.class) - public ApiResult add${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception{ + @ApiOperation(value = "添加${entity}对象", notes = "添加$!{table.comment}", response = ApiResult.class) + public ApiResult add${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception { boolean flag = ${cfg.serviceObjectName}.save(${cfg.entityObjectName}); return ApiResult.result(flag); } /** - * 修改$!{table.comment} - */ + * 修改$!{table.comment} + */ @PostMapping("/update") - @ApiOperation(value = "修改${entity}对象",notes = "修改$!{table.comment}",response = ApiResult.class) - public ApiResult update${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception{ + @ApiOperation(value = "修改${entity}对象", notes = "修改$!{table.comment}", response = ApiResult.class) + public ApiResult update${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception { boolean flag = ${cfg.serviceObjectName}.updateById(${cfg.entityObjectName}); return ApiResult.result(flag); } /** - * 删除$!{table.comment} - */ + * 删除$!{table.comment} + */ @PostMapping("/delete") - @ApiOperation(value = "删除${entity}对象",notes = "删除$!{table.comment}",response = ApiResult.class) - public ApiResult delete${entity}(@Valid @RequestBody IdParam idParam) throws Exception{ + @ApiOperation(value = "删除${entity}对象", notes = "删除$!{table.comment}", response = ApiResult.class) + public ApiResult delete${entity}(@Valid @RequestBody IdParam idParam) throws Exception { boolean flag = ${cfg.serviceObjectName}.removeById(idParam.getId()); return ApiResult.result(flag); } /** - * 获取$!{table.comment} - */ + * 获取$!{table.comment} + */ @PostMapping("/info") - @ApiOperation(value = "获取${entity}对象详情",notes = "查看$!{table.comment}",response = ${entity}QueryVo.class) - public ApiResult<${entity}QueryVo> get${entity}(@Valid @RequestBody IdParam idParam) throws Exception{ + @ApiOperation(value = "获取${entity}对象详情", notes = "查看$!{table.comment}", response = ${entity}QueryVo.class) + public ApiResult<${entity}QueryVo> get${entity}(@Valid @RequestBody IdParam idParam) throws Exception { ${entity}QueryVo ${cfg.entityObjectName}QueryVo = ${cfg.serviceObjectName}.get${entity}ById(idParam.getId()); return ApiResult.ok(${cfg.entityObjectName}QueryVo); } @@ -102,8 +102,8 @@ public class ${table.controllerName} { * $!{table.comment}分页列表 */ @PostMapping("/getPageList") - @ApiOperation(value = "获取${entity}分页列表",notes = "$!{table.comment}分页列表",response = ${entity}QueryVo.class) - public ApiResult> get${entity}PageList(@Valid @RequestBody(required = false) ${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception{ + @ApiOperation(value = "获取${entity}分页列表", notes = "$!{table.comment}分页列表", response = ${entity}QueryVo.class) + public ApiResult> get${entity}PageList(@Valid @RequestBody(required = false) ${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception { Paging<${entity}QueryVo> paging = ${cfg.entityObjectName}Service.get${entity}PageList(${cfg.entityObjectName}QueryParam); return ApiResult.ok(paging); } diff --git a/src/test/resources/templates/entity.java.vm b/src/test/resources/templates/entity.java.vm index 61c3326a..fc801134 100644 --- a/src/test/resources/templates/entity.java.vm +++ b/src/test/resources/templates/entity.java.vm @@ -10,11 +10,9 @@ import io.swagger.annotations.ApiModelProperty; #if(${entityLombokModel}) import lombok.Data; import lombok.EqualsAndHashCode; -## import lombok.experimental.Accessors; +import lombok.experimental.Accessors; #end -import java.util.Date; - /** *

* $!{table.comment} @@ -25,18 +23,18 @@ import java.util.Date; */ #if(${entityLombokModel}) @Data +@Accessors(chain = true) #if(${superEntityClass}) @EqualsAndHashCode(callSuper = true) #else @EqualsAndHashCode(callSuper = false) #end -## @Accessors(chain = true) #end #if(${table.convert}) @TableName("${table.name}") #end #if(${swagger2}) -@ApiModel(value="${entity}对象", description="$!{table.comment}") +@ApiModel(value = "${entity}对象", description = "$!{table.comment}") #end #if(${superEntityClass}) public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end { diff --git a/src/test/resources/templates/mapper.java.vm b/src/test/resources/templates/mapper.java.vm index 207c1cbb..74d2b97d 100644 --- a/src/test/resources/templates/mapper.java.vm +++ b/src/test/resources/templates/mapper.java.vm @@ -28,6 +28,7 @@ public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { /** * 根据ID获取查询对象 + * * @param id * @return */ @@ -35,6 +36,7 @@ public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { /** * 获取分页对象 + * * @param page * @param ${cfg.entityObjectName}QueryParam * @return diff --git a/src/test/resources/templates/mapper.xml.vm b/src/test/resources/templates/mapper.xml.vm index b3829d3f..3d6ebd75 100644 --- a/src/test/resources/templates/mapper.xml.vm +++ b/src/test/resources/templates/mapper.xml.vm @@ -36,11 +36,15 @@ #if(${cfg.generatorStrategy}) #end diff --git a/src/test/resources/templates/queryParam.java.vm b/src/test/resources/templates/queryParam.java.vm index 15357e73..a8dea102 100644 --- a/src/test/resources/templates/queryParam.java.vm +++ b/src/test/resources/templates/queryParam.java.vm @@ -1,8 +1,9 @@ -package io.geekidea.springbootplus.${package.ModuleName}.web.param; +package ${cfg.queryParamPackage}; import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; #if(${cfg.pageListOrder}) import ${cfg.orderQueryParamPath}; @@ -19,8 +20,9 @@ import ${cfg.queryParamCommonPath}; * @date ${date} */ @Data +@Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -@ApiModel(value="${entity}QueryParam对象", description="$!{table.comment}查询参数") +@ApiModel(value = "${entity}QueryParam对象", description = "$!{table.comment}查询参数") #if(${cfg.pageListOrder}) public class ${entity}QueryParam extends OrderQueryParam { #else diff --git a/src/test/resources/templates/queryVo.java.vm b/src/test/resources/templates/queryVo.java.vm index 4ccd4ce4..bf964cd5 100644 --- a/src/test/resources/templates/queryVo.java.vm +++ b/src/test/resources/templates/queryVo.java.vm @@ -1,4 +1,4 @@ -package io.geekidea.springbootplus.${package.ModuleName}.web.vo; +package ${cfg.queryVoPackage}; #if(${swagger2}) import io.swagger.annotations.ApiModel; @@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty; #end #if(${entityLombokModel}) import lombok.Data; +import lombok.experimental.Accessors; #end import java.io.Serializable; @@ -21,12 +22,13 @@ import java.util.Date; */ #if(${entityLombokModel}) @Data +@Accessors(chain = true) #end #if(${table.convert}) @TableName("${table.name}") #end -@ApiModel(value="${entity}QueryVo对象", description="$!{table.comment}查询参数") -public class ${entity}QueryVo implements Serializable{ +@ApiModel(value = "${entity}QueryVo对象", description = "$!{table.comment}查询参数") +public class ${entity}QueryVo implements Serializable { private static final long serialVersionUID = 1L; ## ---------- BEGIN 字段循环遍历 ---------- #foreach($field in ${table.fields}) diff --git a/src/test/resources/templates/service.java.vm b/src/test/resources/templates/service.java.vm index 9009d5c1..5295594a 100644 --- a/src/test/resources/templates/service.java.vm +++ b/src/test/resources/templates/service.java.vm @@ -24,6 +24,7 @@ public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { /** * 根据ID获取查询对象 + * * @param id * @return */ @@ -31,6 +32,7 @@ public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { /** * 获取分页对象 + * * @param ${cfg.entityObjectName}QueryParam * @return */ diff --git a/src/test/resources/templates/serviceImpl.java.vm b/src/test/resources/templates/serviceImpl.java.vm index 648f327d..152620a7 100644 --- a/src/test/resources/templates/serviceImpl.java.vm +++ b/src/test/resources/templates/serviceImpl.java.vm @@ -41,14 +41,14 @@ public class ${table.serviceImplName} extends BaseServiceImpl<${table.mapperName #if(${cfg.generatorStrategy}) @Override - public ${entity}QueryVo get${entity}ById(Serializable id) throws Exception{ + public ${entity}QueryVo get${entity}ById(Serializable id) throws Exception { return ${cfg.mapperObjectName}.get${entity}ById(id); } @Override - public Paging<${entity}QueryVo> get${entity}PageList(${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception{ - Page page = setPageParam(${cfg.entityObjectName}QueryParam,OrderItem.desc("create_time")); - IPage<${entity}QueryVo> iPage = ${cfg.mapperObjectName}.get${entity}PageList(page,${cfg.entityObjectName}QueryParam); + public Paging<${entity}QueryVo> get${entity}PageList(${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception { + Page page = setPageParam(${cfg.entityObjectName}QueryParam, OrderItem.desc("create_time")); + IPage<${entity}QueryVo> iPage = ${cfg.mapperObjectName}.get${entity}PageList(page, ${cfg.entityObjectName}QueryParam); return new Paging(iPage); } #end