实现程序内静态页面跳转

实现dockerfile文件
This commit is contained in:
xiongfeng
2022-07-06 15:41:29 +08:00
parent 20fd8827af
commit 1c5e244a95
12 changed files with 130 additions and 30 deletions

14
Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
# java8运行环境
FROM openjdk:8-jdk-alpine
# 作者名称
MAINTAINER xiongfeng
# 切换工作目录
WORKDIR /root/java
# 添加demo-start-1.0.0.jar文件到docker环境内
ADD xf-boot-base.jar /root/java/xf-boot-base.jar
# 暴露端口8080
EXPOSE 8080
# 运行命令
ENTRYPOINT ["java", "-server", "-Xms512m", "-Xmx512m", "-jar", "/root/java/xf-boot-base.jar"]

12
pom.xml
View File

@@ -9,10 +9,10 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cn.xf</groupId>
<artifactId>spring-boot-base-demo</artifactId>
<artifactId>xf-boot-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-base-demo</name>
<description>spring-boot-base-demo</description>
<name>xf-boot-base</name>
<description>xf-boot-base</description>
<properties>
<java.version>1.8</java.version>
<mybatis-plus.version></mybatis-plus.version>
@@ -97,7 +97,11 @@
<version>2.0.8</version>
</dependency>
<!--访问templates文件下的静态资源-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>

View File

@@ -0,0 +1,36 @@
package cn.xf.basedemo.common.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* @program: xf-boot-base
* @ClassName ApplicationContextUtils
* @description:
* @author: xiongfeng
* @create: 2022-07-06 14:13
**/
@Component
public class ApplicationContextUtils implements ApplicationContextAware {
//放置在获取bean的时候提示空指针将其定义为静态变量
private static ApplicationContext context;
//类初始化完成之后调用setApplicationContext()方法进行操作
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ApplicationContextUtils.context = applicationContext;
}
public static ApplicationContext geteContext(){
return context;
}
public static Object getBean(String beanName){
//在这一步的时候一定要注意,此时可调用这个方法的时候
//context可能为空会提示空指针异常需要将其定义成静态的这样类加载的时候
//context就已经存在了
return context.getBean(beanName);
}
}

View File

@@ -0,0 +1,42 @@
package cn.xf.basedemo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @program: xf-boot-base
* @ClassName LoginController
* @description: 页面跳转转发控制器
* @author: xiongfeng
* @create: 2022-07-06 11:51
**/
@Controller
@RequestMapping("web")
public class LoginController {
/**
* @Description 进入登录页面
* @Author xiongfeng
* @Date 2022/7/6
* @Param []
* @return java.lang.String
**/
@RequestMapping(value = "/login")
public String login() {
return "login";
}
/**
* @Description 静态页面跳转统一入口
* @Author xiongfeng
* @Date 2022/7/6
* @Param [url]
* @return java.lang.String
**/
@RequestMapping(value = "/{url}")
public String skipUrl(@PathVariable(name = "url") String url) {
return url;
}
}

View File

@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @program: xf-boot-base
* @ClassName UserController
* @description:
* @description: 用户控制器
* @author: xiongfeng
* @create: 2022-06-28 09:17
**/

View File

@@ -19,6 +19,6 @@ public class InterceptorConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TokenInterceptor()) //登录逻辑拦截类
.addPathPatterns("/**") //需要拦截的请求(设置的全部拦截)
.excludePathPatterns("`/user/login","/user/register`"); //忽略的请求
.excludePathPatterns("/user/**","/web/**"); //忽略的请求
}
}

View File

@@ -1,9 +1,11 @@
package cn.xf.basedemo.interceptor;
import cn.xf.basedemo.common.model.LoginUser;
import cn.xf.basedemo.common.utils.ApplicationContextUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;
@@ -22,15 +24,15 @@ import java.util.concurrent.TimeUnit;
**/
public class TokenInterceptor implements HandlerInterceptor {
@Autowired
private StringRedisTemplate redisTemplate;
RedisTemplate<Object,Object> redisTemplate =
(RedisTemplate<Object,Object>) ApplicationContextUtils.getBean("redisTemplate");
@Autowired
private ObjectMapper objectMapper;
//不拦截的请求列表
private static final List<String> EXCLUDE_PATH_LIST = Arrays.asList("/user/login");
private static final List<String> EXCLUDE_PATH_LIST = Arrays.asList("/user/login","/web/login");
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@@ -43,8 +45,10 @@ public class TokenInterceptor implements HandlerInterceptor {
String token = request.getHeader("Authorization");
if(StringUtils.isEmpty(token))
token = request.getParameter("token");
String value = redisTemplate.opsForValue().get(token);
if(StringUtils.isEmpty(token)){
return false;
}
String value = (String) redisTemplate.opsForValue().get("token:" + token);
if(StringUtils.isEmpty(value)){
return false;
}

View File

@@ -63,6 +63,7 @@ public class UserServiceImpl implements UserService {
loginInfo = objectMapper.readValue(loginJson, LoginInfo.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
return RetObj.error("账号或密码错误");
}
if (StringUtils.isNotBlank(loginInfo.check())) {
return RetObj.error(loginInfo.check());

View File

@@ -42,20 +42,20 @@ global:
rsaPrivateKey: MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL8XlRALVBay7dCwRJAHP0z4YMD0C2bSpVK_AizLnryXJEuL6erdW--eaCuUvjJNueAXPJ9vYOfflw0IewG8hoa4Jjf8-nM-ozNWnGvZCUSSERf1q2clDWtZ7FLxB5m0-OmIjChCsKFPNeMP-xhSQOupLKQWmXKK9_Q1I7ZaoIF3AgMBAAECgYBxTUA61Ry0oL7U_86HP2TO9G4ZuhmQi9EucMaPXOPvmgYRLRIzCbDbMKc_P-BN3zwYnG57cgSZNz9OoPqeGvP_oVTnkoEpVkCSV-JP2p_DK09LdbDqszJXMrxAkPmWGUw8IRMcTJT1xJJcgzFE6T0CmTo-Vk47AnmqfJD4U6o74QJBAPRjVUJKZnrMSnSqKPDL2ThgTo8h7-KFxl_Z-g724lTOFiCmBpi6nCWAcuacFRrrYqxF-r9c4zdIyR7AvLROql8CQQDIK_kRF52dVtwShciZhyeUBLoi0nWV9F8mMGt60NTEER9zPEgPsv2aVn8h97KMWOwmd2Da4EPm25QxOuaKQC_pAkBczcfXp5co9KElkmR_pHl1jiTm97U3qSM-zPDHc_tYxvXiKgoBP4QCPbfkWMsu8MoEr4Jb3vMt0EcHlZtTQTgzAkAfmNla-lhV4sUgY1_T5EK6GbjsED6hag6u74u3ukkrnexR-10ApWdkumydBwV3I_464DM4uZfeVCDjWIHVpuYpAkEA6QLPztGD4V8Q1PqTEeSF3i68CKPM8vO1_mCH2JD7qsqDQcIKkczj5rTg7hlOKwB9V6gSw4CbnOF6moTooRD-cQ
##redis
redis:
datasource:
token:
database: 1
host: 122.112.153.128
port: 6379
password: 'redis'
lettuce:
pool:
max-active: 8
max-wait: -1ms
max-idle: 8
min-idle: 0
timeout: 3000ms
#redis:
# datasource:
# token:
# database: 1
# host: 122.112.153.128
# port: 6379
# password: 'redis'
# lettuce:
# pool:
# max-active: 8
# max-wait: -1ms
# max-idle: 8
# min-idle: 0
# timeout: 3000ms
#oss:
# name: alioss

View File

@@ -6,7 +6,7 @@ spring:
profiles:
active: dev
application:
name: spring-boot-base-demo
name: xf-boot-base
servlet:
multipart:
max-file-size: 20MB

View File

@@ -24,7 +24,6 @@
<script src="https://cdn.bootcdn.net/ajax/libs/jsencrypt/3.2.1/jsencrypt.min.js"></script>
<!--http 请求插件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue-router/4.1.0-beta.2/vue-router.js"></script>
<div id="app">
@@ -63,8 +62,8 @@
var data = response.data;
if (data.code == 200) {
//中文需要进行两次encodeURI转码( encodeURI:把URI字符串采用UTF-8编码格式转化成escape格式的字符串)
var param = "?token=" + data.data.token + "&name=" + encodeURI(encodeURI(data.data.name));
window.location.href ="success.html" + param
var param = "?token=" + data.data.token + "&name=" + encodeURI(encodeURI(data.data.name));
window.location.href = "success" + param
} else {
alert(data.message)
}

View File

@@ -22,7 +22,7 @@
el: '#app',
data: {
token: '',
name:''
name: ''
},
mounted: function () {
this.token = this.getData("token");