Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaSpring引导中使用RESTXML文件_Java_Xml_Rest_Spring Boot - Fatal编程技术网

在JavaSpring引导中使用RESTXML文件

在JavaSpring引导中使用RESTXML文件,java,xml,rest,spring-boot,Java,Xml,Rest,Spring Boot,我有一个SpringBoot项目,其中我需要通过REST使用xml文件。 我只想以xml文件的形式检索REST消息的有效负载,并将其存储在本地 在internet上,有许多教程使用xml文件并将其转换为java对象,这主要归功于Jersey。 然而,我不想将这个xml文件转换成java对象;我只需要恢复xml并存储它 我猜它将如下所示: @POST @Consumes(MediaType.APPLICATION_XML) public void post(...) { //retriev

我有一个SpringBoot项目,其中我需要通过REST使用xml文件。 我只想以xml文件的形式检索REST消息的有效负载,并将其存储在本地

在internet上,有许多教程使用xml文件并将其转换为java对象,这主要归功于Jersey。 然而,我不想将这个xml文件转换成java对象;我只需要恢复xml并存储它

我猜它将如下所示:

@POST
@Consumes(MediaType.APPLICATION_XML)
public void post(...) {
    //retrieve payload of my xml rest message
} 

@POST
不是spring注释,而是Jersey注释

对于Spring注释,它将是这样的:

import java.nio.file.Paths;
import java.nio.file.Files;
import org.springframework.web.bind.annotation.*;

@RestController
public class YourController {

    @RequestMapping(value = "/requestpath",  method = RequestMethod.POST)
    @ResponseBody
    public String home(@RequestBody byte[] requestBody) throws Exception {
        String fileName = "target.filename.xml";
        Files.write(Paths.get(fileName), requestBody);
        return "<message>OK</message>";
    }

}
import java.nio.file.path;
导入java.nio.file.Files;
导入org.springframework.web.bind.annotation.*;
@RestController
公共类控制器{
@RequestMapping(value=“/requestpath”,method=RequestMethod.POST)
@应答器
公共字符串home(@RequestBody byte[]RequestBody)引发异常{
String fileName=“target.fileName.xml”;
Files.write(路径.get(文件名),requestBody);
返回“OK”;
}
}

@LaverteJean好极了!如果这解决了问题,请随意接受答案。