mirror of https://gitee.com/maxjhandsome/pig
feat: 动态路由、客户端管理
This commit is contained in:
parent
5dae96f425
commit
ca084859fa
|
@ -1,26 +0,0 @@
|
|||
package com.github.pig.auth.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/28
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "auth")
|
||||
public class AuthServerConfig {
|
||||
private List<AuthServer> clients = new ArrayList<>();
|
||||
|
||||
@Data
|
||||
class AuthServer {
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String scope;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.github.pig.common.bean.config;
|
|||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -14,6 +15,7 @@ import java.util.List;
|
|||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConditionalOnExpression("!'${ignore}'.isEmpty()")
|
||||
@ConfigurationProperties(prefix = "ignore")
|
||||
public class FilterIgnorePropertiesConfig {
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package com.github.pig.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
import com.baomidou.mybatisplus.annotations.TableField;
|
||||
import com.baomidou.mybatisplus.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 动态路由配置表
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_zuul_route")
|
||||
public class SysZuulRoute extends Model<SysZuulRoute> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* router Id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
@TableField("service_id")
|
||||
private String serviceId;
|
||||
/**
|
||||
* url代理
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 转发去掉前缀
|
||||
*/
|
||||
@TableField("strip_prefix")
|
||||
private String stripPrefix;
|
||||
/**
|
||||
* 是否重试
|
||||
*/
|
||||
private String retryable;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private String enabled;
|
||||
/**
|
||||
* 敏感请求头
|
||||
*/
|
||||
@TableField("sensitiveHeaders_list")
|
||||
private String sensitiveheadersList;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 删除标识(0-正常,1-删除)
|
||||
*/
|
||||
@TableField("del_flag")
|
||||
private String delFlag;
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.github.pig.common.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/5/15
|
||||
* 自定义路由实体
|
||||
*/
|
||||
@Data
|
||||
public class ZuulRouteVO {
|
||||
/**
|
||||
* router ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* The path (pattern) for the route, e.g. /foo/**.
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* The service ID (if any) to map to this route. You can specify a physical URL or
|
||||
* a service, but not both.
|
||||
*/
|
||||
private String serviceId;
|
||||
|
||||
/**
|
||||
* A full physical URL to map to the route. An alternative is to use a service ID
|
||||
* and service discovery to find the physical address.
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Flag to determine whether the prefix for this route (the path, minus pattern
|
||||
* patcher) should be stripped before forwarding.
|
||||
*/
|
||||
private boolean stripPrefix = true;
|
||||
|
||||
/**
|
||||
* Flag to indicate that this route should be retryable (if supported). Generally
|
||||
* retry requires a service ID and ribbon.
|
||||
*/
|
||||
private Boolean retryable;
|
||||
|
||||
/**
|
||||
* 是否开启
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 微服务敏感的header
|
||||
*/
|
||||
private String sensitiveHeadersList;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.github.pig.gateway;
|
||||
|
||||
import com.github.pig.gateway.component.config.DynamicRouteLocator;
|
||||
import com.github.pig.gateway.feign.ZuulRouteService;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
|
||||
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/5/15
|
||||
* 动态路由配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class DynamicRouteConfiguration {
|
||||
private Registration registration;
|
||||
private DiscoveryClient discovery;
|
||||
private ZuulProperties zuulProperties;
|
||||
private ServerProperties server;
|
||||
private ZuulRouteService zuulRouteService;
|
||||
|
||||
public DynamicRouteConfiguration(ZuulRouteService zuulRouteService, Registration registration, DiscoveryClient discovery, ZuulProperties zuulProperties, ServerProperties server) {
|
||||
this.registration = registration;
|
||||
this.discovery = discovery;
|
||||
this.zuulProperties = zuulProperties;
|
||||
this.server = server;
|
||||
this.zuulRouteService = zuulRouteService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DynamicRouteLocator dynamicRouteLocator() {
|
||||
return new DynamicRouteLocator(server.getServletPrefix()
|
||||
, discovery
|
||||
, zuulProperties
|
||||
, registration
|
||||
, zuulRouteService);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package com.github.pig.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
|
@ -9,6 +11,7 @@ import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
|
@ -42,4 +45,9 @@ public class PigGatewayApplication {
|
|||
LoadBalancerInterceptor loadBalancerInterceptor(LoadBalancerClient loadBalance){
|
||||
return new LoadBalancerInterceptor(loadBalance);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package com.github.pig.gateway.component.config;
|
||||
|
||||
import com.github.pig.common.constant.ServiceNameConstant;
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
import com.github.pig.gateway.feign.ZuulRouteService;
|
||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||
import com.xiaoleilu.hutool.util.ArrayUtil;
|
||||
import com.xiaoleilu.hutool.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator;
|
||||
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
|
||||
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/5/15
|
||||
* 动态路由实现
|
||||
*/
|
||||
@Slf4j
|
||||
public class DynamicRouteLocator extends DiscoveryClientRouteLocator {
|
||||
private ZuulProperties properties;
|
||||
private RestTemplate restTemplate;
|
||||
private ZuulRouteService zuulRouteService;
|
||||
|
||||
public DynamicRouteLocator(String servletPath, DiscoveryClient discovery, ZuulProperties properties, ServiceInstance localServiceInstance, ZuulRouteService zuulRouteService) {
|
||||
super(servletPath, discovery, properties, localServiceInstance);
|
||||
this.properties = properties;
|
||||
this.zuulRouteService = zuulRouteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写路由配置
|
||||
* <p>
|
||||
* 1. properties 配置。
|
||||
* 2. eureka 默认配置。
|
||||
* 3. DB数据库配置。
|
||||
*
|
||||
* @return 路由表
|
||||
*/
|
||||
@Override
|
||||
protected LinkedHashMap<String, ZuulProperties.ZuulRoute> locateRoutes() {
|
||||
LinkedHashMap<String, ZuulProperties.ZuulRoute> routesMap = new LinkedHashMap<>();
|
||||
//读取properties配置、eureka默认配置
|
||||
routesMap.putAll(super.locateRoutes());
|
||||
log.info("初始默认的路由配置完成");
|
||||
routesMap.putAll(locateRoutesFromDb());
|
||||
LinkedHashMap<String, ZuulProperties.ZuulRoute> values = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, ZuulProperties.ZuulRoute> entry : routesMap.entrySet()) {
|
||||
String path = entry.getKey();
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path;
|
||||
}
|
||||
if (StrUtil.isNotBlank(this.properties.getPrefix())) {
|
||||
path = this.properties.getPrefix() + path;
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path;
|
||||
}
|
||||
}
|
||||
values.put(path, entry.getValue());
|
||||
}
|
||||
return routesMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉去路由配置先采用RestTemplate 加载eureka中信息来是实现
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Map<String, ZuulProperties.ZuulRoute> locateRoutesFromDb() {
|
||||
Map<String, ZuulProperties.ZuulRoute> routes = new LinkedHashMap<>();
|
||||
|
||||
String url = String.format("http://localhost:4000/route/findAllZuulRoute", ServiceNameConstant.UMPS_SERVICE);
|
||||
SysZuulRoute[] response = restTemplate.getForObject(url, SysZuulRoute[].class);
|
||||
if (ArrayUtil.isEmpty(response)) {
|
||||
return routes;
|
||||
}
|
||||
|
||||
for (SysZuulRoute result : response) {
|
||||
if (StrUtil.isBlank(result.getPath()) || StrUtil.isBlank(result.getUrl())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ZuulProperties.ZuulRoute zuulRoute = new ZuulProperties.ZuulRoute();
|
||||
try {
|
||||
zuulRoute.setId(String.valueOf(result.getId()));
|
||||
zuulRoute.setPath(result.getPath());
|
||||
zuulRoute.setServiceId(result.getServiceId());
|
||||
zuulRoute.setRetryable(StrUtil.equals(result.getRetryable(), "0") ? Boolean.FALSE : Boolean.TRUE);
|
||||
zuulRoute.setStripPrefix(StrUtil.equals(result.getStripPrefix(), "0") ? Boolean.FALSE : Boolean.TRUE);
|
||||
zuulRoute.setUrl(result.getUrl());
|
||||
List<String> sensitiveHeadersList = StrUtil.splitTrim(result.getSensitiveheadersList(), ",");
|
||||
if (CollUtil.isNotEmpty(sensitiveHeadersList)) {
|
||||
Set<String> sensitiveHeaderSet = CollUtil.newHashSet();
|
||||
sensitiveHeadersList.forEach(sensitiveHeader -> sensitiveHeaderSet.add(sensitiveHeader));
|
||||
zuulRoute.setSensitiveHeaders(sensitiveHeaderSet);
|
||||
zuulRoute.setCustomSensitiveHeaders(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("从数据库加载路由配置异常", e);
|
||||
}
|
||||
log.info("添加数据库自定义的路由配置,path:{},serviceId:{}", zuulRoute.getPath(), zuulRoute.getServiceId());
|
||||
routes.put(zuulRoute.getPath(), zuulRoute);
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,18 @@
|
|||
package com.github.pig.gateway.component.config;
|
||||
|
||||
import com.github.pig.common.bean.config.FilterIgnorePropertiesConfig;
|
||||
import com.github.pig.gateway.component.filter.ValidateCodeFilter;
|
||||
import com.github.pig.gateway.component.handler.PigAccessDeniedHandler;
|
||||
import com.github.pig.gateway.feign.ZuulRouteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
|
||||
import org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
@ -15,6 +21,7 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.E
|
|||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/27
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package com.github.pig.gateway.feign;
|
||||
|
||||
import com.github.pig.common.vo.UserVO;
|
||||
import com.github.pig.gateway.feign.fallback.UserServiceFallbackImpl;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/31
|
||||
*/
|
||||
@FeignClient(name = "pig-upms-service", fallback = UserServiceFallbackImpl.class)
|
||||
public interface UserService {
|
||||
/**
|
||||
* 通过用户名查询用户、角色信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return UserVo
|
||||
*/
|
||||
@GetMapping("/user/findUserByUsername/{username}")
|
||||
UserVO findUserByUsername(@PathVariable("username") String username);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.github.pig.gateway.feign;
|
||||
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
import com.github.pig.gateway.feign.fallback.MenuServiceFallbackImpl;
|
||||
import com.github.pig.gateway.feign.fallback.ZuulRouteServiceFallbackImpl;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/5/15
|
||||
* 远程获取zuul配置
|
||||
*/
|
||||
@FeignClient(name = "pig-upms-service", fallback = ZuulRouteServiceFallbackImpl.class)
|
||||
public interface ZuulRouteService {
|
||||
/**
|
||||
* 调用upms查询全部的路由配置
|
||||
*
|
||||
* @return 路由配置表
|
||||
*/
|
||||
@GetMapping(value = "/route/findAllZuulRoute")
|
||||
List<SysZuulRoute> findAllZuulRoute();
|
||||
}
|
|
@ -2,6 +2,8 @@ package com.github.pig.gateway.feign.fallback;
|
|||
|
||||
import com.github.pig.common.vo.MenuVO;
|
||||
import com.github.pig.gateway.feign.MenuService;
|
||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -14,12 +16,12 @@ import java.util.Set;
|
|||
* why add @Service when i up version ?
|
||||
* https://github.com/spring-cloud/spring-cloud-netflix/issues/762
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MenuServiceFallbackImpl implements MenuService {
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@Override
|
||||
public Set<MenuVO> findMenuByRole(String role) {
|
||||
logger.error("调用{}异常{}","findMenuByRole",role);
|
||||
return null;
|
||||
log.error("调用{}异常{}","findMenuByRole",role);
|
||||
return CollUtil.newHashSet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package com.github.pig.gateway.feign.fallback;
|
||||
|
||||
import com.github.pig.common.vo.UserVO;
|
||||
import com.github.pig.gateway.feign.UserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2017/10/31
|
||||
* 用户服务的fallback
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceFallbackImpl implements UserService {
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public UserVO findUserByUsername(String username) {
|
||||
logger.error("调用{}异常:{}", "findUserByUsername", username);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.github.pig.gateway.feign.fallback;
|
||||
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
import com.github.pig.common.vo.MenuVO;
|
||||
import com.github.pig.gateway.feign.MenuService;
|
||||
import com.github.pig.gateway.feign.ZuulRouteService;
|
||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/5/15
|
||||
* 远程调用路由接口异常回调
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ZuulRouteServiceFallbackImpl implements ZuulRouteService {
|
||||
|
||||
/**
|
||||
* 调用upms查询全部的路由配置
|
||||
*
|
||||
* @return 路由配置表
|
||||
*/
|
||||
@Override
|
||||
public List<SysZuulRoute> findAllZuulRoute() {
|
||||
log.error("获取远程路由配置失败");
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ public class PigResourcesGenerator {
|
|||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String outputDir = "/Users/lengleng/work/source";
|
||||
String outputDir = "/Users/lengleng/work/temp";
|
||||
final String viewOutputDir = outputDir + "/view/";
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
// 全局配置
|
||||
|
@ -48,7 +48,7 @@ public class PigResourcesGenerator {
|
|||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("lengleng");
|
||||
dsc.setUrl("jdbc:mysql://106.14.69.75:3309/pig?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false");
|
||||
dsc.setUrl("jdbc:mysql://139.224.200.249:3309/pig?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false");
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 策略配置
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package com.github.pig.admin.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.pig.admin.model.entity.SysOauthClientDetails;
|
||||
import com.github.pig.common.util.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.github.pig.common.util.Query;
|
||||
import com.github.pig.admin.service.SysOauthClientDetailsService;
|
||||
import com.github.pig.common.web.BaseController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/client")
|
||||
public class OauthClientDetailsController extends BaseController {
|
||||
@Autowired
|
||||
private SysOauthClientDetailsService sysOauthClientDetailsService;
|
||||
|
||||
/**
|
||||
* 通过ID查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return SysOauthClientDetails
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public SysOauthClientDetails get(@PathVariable Integer id) {
|
||||
return sysOauthClientDetailsService.selectById(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param params 分页对象
|
||||
* @return 分页对象
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public Page page(@RequestParam Map<String, Object> params) {
|
||||
return sysOauthClientDetailsService.selectPage(new Query<>(params), new EntityWrapper<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysOauthClientDetails 实体
|
||||
* @return success/false
|
||||
*/
|
||||
@PostMapping
|
||||
public R<Boolean> add(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
|
||||
return new R<>(sysOauthClientDetailsService.insert(sysOauthClientDetails));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id ID
|
||||
* @return success/false
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public R<Boolean> delete(@PathVariable String id) {
|
||||
SysOauthClientDetails sysOauthClientDetails = new SysOauthClientDetails();
|
||||
sysOauthClientDetails.setClientId(id);
|
||||
return new R<>(sysOauthClientDetailsService.deleteById(sysOauthClientDetails));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysOauthClientDetails 实体
|
||||
* @return success/false
|
||||
*/
|
||||
@PutMapping
|
||||
public R<Boolean> edit(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
|
||||
return new R<>(sysOauthClientDetailsService.updateById(sysOauthClientDetails));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.github.pig.admin.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Date;
|
||||
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
import com.github.pig.common.util.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.github.pig.common.constant.CommonConstant;
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.github.pig.common.util.Query;
|
||||
import com.github.pig.admin.service.SysZuulRouteService;
|
||||
import com.github.pig.common.web.BaseController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 动态路由配置表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/route")
|
||||
public class ZuulRouteController extends BaseController {
|
||||
@Autowired
|
||||
private SysZuulRouteService sysZuulRouteService;
|
||||
|
||||
/**
|
||||
* 通过ID查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return SysZuulRoute
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public SysZuulRoute get(@PathVariable Integer id) {
|
||||
return sysZuulRouteService.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部路由配置
|
||||
*
|
||||
* @return 路由配置表
|
||||
*/
|
||||
@GetMapping("/findAllZuulRoute")
|
||||
public List<SysZuulRoute> findAllZuulRoute() {
|
||||
return sysZuulRouteService.selectList(new EntityWrapper<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询信息
|
||||
*
|
||||
* @param params 分页对象
|
||||
* @return 分页对象
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public Page page(@RequestParam Map<String, Object> params) {
|
||||
params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
|
||||
return sysZuulRouteService.selectPage(new Query<>(params), new EntityWrapper<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param sysZuulRoute 实体
|
||||
* @return success/false
|
||||
*/
|
||||
@PostMapping
|
||||
public R<Boolean> add(@RequestBody SysZuulRoute sysZuulRoute) {
|
||||
return new R<>(sysZuulRouteService.insert(sysZuulRoute));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id ID
|
||||
* @return success/false
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public R<Boolean> delete(@PathVariable Integer id) {
|
||||
SysZuulRoute sysZuulRoute = new SysZuulRoute();
|
||||
sysZuulRoute.setId(id);
|
||||
sysZuulRoute.setUpdateTime(new Date());
|
||||
sysZuulRoute.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
return new R<>(sysZuulRouteService.updateById(sysZuulRoute));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysZuulRoute 实体
|
||||
* @return success/false
|
||||
*/
|
||||
@PutMapping
|
||||
public R<Boolean> edit(@RequestBody SysZuulRoute sysZuulRoute) {
|
||||
sysZuulRoute.setUpdateTime(new Date());
|
||||
return new R<>(sysZuulRouteService.updateById(sysZuulRoute));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.github.pig.admin.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.github.pig.admin.model.entity.SysOauthClientDetails;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
public interface SysOauthClientDetailsMapper extends BaseMapper<SysOauthClientDetails> {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.github.pig.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 动态路由配置表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
public interface SysZuulRouteMapper extends BaseMapper<SysZuulRoute> {
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ public class MenuTree extends TreeNode {
|
|||
private String code;
|
||||
private String type;
|
||||
private String label;
|
||||
private Integer sort;
|
||||
|
||||
public MenuTree() {
|
||||
}
|
||||
|
@ -48,5 +49,6 @@ public class MenuTree extends TreeNode {
|
|||
this.component = menuVo.getComponent();
|
||||
this.type = menuVo.getType();
|
||||
this.label = menuVo.getName();
|
||||
this.sort = menuVo.getSort();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
package com.github.pig.admin.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotations.TableId;
|
||||
import com.baomidou.mybatisplus.annotations.TableField;
|
||||
import com.baomidou.mybatisplus.activerecord.Model;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import com.baomidou.mybatisplus.enums.IdType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@TableName("sys_oauth_client_details")
|
||||
public class SysOauthClientDetails extends Model<SysOauthClientDetails> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "client_id", type = IdType.INPUT)
|
||||
private String clientId;
|
||||
@TableField("resource_ids")
|
||||
private String resourceIds;
|
||||
@TableField("client_secret")
|
||||
private String clientSecret;
|
||||
private String scope;
|
||||
@TableField("authorized_grant_types")
|
||||
private String authorizedGrantTypes;
|
||||
@TableField("web_server_redirect_uri")
|
||||
private String webServerRedirectUri;
|
||||
private String authorities;
|
||||
@TableField("access_token_validity")
|
||||
private Integer accessTokenValidity;
|
||||
@TableField("refresh_token_validity")
|
||||
private Integer refreshTokenValidity;
|
||||
@TableField("additional_information")
|
||||
private String additionalInformation;
|
||||
private String autoapprove;
|
||||
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getResourceIds() {
|
||||
return resourceIds;
|
||||
}
|
||||
|
||||
public void setResourceIds(String resourceIds) {
|
||||
this.resourceIds = resourceIds;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getAuthorizedGrantTypes() {
|
||||
return authorizedGrantTypes;
|
||||
}
|
||||
|
||||
public void setAuthorizedGrantTypes(String authorizedGrantTypes) {
|
||||
this.authorizedGrantTypes = authorizedGrantTypes;
|
||||
}
|
||||
|
||||
public String getWebServerRedirectUri() {
|
||||
return webServerRedirectUri;
|
||||
}
|
||||
|
||||
public void setWebServerRedirectUri(String webServerRedirectUri) {
|
||||
this.webServerRedirectUri = webServerRedirectUri;
|
||||
}
|
||||
|
||||
public String getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public void setAuthorities(String authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
public Integer getAccessTokenValidity() {
|
||||
return accessTokenValidity;
|
||||
}
|
||||
|
||||
public void setAccessTokenValidity(Integer accessTokenValidity) {
|
||||
this.accessTokenValidity = accessTokenValidity;
|
||||
}
|
||||
|
||||
public Integer getRefreshTokenValidity() {
|
||||
return refreshTokenValidity;
|
||||
}
|
||||
|
||||
public void setRefreshTokenValidity(Integer refreshTokenValidity) {
|
||||
this.refreshTokenValidity = refreshTokenValidity;
|
||||
}
|
||||
|
||||
public String getAdditionalInformation() {
|
||||
return additionalInformation;
|
||||
}
|
||||
|
||||
public void setAdditionalInformation(String additionalInformation) {
|
||||
this.additionalInformation = additionalInformation;
|
||||
}
|
||||
|
||||
public String getAutoapprove() {
|
||||
return autoapprove;
|
||||
}
|
||||
|
||||
public void setAutoapprove(String autoapprove) {
|
||||
this.autoapprove = autoapprove;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.clientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysOauthClientDetails{" +
|
||||
", clientId=" + clientId +
|
||||
", resourceIds=" + resourceIds +
|
||||
", clientSecret=" + clientSecret +
|
||||
", scope=" + scope +
|
||||
", authorizedGrantTypes=" + authorizedGrantTypes +
|
||||
", webServerRedirectUri=" + webServerRedirectUri +
|
||||
", authorities=" + authorities +
|
||||
", accessTokenValidity=" + accessTokenValidity +
|
||||
", refreshTokenValidity=" + refreshTokenValidity +
|
||||
", additionalInformation=" + additionalInformation +
|
||||
", autoapprove=" + autoapprove +
|
||||
"}";
|
||||
}
|
||||
}
|
|
@ -37,7 +37,6 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
* 级联删除菜单
|
||||
*
|
||||
* @param id 菜单ID
|
||||
* @param roleList 角色
|
||||
* @return 成功、失败
|
||||
*/
|
||||
Boolean deleteMenu(Integer id);
|
||||
|
@ -46,7 +45,6 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
* 更新菜单信息
|
||||
*
|
||||
* @param sysMenu 菜单信息
|
||||
* @param roleList 角色
|
||||
* @return 成功、失败
|
||||
*/
|
||||
Boolean updateMenuById(SysMenu sysMenu);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.github.pig.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.github.pig.admin.model.entity.SysOauthClientDetails;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
public interface SysOauthClientDetailsService extends IService<SysOauthClientDetails> {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.github.pig.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 动态路由配置表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
public interface SysZuulRouteService extends IService<SysZuulRoute> {
|
||||
|
||||
}
|
|
@ -10,16 +10,14 @@ import com.github.pig.admin.service.SysMenuService;
|
|||
import com.github.pig.common.constant.CommonConstant;
|
||||
import com.github.pig.common.util.Assert;
|
||||
import com.github.pig.common.vo.MenuVO;
|
||||
import com.xiaoleilu.hutool.collection.CollUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -94,12 +92,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
// 获取符合条件得菜单
|
||||
Set<MenuVO> all = new HashSet<>();
|
||||
roleNames.forEach(roleName -> all.addAll(findMenuByRoleName(roleName)));
|
||||
final List<MenuTree> menuTreeList = new ArrayList<>();
|
||||
List<MenuTree> menuTreeList = new ArrayList<>();
|
||||
all.forEach(menuVo -> {
|
||||
if (CommonConstant.MENU.equals(menuVo.getType())) {
|
||||
menuTreeList.add(new MenuTree(menuVo));
|
||||
}
|
||||
});
|
||||
CollUtil.sort(menuTreeList, Comparator.comparingInt(MenuTree::getSort));
|
||||
return TreeUtil.bulid(menuTreeList, -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.github.pig.admin.service.impl;
|
||||
|
||||
import com.github.pig.admin.mapper.SysOauthClientDetailsMapper;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.github.pig.admin.model.entity.SysOauthClientDetails;
|
||||
import com.github.pig.admin.service.SysOauthClientDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@Service
|
||||
public class SysOauthClientDetailsServiceImpl extends ServiceImpl<SysOauthClientDetailsMapper, SysOauthClientDetails> implements SysOauthClientDetailsService {
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.github.pig.admin.service.impl;
|
||||
|
||||
import com.github.pig.admin.mapper.SysZuulRouteMapper;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.github.pig.common.entity.SysZuulRoute;
|
||||
import com.github.pig.admin.service.SysZuulRouteService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 动态路由配置表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author lengleng
|
||||
* @since 2018-05-15
|
||||
*/
|
||||
@Service
|
||||
public class SysZuulRouteServiceImpl extends ServiceImpl<SysZuulRouteMapper, SysZuulRoute> implements SysZuulRouteService {
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.github.pig.admin.mapper.SysOauthClientDetailsMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.github.pig.admin.model.entity.SysOauthClientDetails">
|
||||
<id column="client_id" property="clientId" />
|
||||
<result column="resource_ids" property="resourceIds" />
|
||||
<result column="client_secret" property="clientSecret" />
|
||||
<result column="scope" property="scope" />
|
||||
<result column="authorized_grant_types" property="authorizedGrantTypes" />
|
||||
<result column="web_server_redirect_uri" property="webServerRedirectUri" />
|
||||
<result column="authorities" property="authorities" />
|
||||
<result column="access_token_validity" property="accessTokenValidity" />
|
||||
<result column="refresh_token_validity" property="refreshTokenValidity" />
|
||||
<result column="additional_information" property="additionalInformation" />
|
||||
<result column="autoapprove" property="autoapprove" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
client_id AS clientId, resource_ids AS resourceIds, client_secret AS clientSecret, scope, authorized_grant_types AS authorizedGrantTypes, web_server_redirect_uri AS webServerRedirectUri, authorities, access_token_validity AS accessTokenValidity, refresh_token_validity AS refreshTokenValidity, additional_information AS additionalInformation, autoapprove
|
||||
</sql>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.github.pig.admin.mapper.SysZuulRouteMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.github.pig.common.entity.SysZuulRoute">
|
||||
<id column="id" property="id" />
|
||||
<result column="path" property="path" />
|
||||
<result column="service_id" property="serviceId" />
|
||||
<result column="url" property="url" />
|
||||
<result column="strip_prefix" property="stripPrefix" />
|
||||
<result column="retryable" property="retryable" />
|
||||
<result column="enabled" property="enabled" />
|
||||
<result column="sensitiveHeaders_list" property="sensitiveheadersList" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="del_flag" property="delFlag" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, path, service_id AS serviceId, url, strip_prefix AS stripPrefix, retryable, enabled, sensitiveHeaders_list AS sensitiveheadersList, create_time AS createTime, update_time AS updateTime, del_flag AS delFlag
|
||||
</sql>
|
||||
|
||||
</mapper>
|
|
@ -7,6 +7,7 @@ import com.github.pig.common.constant.CommonConstant;
|
|||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.github.pig.common.util.Query;
|
||||
import com.github.pig.common.util.R;
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Service}.${entity}Service;
|
||||
#if(${superControllerClassPackage})
|
||||
|
@ -33,8 +34,8 @@ public class ${table.controllerName} extends ${superControllerClass} {
|
|||
* @return ${entity}
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ${entity} get(@PathVariable Integer id) {
|
||||
return ${table.entityPath}Service.selectById(id);
|
||||
public R<${entity}> get(@PathVariable Integer id) {
|
||||
return new R<>(${table.entityPath}Service.selectById(id));
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,8 +57,8 @@ public class ${table.controllerName} extends ${superControllerClass} {
|
|||
* @return success/false
|
||||
*/
|
||||
@PostMapping
|
||||
public Boolean add(@RequestBody ${entity} ${table.entityPath}) {
|
||||
return ${table.entityPath}Service.insert(${table.entityPath});
|
||||
public R<Boolean> add(@RequestBody ${entity} ${table.entityPath}) {
|
||||
return new R<>(${table.entityPath}Service.insert(${table.entityPath}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,12 +67,12 @@ public class ${table.controllerName} extends ${superControllerClass} {
|
|||
* @return success/false
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Boolean delete(@PathVariable Integer id) {
|
||||
public R<Boolean> delete(@PathVariable Integer id) {
|
||||
${entity} ${table.entityPath} = new ${entity}();
|
||||
${table.entityPath}.setId(id);
|
||||
${table.entityPath}.setUpdateTime(new Date());
|
||||
${table.entityPath}.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
return ${table.entityPath}Service.updateById(${table.entityPath});
|
||||
return new R<>(${table.entityPath}Service.updateById(${table.entityPath}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,8 +81,8 @@ public class ${table.controllerName} extends ${superControllerClass} {
|
|||
* @return success/false
|
||||
*/
|
||||
@PutMapping
|
||||
public Boolean edit(@RequestBody ${entity} ${table.entityPath}) {
|
||||
public R<Boolean> edit(@RequestBody ${entity} ${table.entityPath}) {
|
||||
${table.entityPath}.setUpdateTime(new Date());
|
||||
return ${table.entityPath}Service.updateById(${table.entityPath});
|
||||
return new R<>(${table.entityPath}Service.updateById(${table.entityPath}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue