Compare commits
merge into: wanglin:test
wanglin:master
wanglin:test
pull from: wanglin:master
wanglin:master
wanglin:test
5 Commits
Author | SHA1 | Message | Date |
---|---|---|---|
|
9256ca002e |
维护redis前缀,修复删除redis所有数据问题
|
5 months ago |
|
7bd83035d2 |
修改正式环境的token解析地址
|
5 months ago |
|
4d22067947 |
Merge remote-tracking branch 'origin/master'
|
5 months ago |
|
f9e1af4f51 |
修改空指针
|
5 months ago |
|
b161c67b95 |
上传文件至 'src/main/java/com/lh/config'
解决跨域问题 |
5 months ago |
9 changed files with 113 additions and 42 deletions
-
5pom.xml
-
9src/main/java/com/lh/bean/RedisKey.java
-
35src/main/java/com/lh/config/CORSFilter.java
-
16src/main/java/com/lh/config/CandidateCacheRepository.java
-
7src/main/java/com/lh/controller/VoteController.java
-
2src/main/java/com/lh/exception/MyException.java
-
14src/main/java/com/lh/service/VoteServiceImpl.java
-
53src/main/java/com/lh/until/Utils.java
-
2src/main/resources/application.properties
@ -0,0 +1,9 @@ |
|||||
|
package com.lh.bean; |
||||
|
|
||||
|
|
||||
|
public interface RedisKey { |
||||
|
String KEY_PREFIX = "homilychart-vote-"; |
||||
|
String CACHE_KEY_VOTE_COUNT = KEY_PREFIX + "vote_count:"; |
||||
|
String CACHE_KEY_VOTE_STATUE = KEY_PREFIX + "vote_status:"; |
||||
|
String CACHE_KEY_CANDIDATE = KEY_PREFIX + "candidate:"; |
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package com.lh.config; |
||||
|
|
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.servlet.*; |
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
@Component |
||||
|
public class CORSFilter implements Filter { |
||||
|
|
||||
|
@Override |
||||
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
||||
|
throws IOException, ServletException { |
||||
|
HttpServletResponse res = (HttpServletResponse) response; |
||||
|
res.addHeader("Access-Control-Allow-Credentials", "true"); |
||||
|
res.addHeader("Access-Control-Allow-Origin", "*"); |
||||
|
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); |
||||
|
res.addHeader("Access-Control-Allow-Headers", "*"); |
||||
|
if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) { |
||||
|
response.getWriter().println("ok"); |
||||
|
return; |
||||
|
} |
||||
|
chain.doFilter(request, response); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void destroy() { |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void init(FilterConfig filterConfig) { |
||||
|
} |
||||
|
} |
@ -1,6 +1,6 @@ |
|||||
package com.lh.exception; |
package com.lh.exception; |
||||
|
|
||||
public class MyException extends Exception{ |
|
||||
|
public class MyException extends RuntimeException { |
||||
public MyException(String msg) { |
public MyException(String msg) { |
||||
super(msg); |
super(msg); |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue