修改 spring cloud feign 调用方式

本文介绍了如何将Spring Cloud Feign的调用方式进行改造,通过引入自定义的HandlerMethodArgumentResolver和配置,简化接口调用,提高代码复用性。详细展示了改造的代码实现,包括接口定义、FeignClient配置以及参数解析器的添加。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有项目要改成 spring cloud 。本着能少干就少干的原则,就偷了个懒,把spring cloud eign的调用方式改了一下。

直接代码
 

public interface IAopActivityBeanService {

    public String name = "IAopActivityBeanService";

    /**

     * 增加或更新

     */

    @SuppressWarnings("deprecation")

@RequestMapping(value = "/saveUpdate", method = RequestMethod.POST)  //,produces=MediaType.APPLICATION_JSON_UTF8_VALUE ,consumes=MediaType.APPLICATION_JSON_UTF8_VALUE 

    public ActivityBean saveUpdate(@MyParams(name = "optType")OptType optType, @MyParams(name = "bean")ActivityBean iActivityBean,@MyParams(name = "optUserId") Long optUserId) throws SystemOptServiceException;

    @RequestMapping(value = "/search/pages", method = RequestMethod.POST)

    public SelectPage<ActivityBean> search(@MyParams(name = "optType") OptType optType, @MyParams(name = "searchBean") ActivityBeanSearchBean searchBean,

        @MyParams(name = "commSearchBean") CommSearchBean commSearchBean, @MyParams(name = "optUserId") Long optUserId) throws SystemOptServiceException;

    @RequestMapping(value = "/search/list", method = RequestMethod.POST)

    public List<ActivityBean> searchList(@MyParams(name = "optType") OptType optType, @MyParams(name = "searchBean") ActivityBeanSearchBean searchBean,

        @MyParams(name = "commSearchBean") CommSearchBean commSearchBean) throws SystemOptServiceException;

    @RequestMapping(value = "/remove", method = RequestMethod.POST)

    public ActivityBean remove(@MyParams(name = "optType") OptType optType, @MyParams(name = "searchBean") ActivityBeanSearchBean searchBean, @MyParams(name = "optUserId") Long optUserId)

        throws SystemOptServiceException;

    @RequestMapping(value = "/remove/all", method = RequestMethod.POST)

    public List<ActivityBean> removes(@MyParams(name = "optType") OptType optType, @MyParams(name = "searchBean") ActivityBeanSearchBean searchBean, @MyParams(name = "optUserId") Long optUserId)

        throws SystemOptServiceException;

    @RequestMapping(value = "/get", method = RequestMethod.POST)

    public ActivityBean get(@MyParams(name = "id") Long id) throws SystemOptServiceException;

}

public interface IAopActivityBeanExService extends IAopActivityBeanService {

    @RequestMapping(value = &quot;/search/time&quot;, method = RequestMethod.POST)
    public List searchByTime(@MyParams(name = &quot;optType&quot;) OptType optType, @MyParams(name = &quot;searchBean&quot;) ActivityBeanSearchBean searchBean, @MyParams(name = &quot;optUserId&quot;) Long optUserId)
        throws SystemOptServiceException;

}

@FeignClient(name = ActivityFeignParams.feign_service, path = ActivityFeignParams.path_activity)
public interface IActivityBeanFeignServiceClient extends IActivityBeanFeignService {

}

@RestController
@RequestMapping(&quot;/activity&quot;)
public class ActivityBeanFeignService implements IActivityBeanFeignService {

    @Autowired
    @Qualifier(IAopActivityBeanExService.name)
    private IAopActivityBeanExService service;

    @Override
    public SelectPage search(OptType optType, ActivityBeanSearchBean searchBean, CommSearchBean commSearchBean, Long optUserId) throws SystemOptServiceException {

        SelectPage selectPage = service.search(optType, searchBean, commSearchBean, optUserId);
  &n

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pzzy2000

大家高兴就行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值