gpt4 book ai didi

java - 检查 JAXBElement 参数是否为 null

转载 作者:行者123 更新时间:2023-12-01 04:58:48 25 4
gpt4 key购买 nike

我有以下方法,它接收 XML 并在数据库中创建一本新书:

@PUT
@Path("/{isbn}")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public SuccessfulRequestMessage createBook(JAXBElement<Book> bookParam,
@PathParam("isbn") String isbn) {

if(bookParam == null)
{
ErrorMessage errorMessage = new ErrorMessage(
"400 Bad request",
"To create a new book you must provide the corresponding XML code!");
throw new MyWebServiceException(Response.Status.BAD_REQUEST,
errorMessage);
}
....................................................................
}

问题是,当我不在消息正文中发送任何内容时,不会引发异常。如何检查消息正文是否为空?

谢谢!

索林

最佳答案

试试这个:

public SuccessfulRequestMessage createBook(JAXBElement<Book> bookParam, 
@PathParam("isbn") String isbn) throws MyWebServiceException

关于java - 检查 JAXBElement 参数是否为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13651261/

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