繁体   English   中英

在Java spring-boot中使用rest xml文件

[英]Consume rest xml file in java spring-boot

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

在互联网上,主要有泽西岛,有很多教程可以使用xml文件并将其转换为java对象。 不过,我不想将此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>";
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM