如何在C中分配和声明结构的3D数组?你首先分配数组还是声明它?我觉得你必须先分配它,这样你就可以声明它在堆上了,但那么你如何分配尚未制作的东西呢?另外,您应该一次性还是逐个元素地分配它?我也正确地将结构放入数组中?我对如何做的猜测是:
header.h
struct myStruct{
int a;
int b;
};
typedef struct myStruct myStruct_t;
Run Code Online (Sandbox Code Playgroud)
main.c中
#include "header.h"
#include <stdio.h>
#include <stdlib.h>
int main(void){
int length=2;
int height=3;
int width =4;
myStruct_t *elements;
struct myStruct arr = (*myStruct_t) calloc(length*height*width, sizeof(myStruct);
//zero based array
arr[length-1][height-1][width-1];
int x=0;
while(x<length){
int y=0;
while(y<height){
int z=0;
while(z<depth){
arr[x][y][z].a=rand();
arr[x][y][z].b=rand();
z++;
}
y++;
}
x++;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我不知道如何将 Java 列表传递到 Spring RestTemplate 调用中,然后在 Controller 方法中使用该列表
客户端代码:
public String generateInfoOfIds(List<String> ids, String userName, String password){
RestTemplate restTemplate = new RestTemplate();
String response = null;
String url = "https://someservice.com/getInfoOfIds?";
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(userName, password));
response = restTemplate.exchange(url+"ids=" + ids, HttpMethod.GET, null, String.class);
return response;
}
Run Code Online (Sandbox Code Playgroud)
控制器代码:
@RequestMapping(value = "/getInfoOfIds", method = RequestMethod.GET)
public String getInfoOfIds(@RequestParam("ids") List<String> ids) {
String response = myService.doSomeWork(ids);
return response;
}
Run Code Online (Sandbox Code Playgroud)
对控制器本身的调用有效,但 List 未正确转换为 @RequestParam id。
在 Spring 中,如何将 List 从 RestTemplate 传递到 Controller?
allocation ×1
arrays ×1
c ×1
controller ×1
java ×1
resttemplate ×1
spring ×1
struct ×1
typedef ×1