cors开启

This commit is contained in:
guo 2023-10-30 18:38:48 +08:00
parent 3d7bb21968
commit 3fe7e97b71
6 changed files with 28 additions and 13 deletions

View File

@ -100,7 +100,7 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
int pageSize = Integer.parseInt(map.getOrDefault("pageSize", 10).toString());
Page<EntityMap> page = new Page<>(pageNo, pageSize);
List<EntityMap> list = companyMapper.selectCompanyPage(page, map);
List<EntityMap> list = companyMapper.selectCompanyPage(page, map);
for (EntityMap entityMap : list) {
if (entityMap.get("expireTime") == null) {

View File

@ -4,16 +4,20 @@
<select id="queryDevAndNewestData" resultType="com.zhgd.xmgl.modules.sewage.entity.SewageData">
select max(d.ph_value) as ph_value,
max(d.turbidity_value) as turbidity_value,
max(d.conductivity) as conductivity,
max(d.dissolved_oxygen) as dissolved_oxygen,
max(d.water_temperature) as water_temperature,
max(d.flow_velocity) as flow_velocity,
max(d.water_level) as water_level,
sd.dev_sn,
sd.dev_name,
max(d.create_date) as create_date
max(d.conductivity) as conductivity,
max(d.dissolved_oxygen) as dissolved_oxygen,
max(d.water_temperature) as water_temperature,
max(d.flow_velocity) as flow_velocity,
max(d.water_level) as water_level,
sd.dev_sn,
sd.dev_name,
max(d.create_date) as create_date
from sewage_data d
right join sewage_dev sd on d.dev_sn = sd.dev_sn
right join sewage_dev sd on d.dev_sn = sd.dev_sn
where 1 = 1
<if test="devSn != null and devSn != ''">
and sd.dev_sn = #{devSn}
</if>
group by sd.dev_sn
</select>
</mapper>

View File

@ -31,7 +31,7 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Se
log.info("认证失败:" + authException.getMessage() + "--请求路径:" + request.getRequestURL());
response.setStatus(401);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.setContentType("application/json;charset=UTF-8");
PrintWriter printWriter = response.getWriter();
JSONObject resParam = new JSONObject();
resParam.put("message", authException.getMessage());

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.IdUtil;
import com.zhgd.exception.CustomException;
import com.zhgd.redis.lock.RedisRepository;
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
import com.zhgd.xmgl.util.EnvironmentUtil;
import io.jsonwebtoken.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -32,7 +33,7 @@ public class JwtTokenProvider {
private Integer userTokenExpireMinute;
@Autowired
private RedisRepository redisRepository;
private static final String USER_TOKEN_EXPIRE_PREFIX = "USER_TOKEN_EXPIRE:";
private final String USER_TOKEN_EXPIRE_PREFIX = "USER_TOKEN_EXPIRE:" + EnvironmentUtil.activeEnvironment + ":";
private static ConcurrentHashMap<String, String> userMap = new ConcurrentHashMap<>();
@Autowired

View File

@ -246,6 +246,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(HttpMethod.OPTIONS, "/**").anonymous()
.anyRequest().authenticated() // 剩下所有的验证都需要验证
.and()
//设置跨域, 如果不设置, 即使配置了filter, 也不会生效
.cors()
.and()
// 禁用 Spring Security 自带的跨域处理
.csrf().disable()
// 授权异常

View File

@ -12,8 +12,15 @@ import java.util.stream.Stream;
@Component
@Slf4j
public class EnvironmentUtil {
/**
* 激活的环境
*/
public static String activeEnvironment;
@Value("${active.environment.name}")
private String activeEnvironment;
public void setActiveEnvironment(String activeEnvironment) {
EnvironmentUtil.activeEnvironment = activeEnvironment;
}
/**
* 是否本地开发环境