Skip to content

Commit d631394

Browse files
Merge pull request #128 from geekidea/dev
fix CodeGenerator/ SysUser / mysql_spring_boot_plus.sql
2 parents c824049 + ecf6276 commit d631394

File tree

7 files changed

+102
-94
lines changed

7 files changed

+102
-94
lines changed

docs/db/mysql_spring_boot_plus.sql

+84-74
Large diffs are not rendered by default.

framework/src/main/java/io/geekidea/springbootplus/framework/util/PrintApplicationInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void printTip(ConfigurableApplicationContext context) {
5757
tip.append(" generator: 代码生成模块,启动类:SpringBootPlusGenerator,请根据实际情况进行配置\n");
5858
tip.append(" scheduled: 任务调度模块\n");
5959
tip.append(" system: 系统管理模块\n");
60-
tip.append(" 6.FAQ:https://springboot.plus/faq.html\n");
60+
tip.append(" 6.FAQ:https://springboot.plus/faq\n");
6161
tip.append(" 7.如开发中遇到bug及问题,欢迎提交ISSUES:https://github.com/geekidea/spring-boot-plus/issues\n");
6262
tip.append(" 8.QQ:625301326,进群答案:springboot.plus\n");
6363
tip.append(" \n");

generator/src/main/java/io/geekidea/springbootplus/generator/CodeGenerator.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.HashMap;
4242
import java.util.List;
4343
import java.util.Map;
44+
import java.util.regex.Matcher;
4445

4546
/**
4647
* spring-boot-plus代码生成器
@@ -82,7 +83,7 @@ public void init(String tableName, GeneratorProperties generatorProperties) {
8283
}
8384
// 如果包路径为空,转换包名称路径
8485
if (StringUtils.isNotBlank(parentPackage)) {
85-
generatorProperties.setParentPackagePath(parentPackage.replaceAll("\\.", File.separator));
86+
generatorProperties.setParentPackagePath(parentPackage.replaceAll("\\.", Matcher.quoteReplacement(File.separator)));
8687
}
8788

8889
String mavenModuleName = generatorProperties.getMavenModuleName();
@@ -130,17 +131,9 @@ public void generator(String tableName, String pkIdName, GeneratorProperties gen
130131
String resourcesOutputDir = null;
131132
String mapperXmlOutputDir = null;
132133

133-
134134
if (StringUtils.isBlank(outputDir)) {
135-
// 使用application.yml配置时,默认路径设置
136-
// String currentProjectPath = System.getProperty(GeneratorConstant.USER_DIR);
137-
// File rootProjectFile = new File(currentProjectPath);
138-
// String rootProjectPath = rootProjectFile.getParent();
139-
// 从java启动时,默认路径设置
140-
String currentClassPath = this.getClass().getClassLoader().getResource("").getFile();
141-
File file = new File(currentClassPath);
142-
String rootProjectPath = file.getParentFile().getParentFile().getParentFile().getAbsolutePath();
143-
outputDir = rootProjectPath + File.separator + mavenModuleName;
135+
String rootProjectFile = System.getProperty(GeneratorConstant.USER_DIR);
136+
outputDir = rootProjectFile + File.separator + mavenModuleName;
144137
}
145138
log.info("outputDir: {}", outputDir);
146139
javaOutputDir = outputDir + GeneratorConstant.JAVA_DIR;

generator/src/main/java/io/geekidea/springbootplus/generator/SpringBootPlusGenerator.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import io.geekidea.springbootplus.generator.properties.GeneratorProperties;
2626
import org.springframework.stereotype.Component;
2727

28+
import java.util.Arrays;
29+
2830
/**
2931
* spring-boot-plus代码生成器入口类
3032
*
@@ -51,6 +53,8 @@ public static void main(String[] args) {
5153

5254
// 设置表信息
5355
generatorProperties.addTable("foo_bar","id");
56+
// 设置表前缀
57+
// generatorProperties.setTablePrefix(Arrays.asList("tb_"));
5458

5559
// 数据源配置
5660
generatorProperties.getDataSourceConfig()

system/src/main/java/io/geekidea/springbootplus/system/controller/SysUserController.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import io.geekidea.springbootplus.framework.common.api.ApiResult;
2121
import io.geekidea.springbootplus.framework.common.controller.BaseController;
2222
import io.geekidea.springbootplus.framework.core.pagination.Paging;
23+
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
24+
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
2325
import io.geekidea.springbootplus.framework.log.annotation.Module;
2426
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
2527
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
@@ -66,7 +68,7 @@ public class SysUserController extends BaseController {
6668
@RequiresPermissions("sys:user:add")
6769
@OperationLog(name = "添加系统用户", type = OperationLogType.ADD)
6870
@ApiOperation(value = "添加系统用户", response = ApiResult.class)
69-
public ApiResult<Boolean> addSysUser(@Validated @RequestBody SysUser sysUser) throws Exception {
71+
public ApiResult<Boolean> addSysUser(@Validated(Add.class) @RequestBody SysUser sysUser) throws Exception {
7072
boolean flag = sysUserService.saveSysUser(sysUser);
7173
return ApiResult.result(flag);
7274
}
@@ -78,7 +80,7 @@ public ApiResult<Boolean> addSysUser(@Validated @RequestBody SysUser sysUser) th
7880
@RequiresPermissions("sys:user:update")
7981
@OperationLog(name = "修改系统用户", type = OperationLogType.UPDATE)
8082
@ApiOperation(value = "修改系统用户", response = ApiResult.class)
81-
public ApiResult<Boolean> updateSysUser(@Validated @RequestBody SysUser sysUser) throws Exception {
83+
public ApiResult<Boolean> updateSysUser(@Validated(Update.class) @RequestBody SysUser sysUser) throws Exception {
8284
boolean flag = sysUserService.updateSysUser(sysUser);
8385
return ApiResult.result(flag);
8486
}

system/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.baomidou.mybatisplus.annotation.TableLogic;
2222
import com.baomidou.mybatisplus.annotation.Version;
2323
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
24+
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
2425
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
2526
import io.swagger.annotations.ApiModel;
2627
import io.swagger.annotations.ApiModelProperty;
@@ -50,12 +51,12 @@ public class SysUser extends BaseEntity {
5051
private static final long serialVersionUID = 1L;
5152

5253
@ApiModelProperty("主键")
53-
@NotNull(message = "ID不能为空",groups = {Update.class})
54+
@NotNull(message = "ID不能为空", groups = {Update.class})
5455
@TableId(value = "id", type = IdType.AUTO)
5556
private Long id;
5657

5758
@ApiModelProperty("用户名")
58-
@NotNull(message = "用户名不能为空")
59+
@NotNull(message = "用户名不能为空", groups = {Add.class})
5960
private String username;
6061

6162
@ApiModelProperty("昵称")

system/src/main/java/io/geekidea/springbootplus/system/service/impl/SysUserServiceImpl.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,16 @@ public boolean saveSysUser(SysUser sysUser) throws Exception {
9090
// 生成盐值
9191
String salt = null;
9292
String password = sysUser.getPassword();
93-
String encryptPassword = null;
9493
// 如果密码为空,则设置默认密码
9594
if (StringUtils.isBlank(password)) {
9695
salt = springBootPlusProperties.getLoginInitSalt();
97-
encryptPassword = springBootPlusProperties.getLoginInitPassword();
96+
password = springBootPlusProperties.getLoginInitPassword();
9897
} else {
9998
salt = SaltUtil.generateSalt();
10099
}
101100
// 密码加密
102-
encryptPassword = PasswordUtil.encrypt(password, salt);
103101
sysUser.setSalt(salt);
104-
sysUser.setPassword(encryptPassword);
102+
sysUser.setPassword(PasswordUtil.encrypt(password, salt));
105103

106104
// 如果头像为空,则设置默认头像
107105
if (StringUtils.isBlank(sysUser.getHead())) {

0 commit comments

Comments
 (0)