Fegin调用传参会拼接在url后面的问题解决办法(@SpringQueryMap并不能解决)

问题发现场景

原fegin的代码如下

@FeignClient(value = "zz-atexpress",contextId = "AtExpressClient")
public interface AtExpressClient {
//@ApiOperation("获取at公式的值")
@PostMapping("/zzAtexpress/exeuteAtExpress")
ResultInfo exeuteAtExpress(@RequestParam String processInstId
, @RequestParam String taskId, @RequestParam String atExpress);
}

这样 当我传递的值atExpress=aaa&token=@token时 那么fegin就会把参数拼接在url后面导致

实际atExpress接收到的值是aaa 而不是aaa&token=@token

参数带@RequestParam的都会拼接在url后面 不管是post还是get contenttype值是否其他的任何值

解决办法如下

@FeignClient(value = "zz-atexpress",contextId = "AtExpressClient")
public interface AtExpressClient {
//这样可以 但是要组装map
@PostMapping("/zzAtexpress/exeuteAtExpress")
ResultInfo exeuteAtExpress(@SpringQueryMap Map<String,?> param);
}

这样 调用之前 要组装map ,但是参数不会拼接在url之后导致 接收参数错误

或者修改接收参数为@requestBody 也可以

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java 中,使用 @Transactional 注解可以实现事务管理。但是在某些情况下,@Transactional 注解可能不生效,比如注解在事务类的内部方法上。 这是因为 Spring AOP 默认只拦截通过 Spring 容器管理的 Bean 的方法调用,而事务类通常是使用自调用的方式,因此不Spring AOP 拦截。 解决这个问题的方法是使用 AspectJ。AspectJ 是一种基于语言的 AOP 实现方式,可以在编译期或者运行期织入切面。 具体实现如下: 1. 添加 AspectJ 依赖 ```xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> ``` 2. 配置 Spring,启用 AspectJ 自动代理 ```xml <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /> <aop:aspectj-autoproxy /> ``` 3. 在事务类上添加 @Aspect 注解,并实现一个切面类 ```java @Aspect @Component public class TransactionAspect { @Autowired private PlatformTransactionManager transactionManager; @Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)") public void transactionalMethod() {} @Around("transactionalMethod()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable { TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); Object result; try { result = joinPoint.proceed(); transactionManager.commit(status); } catch (Exception e) { transactionManager.rollback(status); throw e; } return result; } } ``` 这个切面类拦截所有被 @Transactional 注解标记的方法,并使用事务管理器执行事务。 以上就是解决注解@Transactional事务类内调用不生效问题的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值