这个问题在这里已经有了答案:
如何获取java中的示例名称[(1份答覆)
四天前关门。
我知道这没有多大意义,但我正在尝试创建一个动态方法来记录请求,例如:
@GetMapping("/my-path")
public ResponseEntity<Foo> findSomethingBy(Integer bankId, String clientName, FooFilter filter){
log.info("The method findSomethingBy was called with=" +**dynamicMethotRequest(Arrays.asList(bankId, clientName, filter)**);
var result = service.findSomethingBy(bankId, clientName, filter);
log.info("The method findSomethingBy result=" + result);
return ResponseEntity.ok(result);
}
@GetMapping("/my-other-path")
public ResponseEntity<Foo> findSomethingByAnotherThing(Integer bankId, Integr clientId){
log.info("The method findSomethingBy was called with=" +**dynamicMethotRequest(Arrays.asList(bankId, clientName)**);
var result = service.findSomethingByAnotherThing(bankId, clientName, filter);
log.info("The method findSomethingByAnotherThing result=" + result);
return ResponseEntity.ok(result);
}
来自的第一个预期日志 findSomethingBy
应该是:
The method findSomethingBy was called with=(bankId=1, clientName=Jack, filter=(age=24, job=dev, working=true, from=Brazil))
来自的第一个预期日志 findSomethingByAnotherThing
应该是:
The method findSomethingByAnotherThing was called with=(bankId=1, clientId=1)
那我该怎么做呢 dynamicMethotRequest
要获取数组每个位置的示例名称?
这就是我尝试的方式:
private String dynamicMethotRequest(List list){
String result = "";
var size = list.size();
for (int i = 0; i < size; i++) {
var element = list.get(i);
String elemnetName = element.getInstanceName();
if(i == 0){
result = "(";
}
result = result + "elemnetName" + "=" + element.toString();
if(i+1 == size){
result = result + ")";
}else {
result = result + ",";
}
}
return result;
}
2条答案
按热度按时间mlmc2os51#
您可以为所有请求实现一个拦截器,并从请求中获取所有值
创建拦截器
在配置上设置拦截器
因此,当您调用时,所有的请求都将在您的实现上被拦截,并在httpservletresponse上获得方法返回或值的结果
plupiseo2#
无法保留您称之为变量的信息,您将该变量传递到数组中。
看到这个帖子了吗
如果你必须这么做(你不应该这么做),你应该使用Map。