【3.7.4 开源代码同步】新增断言异常类和断言工具类,优化JWT工具类,更新文件类型白名单,切换undertow配置,修改多个YAML配置文件

This commit is contained in:
JEECG
2025-03-30 17:51:55 +08:00
parent 4fb53637aa
commit 9191a8b620
50 changed files with 679 additions and 930 deletions

View File

@ -26,8 +26,11 @@ public class CodeTemplateInitListener implements ApplicationListener<Application
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
try {
log.info(" Init Code Generate Template [ 检测如果是JAR启动环境Copy模板到config目录 ] ");
long startTime = System.currentTimeMillis(); // 记录开始时间
log.info(" Init Code Generate Template [ 检测如果是JAR启动Copy模板到config目录 ] ");
this.initJarConfigCodeGeneratorTemplate();
long endTime = System.currentTimeMillis(); // 记录结束时间
log.info(" Init Code Generate Template completed in " + (endTime - startTime) + " ms"); // 计算并记录耗时
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -1,33 +1,33 @@
package org.jeecg.config.init;
import org.apache.catalina.Context;
import org.apache.tomcat.util.scan.StandardJarScanner;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Description: TomcatFactoryConfig
* @author: scott
* @date: 2021年01月25日 11:40
*/
@Configuration
public class TomcatFactoryConfig {
/**
* tomcat-embed-jasper引用后提示jar找不到的问题
*/
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
}
};
factory.addConnectorCustomizers(connector -> {
connector.setProperty("relaxedPathChars", "[]{}");
connector.setProperty("relaxedQueryChars", "[]{}");
});
return factory;
}
}
//package org.jeecg.config.init;
//
//import org.apache.catalina.Context;
//import org.apache.tomcat.util.scan.StandardJarScanner;
//import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * @Description: TomcatFactoryConfig
// * @author: scott
// * @date: 2021年01月25日 11:40
// */
//@Configuration
//public class TomcatFactoryConfig {
// /**
// * tomcat-embed-jasper引用后提示jar找不到的问题
// */
// @Bean
// public TomcatServletWebServerFactory tomcatFactory() {
// TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
// @Override
// protected void postProcessContext(Context context) {
// ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
// }
// };
// factory.addConnectorCustomizers(connector -> {
// connector.setProperty("relaxedPathChars", "[]{}");
// connector.setProperty("relaxedQueryChars", "[]{}");
// });
// return factory;
// }
//}

View File

@ -88,8 +88,10 @@ public class LoginController {
}
String lowerCaseCaptcha = captcha.toLowerCase();
// 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可
String origin = lowerCaseCaptcha+sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret();
String realKey = Md5Util.md5Encode(origin, "utf-8");
//update-begin---author:chenrui ---date:20250107 for[QQYUN-10775]验证码可以复用 #7674------------
String keyPrefix = Md5Util.md5Encode(sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret(), "utf-8");
String realKey = keyPrefix + lowerCaseCaptcha;
//update-end---author:chenrui ---date:20250107 for[QQYUN-10775]验证码可以复用 #7674------------
Object checkCode = redisUtil.get(realKey);
//当进入登录页时,有一定几率出现验证码错误 #1714
if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {
@ -533,10 +535,12 @@ public class LoginController {
//update-begin-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
// 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可
String origin = lowerCaseCode+key+jeecgBaseConfig.getSignatureSecret();
String realKey = Md5Util.md5Encode(origin, "utf-8");
//update-begin---author:chenrui ---date:20250107 for[QQYUN-10775]验证码可以复用 #7674------------
String keyPrefix = Md5Util.md5Encode(key+jeecgBaseConfig.getSignatureSecret(), "utf-8");
String realKey = keyPrefix + lowerCaseCode;
//update-end-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906
redisUtil.removeAll(keyPrefix);
//update-end---author:chenrui ---date:20250107 for[QQYUN-10775]验证码可以复用 #7674------------
redisUtil.set(realKey, lowerCaseCode, 60);
log.info("获取验证码Redis key = {}checkCode = {}", realKey, code);
//返回前端

View File

@ -101,7 +101,13 @@ public class SysRoleController {
public Result<IPage<SysRole>> queryPageList(SysRole role,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
@RequestParam(name="isMultiTranslate", required = false) Boolean isMultiTranslate,
HttpServletRequest req) {
//update-begin---author:wangshuai---date:2025-03-26---for:【issues/7948】角色解决根据id查询回显不对---
if(null != isMultiTranslate && isMultiTranslate){
pageSize = 100;
}
//update-end---author:wangshuai---date:2025-03-26---for:【issues/7948】角色解决根据id查询回显不对---
Result<IPage<SysRole>> result = new Result<IPage<SysRole>>();
//QueryWrapper<SysRole> queryWrapper = QueryGenerator.initQueryWrapper(role, req.getParameterMap());
//IPage<SysRole> pageList = sysRoleService.page(page, queryWrapper);

View File

@ -23,7 +23,11 @@ import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.mybatis.MybatisPlusSaasConfig;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.service.*;
import org.jeecg.modules.system.service.ISysTenantPackService;
import org.jeecg.modules.system.service.ISysTenantService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.service.ISysUserTenantService;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.vo.SysUserTenantVo;
import org.jeecg.modules.system.vo.tenant.TenantDepartAuthInfo;
import org.jeecg.modules.system.vo.tenant.TenantPackModel;

View File

@ -136,7 +136,7 @@
<!--根据用户id获取用户id和部门名称-->
<select id="getUserDepartByTenantUserId" resultType="org.jeecg.modules.system.vo.SysUserDepVo">
SELECT sd.depart_name, sud.user_id
SELECT sd.depart_name, sud.user_id, sd.id as deptId, sd.parent_id
FROM sys_depart sd
RIGHT JOIN sys_user_depart sud on sd.id = sud.dep_id and sd.del_flag = 0
WHERE sud.user_id IN

View File

@ -23,6 +23,20 @@
</otherwise>
</choose>
</if>
<!--增加id查询 for:【issues/7948】角色解决根据id查询回显不对-->
<if test="role.id!='' and role.id!=null">
<choose>
<when test="role.id.indexOf(',') != -1">
AND id in
<foreach item="item" index="index" collection="role.id.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</when>
<otherwise>
AND id = #{role.id}
</otherwise>
</choose>
</if>
order by create_time desc
</select>

View File

@ -43,8 +43,7 @@
<select id="queryTenantPackUserCount" resultType="org.jeecg.modules.system.vo.tenant.TenantPackUserCount">
SELECT pack_code, count(*) as user_count FROM sys_tenant_pack a
join sys_tenant_pack_user b on a.id = b.pack_id
join sys_user_tenant sut on a.tenant_id = sut.tenant_id and b.user_id = sut.user_id and sut.status = 1
where a.tenant_id = #{tenantId}
where a.tenant_id = #{tenantId} and b.tenant_id = #{tenantId}
and a.pack_code in ('superAdmin', 'accountAdmin', 'appAdmin')
and b.status = 1
group by a.pack_code

View File

@ -1,7 +1,7 @@
package org.jeecg.modules.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.system.entity.SysTenantPack;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.system.entity.SysTenantPackUser;
import java.util.List;

View File

@ -26,6 +26,7 @@ import org.jeecg.modules.system.vo.SysCommentVO;
import org.jeecg.modules.system.vo.UserAvatar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;

View File

@ -1,7 +1,6 @@
package org.jeecg.modules.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.TenantConstant;
@ -10,6 +9,7 @@ import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aop.TenantLog;
import org.jeecg.modules.system.entity.SysPackPermission;
import org.jeecg.modules.system.entity.SysTenant;
import org.jeecg.modules.system.entity.SysTenantPack;
import org.jeecg.modules.system.entity.SysTenantPackUser;
import org.jeecg.modules.system.mapper.SysPackPermissionMapper;
@ -20,6 +20,8 @@ import org.jeecg.modules.system.service.ISysTenantPackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;

View File

@ -55,6 +55,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@ -265,7 +266,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
@Transactional(rollbackFor = Exception.class)
public boolean deleteUser(String userId) {
//1.删除用户
//update-begin---author:wangshuai---date:2024-01-16---for:【QQYUN-7974】admin用户禁止删除---
//1.验证当前用户是管理员账号 admin
//验证用户是否为管理员
this.checkUserAdminRejectDel(userId);
//update-end---author:wangshuai---date:2024-01-16---for:【QQYUN-7974】admin用户禁止删除---
//2.删除用户
this.removeById(userId);
return false;
}
@ -274,7 +281,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@CacheEvict(value={CacheConstant.SYS_USERS_CACHE}, allEntries=true)
@Transactional(rollbackFor = Exception.class)
public boolean deleteBatchUsers(String userIds) {
//1.删除用户
//1.验证当前用户是管理员账号 admin
this.checkUserAdminRejectDel(userIds);
//2.删除用户
this.removeByIds(Arrays.asList(userIds.split(",")));
return false;
}
@ -875,7 +884,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
SysUserTenant userTenant = new SysUserTenant();
userTenant.setStatus(CommonConstant.USER_TENANT_QUIT);
userTenantMapper.update(userTenant,query);
//update-end---author:wangshuai ---date:20230111 for[QQYUN-3951]租户用户离职重构------------
}
@Override
@ -1901,7 +1909,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
}
@Override
public void changePhone(JSONObject json, String username) {
String smscode = json.getString("smscode");
@ -1935,7 +1942,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
userMapper.updateById(sysUser);
}
}
/**
* 验证手机号
*
@ -1955,7 +1962,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
//验证完成之后清空手机验证码
redisUtil.removeAll(phoneKey);
}
@Override
public void sendChangePhoneSms(JSONObject jsonObject, String username, String ipAddress) {
String type = jsonObject.getString("type");

View File

@ -12,4 +12,13 @@ import lombok.Data;
public class SysUserDepVo {
private String userId;
private String departName;
/**
* 部门id
*/
private String deptId;
/**
* 部门的父级id
*/
private String parentId;
}

View File

@ -208,7 +208,11 @@
exportConfig: {
name: "${tableVo.ftlDescription}",
url: getExportUrl,
<#if is_range>
params: setRangeQuery,
<#else>
params: queryParam,
</#if>
},
importConfig: {
url: getImportUrl,

View File

@ -234,7 +234,11 @@
exportConfig: {
name:"${tableVo.ftlDescription}",
url: getExportUrl,
<#if is_range>
params: setRangeQuery,
<#else>
params: queryParam,
</#if>
},
importConfig: {
url: getImportUrl,

View File

@ -213,7 +213,11 @@
exportConfig: {
name:"${tableVo.ftlDescription}",
url: getExportUrl,
<#if is_range>
params: setRangeQuery,
<#else>
params: queryParam,
</#if>
},
importConfig: {
url: getImportUrl,

View File

@ -36,7 +36,7 @@ public class FlywayConfig {
*/
@Value("${spring.flyway.enabled:false}")
private Boolean enabled;
/**
* 编码格式默认UTF-8
*/
@ -102,7 +102,7 @@ public class FlywayConfig {
if(!enabled){
return;
}
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
Map<String, DataSource> dataSources = ds.getDataSources();
dataSources.forEach((k, v) -> {

View File

@ -1,7 +1,11 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
# max-http-post-size: 10MB # 平替 tomcat server.tomcat.max-swallow-siz undertow该值默认为-1
worker-threads: 16 # 4核CPU标准配置
buffers:
websocket: 8192 # WebSocket缓冲 以字节为单位这里设置为8 KB
io: 16384 # IO操作缓冲 以字节为单位这里设置为16 KB
error:
include-exception: true
include-stacktrace: ALWAYS
@ -269,11 +273,6 @@ jeecg:
app-id: ??
api-key: ??
secret-key: ??
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas

View File

@ -1,7 +1,11 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
# max-http-post-size: 10MB # 平替 tomcat server.tomcat.max-swallow-siz undertow该值默认为-1
worker-threads: 16 # 4核CPU标准配置
buffers:
websocket: 8192 # WebSocket缓冲 以字节为单位这里设置为8 KB
io: 16384 # IO操作缓冲 以字节为单位这里设置为16 KB
error:
include-exception: true
include-stacktrace: ALWAYS
@ -230,11 +234,6 @@ jeecg:
password:
type: STANDALONE
enabled: true
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas

View File

@ -1,7 +1,11 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
# max-http-post-size: 10MB # 平替 tomcat server.tomcat.max-swallow-siz undertow该值默认为-1
worker-threads: 16 # 4核CPU标准配置
buffers:
websocket: 8192 # WebSocket缓冲 以字节为单位这里设置为8 KB
io: 16384 # IO操作缓冲 以字节为单位这里设置为16 KB
error:
include-exception: true
include-stacktrace: ALWAYS
@ -209,11 +213,6 @@ jeecg:
secretKey: ??
endpoint: oss-cn-beijing.aliyuncs.com
bucketName: jeecgdev
# ElasticSearch 6设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传

View File

@ -1,7 +1,7 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
worker-threads: 16
error:
include-exception: true
include-stacktrace: ALWAYS
@ -22,7 +22,7 @@ management:
spring:
flyway:
# 是否启用flyway
enabled: false
enabled: true
# 是否关闭要清除已有库下的表功能,生产环境必须为true,否则会删库,非常重要!!!
clean-disabled: true
servlet:
@ -230,11 +230,7 @@ jeecg:
SMS_465391221:
# 注册账号短信模板编码
SMS_175430166:
# ElasticSearch 设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 127.0.0.1:9200
check-enabled: false
SMS_461885023:
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传

View File

@ -1,7 +1,7 @@
server:
port: 8080
tomcat:
max-swallow-size: -1
undertow:
worker-threads: 16
error:
include-exception: true
include-stacktrace: ALWAYS
@ -22,9 +22,9 @@ management:
spring:
flyway:
# 是否启用flyway
enabled: false
# 是否关闭要清除已有库下的表功能,生产环境必须为true,否则会删库,非常重要!!!
clean-disabled: true
enabled: true
# 迁移sql脚本存放路径
locations: classpath:flyway/sql/mysql
servlet:
multipart:
max-file-size: 10MB
@ -270,11 +270,6 @@ jeecg:
app-id: ??
api-key: ??
secret-key: ??
# ElasticSearch 设置
elasticsearch:
cluster-name: jeecg-ES
cluster-nodes: 192.168.1.188:9200
check-enabled: false
#Mybatis输出sql日志
logging:
level:

View File

@ -1,47 +1,47 @@
//package org.jeecg;
//
//import com.alibaba.fastjson.JSONObject;
//import org.jeecg.common.util.RestUtil;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//
///**
// * @Description: TODO
// * @author: scott
// * @date: 2022年05月10日 14:02
// */
//public class TestMain {
// public static void main(String[] args) {
// // 请求地址
// String url = "https://api.boot.jeecg.com/sys/user/list";
// // 请求 Header 用于传递Token
// HttpHeaders headers = getHeaders();
// // 请求方式是 GET 代表获取数据
// HttpMethod method = HttpMethod.GET;
//
// System.out.println("请求地址:" + url);
// System.out.println("请求方式:" + method);
//
// // 利用 RestUtil 请求该url
// ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
// if (result != null && result.getBody() != null) {
// System.out.println("返回结果:" + result.getBody().toJSONString());
// } else {
// System.out.println("查询失败");
// }
// }
// private static HttpHeaders getHeaders() {
// String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.50h-g6INOZRVnznExiawFb1U6PPjcVVA4POeYRA5a5Q";
// System.out.println("请求Token" + token);
//
// HttpHeaders headers = new HttpHeaders();
// String mediaType = MediaType.APPLICATION_JSON_VALUE;
// headers.setContentType(MediaType.parseMediaType(mediaType));
// headers.set("Accept", mediaType);
// headers.set("X-Access-Token", token);
// return headers;
// }
//
//}
package org.jeecg;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.util.RestUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
/**
* @Description: TODO
* @author: scott
* @date: 2022年05月10日 14:02
*/
public class TestMain {
public static void main(String[] args) {
// 请求地址
String url = "https://api3.boot.jeecg.com/sys/user/list";
// 请求 Header 用于传递Token
HttpHeaders headers = getHeaders();
// 请求方式是 GET 代表获取数据
HttpMethod method = HttpMethod.GET;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
private static HttpHeaders getHeaders() {
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.50h-g6INOZRVnznExiawFb1U6PPjcVVA4POeYRA5a5Q";
System.out.println("请求Token" + token);
HttpHeaders headers = new HttpHeaders();
String mediaType = MediaType.APPLICATION_JSON_VALUE;
headers.setContentType(MediaType.parseMediaType(mediaType));
headers.set("Accept", mediaType);
headers.set("X-Access-Token", token);
return headers;
}
}

View File

@ -1,83 +0,0 @@
package org.jeecg.modules.system.test;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.JeecgSystemApplication;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.RestUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
/**
* 系统用户单元测试
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class)
public class InsertDemoTest {
/**
* 测试地址:实际使用时替换成你自己的地址
*/
private final String BASE_URL = "http://localhost:8080/jeecg-boot//test/jeecgDemo/";
//测试:用户名和密码
private final String USERNAME = "admin";
private final String PASSWORD = "123456";
@Autowired
private RedisUtil redisUtil;
/**
* 测试用例:新增
*/
@Test
public void testAdd() {
// 请求地址
String url = BASE_URL + "add" ;
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 POST 代表提交新增数据
HttpMethod method = HttpMethod.POST;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
for (int i = 0; i < 100; i++) {
String name = "李哈哈" + i;
JSONObject params = new JSONObject();
params.put("name", name);
System.out.println("请求参数:" + params.toJSONString());
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
}
private String getToken() {
String token = JwtUtil.sign(USERNAME, PASSWORD);
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
return token;
}
private HttpHeaders getHeaders() {
String token = this.getToken();
System.out.println("请求Token" + token);
HttpHeaders headers = new HttpHeaders();
String mediaType = MediaType.APPLICATION_JSON_VALUE;
headers.setContentType(MediaType.parseMediaType(mediaType));
headers.set("Accept", mediaType);
headers.set("X-Access-Token", token);
return headers;
}
}

View File

@ -6,10 +6,9 @@ import org.jeecg.modules.demo.test.entity.JeecgDemo;
import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper;
import org.jeecg.modules.demo.test.service.IJeecgDemoService;
import org.jeecg.modules.system.service.ISysDataLogService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.List;
@ -29,7 +28,7 @@ public class SampleTest {
public void testSelect() {
System.out.println(("----- selectAll method test ------"));
List<JeecgDemo> userList = jeecgDemoMapper.selectList(null);
Assertions.assertEquals(5, userList.size());
Assert.isTrue(15==userList.size(),"结果不是5条");
userList.forEach(System.out::println);
}

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.system.test;
import org.aspectj.lang.annotation.Before;
import org.jeecg.JeecgSystemApplication;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.config.JeecgBaseConfig;
@ -8,7 +9,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @Description: 系统表白名单测试

View File

@ -1,175 +0,0 @@
package org.jeecg.modules.system.test;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.JeecgSystemApplication;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.RestUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
/**
* 系统用户单元测试
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,classes = JeecgSystemApplication.class)
public class SysUserTest {
/**
* 测试地址:实际使用时替换成你自己的地址
*/
private final String BASE_URL = "http://localhost:8080/jeecg-boot/sys/user/";
//测试:用户名和密码
private final String USERNAME = "admin";
private final String PASSWORD = "123456";
@Autowired
private RedisUtil redisUtil;
/**
* 测试用例:查询记录
*/
@Test
public void testQuery() {
// 请求地址
String url = BASE_URL + "list";
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 GET 代表获取数据
HttpMethod method = HttpMethod.GET;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
/**
* 测试用例:新增
*/
@Test
public void testAdd() {
// 请求地址
String url = BASE_URL + "add" ;
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 POST 代表提交新增数据
HttpMethod method = HttpMethod.POST;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
JSONObject params = new JSONObject();
params.put("username", "wangwuTest");
params.put("password", "123456");
params.put("confirmpassword","123456");
params.put("realname", "单元测试");
params.put("activitiSync", "1");
params.put("userIdentity","1");
params.put("workNo","0025");
System.out.println("请求参数:" + params.toJSONString());
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
/**
* 测试用例:修改
*/
@Test
public void testEdit() {
// 数据Id
String dataId = "1331795062924374018";
// 请求地址
String url = BASE_URL + "edit";
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 PUT 代表提交修改数据
HttpMethod method = HttpMethod.PUT;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
JSONObject params = new JSONObject();
params.put("username", "wangwuTest");
params.put("realname", "单元测试1111");
params.put("activitiSync", "1");
params.put("userIdentity","1");
params.put("workNo","0025");
params.put("id",dataId);
System.out.println("请求参数:" + params.toJSONString());
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, params, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
/**
* 测试用例:删除
*/
@Test
public void testDelete() {
// 数据Id
String dataId = "1331795062924374018";
// 请求地址
String url = BASE_URL + "delete" + "?id=" + dataId;
// 请求 Header 用于传递Token
HttpHeaders headers = this.getHeaders();
// 请求方式是 DELETE 代表删除数据
HttpMethod method = HttpMethod.DELETE;
System.out.println("请求地址:" + url);
System.out.println("请求方式:" + method);
// 利用 RestUtil 请求该url
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, null, JSONObject.class);
if (result != null && result.getBody() != null) {
System.out.println("返回结果:" + result.getBody().toJSONString());
} else {
System.out.println("查询失败");
}
}
private String getToken() {
String token = JwtUtil.sign(USERNAME, PASSWORD);
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 60);
return token;
}
private HttpHeaders getHeaders() {
String token = this.getToken();
System.out.println("请求Token" + token);
HttpHeaders headers = new HttpHeaders();
String mediaType = MediaType.APPLICATION_JSON_VALUE;
headers.setContentType(MediaType.parseMediaType(mediaType));
headers.set("Accept", mediaType);
headers.set("X-Access-Token", token);
return headers;
}
}

View File

@ -1,5 +1,6 @@
package org.jeecg.smallTools;
import org.junit.jupiter.api.Test;
/**

View File

@ -2,11 +2,17 @@ package org.jeecg.smallTools;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.DateUtils;
import org.junit.jupiter.api.Test;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Base64;
import java.util.Date;
/**
* 字符串处理测试
@ -37,6 +43,23 @@ public class TestStr {
System.out.println("length = "+ conditionValueArray.length);
Arrays.stream(conditionValueArray).forEach(System.out::println);
}
@Test
public void getThisDate() {
LocalDate d = DateUtils.getLocalDate();
System.out.println(d);
}
@Test
public void firstDayOfLastSixMonths() {
LocalDate today = LocalDate.now(); // 获取当前日期
LocalDate firstDayOfLastSixMonths = today.minusMonths(6).withDayOfMonth(1); // 获取近半年的第一天
LocalDateTime firstDateTime = LocalDateTime.of(firstDayOfLastSixMonths, LocalTime.MIN); // 设置时间为当天的最小时间00:00:00
Date date = Date.from(firstDateTime.atZone(ZoneId.systemDefault()).toInstant()); // 将 LocalDateTime 转换为 Date
System.out.println("近半年的第一天的 00:00:00 时间戳:" + date);
}
@Test
public void testJSONArrayJoin() {
@ -67,7 +90,7 @@ public class TestStr {
*/
@Test
public void testSpecialChar() {
String str = "Hello, World! 你好这是一段特殊符号的测试This is a test string with special characters: @#$%^&*";
String str = "Hello, World! 你好这是一段特殊符号的测试This is__ a test string with special characters: @#$%^&*";
// 使用正则表达式替换特殊字符
String replacedStr = str.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", "");
System.out.println("Replaced String: " + replacedStr);