vip.justlive.common.web.base.BaseService Maven / Gradle / Ivy
/*
* Copyright (C) 2018 justlive1
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package vip.justlive.common.web.base;
import java.util.Map;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import vip.justlive.common.base.domain.Response;
import vip.justlive.common.base.exception.Exceptions;
/**
* 基础service
* 提供公共基础方法
*
* @author wubo
*
*/
public abstract class BaseService {
protected RestTemplate template;
/**
* 由继承该类的组件注入template
*
*
* @Override
* protected void setTemplate(@Autowired RestTemplate template) {
* super.setTemplate(template);
* }
*
*
* @param template rest模板
*/
protected void setTemplate(RestTemplate template) {
this.template = template;
}
/**
* 构造json请求体
*
* @param request 请求类
* @param 泛型类
* @return json请求体
*/
protected HttpEntity buildEntity(T request) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return new HttpEntity<>(request, headers);
}
/**
* 构造表单提交请求体
*
* @param request 请求
* @return 表单请求体
*/
protected HttpEntity