重載是java語言的一個(gè)很重要的特性琉预,但是在用dubbo服務(wù)的時(shí)候佩谷,有個(gè)小坑奥喻,和大家分享慕嚷。
上代碼:
/**
* 抓取微信公眾號(hào)文章
* @author WangMin
*/
public interface WeChatNewsService {
/**
* 獲取微信文章
* @param query 查詢條件
* @return 返回Json字符串
*/
String captureNews(WeChatNewsQuery query);
/**
* 獲取文章
* @param queryJson Json參數(shù)
* @return 返回Json字符串
*/
String captureNews(String queryJson);
}
看一下dubbo接口的實(shí)現(xiàn):
import org.springframework.stereotype.Service;
@Service
@com.alibaba.dubbo.config.annotation.Service(
version = "1.0.0",
retries = 0,
timeout = 30000
)
public class WeChatNewsServiceImpl implements WeChatNewsService {
@Override
public String captureNews(WeChatNewsQuery query) {
//獲取參數(shù)
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("type", MediaType.NEWS.getValue());
jsonObject.addProperty("offset", query.getOffset());
jsonObject.addProperty("count", query.getCount());
return captureNews(jsonObject.toString());
}
@Override
public String captureNews(String queryJson) {
//調(diào)用接口
return HttpUtil.post(this.getCaptureUrl(), queryJson);
}
}
參考:
https://blog.csdn.net/java_66666/article/details/82494448