gpt4 book ai didi

java - 如何制作一个 Controller 来使用HashMap获取URL?

转载 作者:行者123 更新时间:2023-12-02 09:27:49 26 4
gpt4 key购买 nike

我需要在 Spring Boot 2.0 中创建一个 Controller 才能正确获取如下 URL:

https://localhost:8443/my_generate_signature?data%5Btimestamp%5D=1570074358&data%5Bsource%5D=uw

此 URL 正在由 AJAX 请求调用:

<script type="text/javascript">
var generateSignature =
function(callback, params_to_sign){
$.ajax({
url : "/my_generate_signature",
type : "GET",
dataType: "text",
data : { data: params_to_sign},
complete: function() {console.log("complete")},
success : function(signature, textStatus, xhr) { callback(signature); },
error : function(xhr, status, error) { console.log(xhr, status, error); }
});
}
</script>
<script type="text/javascript">  
$('#upload_widget_opener').cloudinary_upload_widget({
cloudName: cloudName, apiKey: api_key,
cropping: true, uploadSignature: generateSignature}, (error, result) => { });
</script>

作为引用,我正在尝试实现这个:

https://cloudinary.com/documentation/upload_widget#create_upload_widget_methods

我尝试过这样的 Controller ,但我得到 HttpStatus 400:

@RequestMapping(value="/my_generate_signature")
@ResponseBody
public String generateSignature(@RequestParam(value="params_to_sign", required=true) Map<String, Object> paramsToSign) {

return 'test';
}

最佳答案

您还可以使用发布请求并使用请求正文。@PostMapping@ResponseBody公共(public)字符串generateSignature(@RequestBody Map> paramsToSign){ 返回 ”....”;}

如果是get请求,可以使用@GetMapping和@RequestParam注解。

关于java - 如何制作一个 Controller 来使用HashMap获取URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58212219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com