ibase4j-1.3.0
業務框架上前後端分離,前後臺獨立的web,service可以分佈式部署,token和session放緩存
要跑起來略繁瑣,起activeMQ、redis、zookeeper、nginx,本地搭建就可以
DubboBaseConfig.java
支持Swagger-bootstrapUI
web工程的pom.xml修改如下:
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency><!-- 不要springfox-swagger-ui -->
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
修改SwaggerConfig
// @Bean
// public Docket platformApi() {
// return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).forCodeGeneration(true);
// }
@Bean
public Docket platformApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo()).forCodeGeneration(true)
.select()
.build()
.securitySchemes(Lists.<SecurityScheme>newArrayList(appKey()));
}
private ApiKey appKey() {
return new ApiKey("token", "token", "header");//用於設置token
}
WebConfig.java代碼修改如下:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// super.addInterceptors(registry);
// registry.addInterceptor(new TokenInterceptor()).addPathPatterns("/**").excludePathPatterns("/*.ico",
// "/*/api-docs", "/swagger**", "/swagger-resources/**", "/webjars/**", "/configuration/**");
// }
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new TokenInterceptor())
.addPathPatterns("/**")
// .excludePathPatterns("/user/login")
.excludePathPatterns("/*.ico","/swagger-resources/**", "/webjars/**", "/swagger**", "/v2/api-docs/**", "/doc.html/**", "/configuration/**");//登錄攔截器
super.addInterceptors(registry);
}
WebMvcConfig.java類增加以下資源映射
// 資源重定向(僅作爲後臺使用不提供靜態資源)
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("upload/**").addResourceLocations("/WEB-INF/upload/");
// registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/**").addResourceLocations("/WEB-INF/", "classpath:/META-INF/resources/",
"classpath:/resources/", "classpath:/static/", "classpath:/public/");
}
過濾器排除doc.html(還用過濾器?)
@Bean
public FilterRegistrationBean<CsrfFilter> csrfFilterRegistration() {
FilterRegistrationBean<CsrfFilter> registration = new FilterRegistrationBean<CsrfFilter>(new CsrfFilter());
registration.setName("csrfFilter");
registration.addUrlPatterns("/*");
registration.addInitParameter("excludedPages", "/doc.html");
registration.setOrder(3);
return registration;
}
CsrfFilter.java修改,排除對doc.html的校驗
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
HttpServletRequest req = (HttpServletRequest)request;
String referurl = req.getHeader("Referer");
String url = req.getRequestURL().toString();
// 獲取請求url地址
boolean isExcludedPage = false;
for (String page : excludedPageArray) {//判斷是否在過濾url之外
if(url.endsWith(page) || referurl.endsWith(page)){
isExcludedPage = true;
break;
}
}
if (isExcludedPage) {//在過濾url之外
chain.doFilter(request, response);
return;
}
新版Swagger-boostrapui1.9.6已經有通用設置了
配置一下nginx
#nginx-1.14.2
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 9088;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# 靜態頁面目錄
root D:\git\iBase4J\iBase4J-UI\iBase4J-UI-AngularJS\src;
# 默認首頁
index index.html;
#訪問後臺web成功
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 用戶瀏覽器端的緩存設置
location ~* \.(css|js|jpg|jpeg|gif|png|swf|htm|html|json|xml|svg|woff|ttf|eot|map|ico)$ {
expires 1h;
if (-f $request_filename) {
break;
}
}
# 動態頁面,交給tomcat處理
if ( !-e $request_filename) {
proxy_pass http://127.0.0.1:8088;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#訪問前臺web
server {
listen 9090;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# 靜態頁面目錄
root D:\git\iBase4J\iBase4J-UI\iBase4J-UI-AngularJS\src;
# 默認首頁
index index.html;
#用於訪問Sys-web接口,但是菜單出不來仍然還是不成功,以後有時間再搞 TODO:TODO
location ~* /user/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 用戶瀏覽器端的緩存設置
location ~* \.(css|js|jpg|jpeg|gif|png|swf|htm|html|json|xml|svg|woff|ttf|eot|map|ico)$ {
expires 1h;
if (-f $request_filename) {
break;
}
}
# 動態頁面,交給tomcat處理
if ( !-e $request_filename) {
proxy_pass http://127.0.0.1:8088;
}
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 用戶瀏覽器端的緩存設置
location ~* \.(css|js|jpg|jpeg|gif|png|swf|htm|html|json|xml|svg|woff|ttf|eot|map|ico)$ {
expires 1h;
if (-f $request_filename) {
break;
}
}
# 動態頁面,交給tomcat處理
if ( !-e $request_filename) {
proxy_pass http://127.0.0.1:8090;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#訪問前臺文檔成功:swagger-bootstrapui
server {
listen 9095;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location = /doc.html {
proxy_pass http://127.0.0.1:8090;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
#proxy_set_header Referer 'http://localhost:8090/';
proxy_redirect off;
}
location ~* /*{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8090;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
啓動服務前,按需要修改csrfWhite.txt增加如下內容
http://localhost/
http://localhost:9088/
http://localhost:9085/
http://localhost:9090/
http://localhost:9095/
Swagger可以訪問後,再註冊前臺
SignInterceptor.java屏蔽簽名
1、短信驗證
發短信驗證碼功能,修改SendMsgServiceImpl.java注掉try{邏輯,做一個簡單的setParams(sendMsg);調用在sendRandomCode裏面獲取驗證碼
2、手機註冊
TMember.java新增了三個字段,sql腳本沒有這三個字段,update操作會報錯。
3、會員登錄
會員登錄操作要調Fastdfs存圖片,修改MemberServiceImpl.java注掉if (result != null) {邏輯
loginController.js這個貌似也有點問題
angular.module('app')
.controller('loginController',[ '$rootScope', '$scope', '$http', '$state', function($rootScope, $scope, $http, $state) {
$scope.user = {};
$scope.login = function () {
var u = $scope.user;
u.password = hex_md5(u.password);
$.ajax({
type: 'POST',
url : '/usr/login',
data: u
}).then(function(result) {
if (result.code == 200) {
$state.go('main.sys.user.list');
} else {
$scope.msg = result.msg;
$rootScope.$apply();
}
});
}
} ]);