refactor: 优化字符串模板方法 API 使用
This commit is contained in:
parent
370f9cf796
commit
0f393845a1
@ -133,7 +133,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
|
||||
*/
|
||||
private String getAncestors(Long parentId) {
|
||||
DeptDO parentDept = this.getByParentId(parentId);
|
||||
return String.format("%s,%s", parentDept.getAncestors(), parentId);
|
||||
return "%s,%s".formatted(parentDept.getAncestors(), parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +155,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
|
||||
* @return 子部门列表
|
||||
*/
|
||||
private List<DeptDO> listChildren(Long id) {
|
||||
return baseMapper.lambdaQuery().apply(String.format("find_in_set(%s, ancestors)", id)).list();
|
||||
return baseMapper.lambdaQuery().apply("find_in_set(%s, ancestors)".formatted(id)).list();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,7 +170,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
|
||||
return 0L;
|
||||
}
|
||||
return ids.stream()
|
||||
.mapToLong(id -> baseMapper.lambdaQuery().apply(String.format("find_in_set(%s, ancestors)", id)).count())
|
||||
.mapToLong(id -> baseMapper.lambdaQuery().apply("find_in_set(%s, ancestors)".formatted(id)).count())
|
||||
.sum();
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class ContiNewAdminApplication implements ApplicationRunner {
|
||||
@SaIgnore
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return String.format("%s service started successfully.", projectProperties.getName());
|
||||
return "%s service started successfully.".formatted(projectProperties.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,7 +79,7 @@ public class ContiNewAdminApplication implements ApplicationRunner {
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
Integer port = serverProperties.getPort();
|
||||
String contextPath = serverProperties.getServlet().getContextPath();
|
||||
String baseUrl = URLUtil.normalize(String.format("%s:%s%s", hostAddress, port, contextPath));
|
||||
String baseUrl = URLUtil.normalize("%s:%s%s".formatted(hostAddress, port, contextPath));
|
||||
log.info("----------------------------------------------");
|
||||
log.info("{} service started successfully.", projectProperties.getName());
|
||||
log.info("API 地址:{}", baseUrl);
|
||||
|
@ -87,7 +87,7 @@ public class SocialAuthController {
|
||||
try {
|
||||
return authRequestFactory.get(source);
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(String.format("暂不支持 [%s] 平台账号登录", source));
|
||||
throw new BadRequestException("暂不支持 [%s] 平台账号登录".formatted(source));
|
||||
}
|
||||
}
|
||||
}
|
@ -121,12 +121,12 @@ public class CaptchaController {
|
||||
String content = TemplateUtils.render(captchaMail.getTemplatePath(), Dict.create()
|
||||
.set("captcha", captcha)
|
||||
.set("expiration", expirationInMinutes));
|
||||
MailUtils.sendHtml(email, String.format("【%s】邮箱验证码", projectProperties.getName()), content);
|
||||
MailUtils.sendHtml(email, "【%s】邮箱验证码".formatted(projectProperties.getName()), content);
|
||||
// 保存验证码
|
||||
String captchaKey = captchaKeyPrefix + email;
|
||||
RedisUtils.set(captchaKey, captcha, Duration.ofMinutes(expirationInMinutes));
|
||||
RedisUtils.set(limitCaptchaKey, captcha, Duration.ofSeconds(captchaMail.getLimitInSeconds()));
|
||||
return R.ok(String.format("发送成功,验证码有效期 %s 分钟", expirationInMinutes));
|
||||
return R.ok("发送成功,验证码有效期 %s 分钟".formatted(expirationInMinutes));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取短信验证码", description = "发送验证码到指定手机号")
|
||||
@ -173,6 +173,6 @@ public class CaptchaController {
|
||||
// 保存验证码
|
||||
String captchaKey = captchaKeyPrefix + phone;
|
||||
RedisUtils.set(captchaKey, captcha, Duration.ofMinutes(expirationInMinutes));
|
||||
return R.ok(String.format("发送成功,验证码有效期 %s 分钟", expirationInMinutes));
|
||||
return R.ok("发送成功,验证码有效期 %s 分钟".formatted(expirationInMinutes));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user