如何解决Spring native - 运行本机图像时具有多对多关系的查询不显示数据
我在 webflux 服务中工作,该服务从 postgresql 数据库中获取信息。当我从 Intellij Idea 运行它时,该服务运行良好。但是,当我生成本机图像时,一些响应数据是空的(我认为这是由于 jackson 中的一些配置错误,但我无法修复它)。有人可以帮忙吗?
这是我拥有的存储库:
@Repository
public interface BookAuthorsRepository extends ReactiveCrudRepository<BookAuthors,Long> {
@Query("SELECT b.id,b.title,b.description," +
"( SELECT json_agg(json_build_object('authorId',a.id,'fullName',concat_ws(' ',a.name,a.surname))) " +
" FROM authors a JOIN books_authors ba ON a.id=ba.author_id " +
" WHERE b.id=ba.book_id ) as authors" +
" FROM books b")
Flux<BookAuthors> findAll();
@Query("SELECT b.id,a.surname))) " +
" FROM authors a JOIN books_authors ba ON a.id=ba.author_id " +
" WHERE b.id=ba.book_id ) as authors" +
" FROM books b " +
" WHERE b.id=:bookId" )
Mono<BookAuthors> findByBookId(final Long bookId);
}
我还有一个转换器,它基本上返回 BookAuthors 对象:
public class BookAuthorsReadConverter implements Converter<Row,BookAuthors> {
private static Logger LOG = LoggerFactory.getLogger(BookAuthorsReadConverter.class);
@Override
public BookAuthors convert(Row row) {
final Long id = row.get("id",Long.class);
final String bookTitle = row.get("title",String.class);
final String bookDescription = row.get("description",String.class);
final List<AuthorRef> authors = new java.util.ArrayList<>();
final JSONArray array = new JSONArray(row.get("authors",String.class));
array.forEach(item -> {
final JSONObject jsonObject = (JSONObject) item;
final AuthorRef authorRef = new AuthorRef(Long.parseLong(jsonObject.get("authorId").toString()),jsonObject.get("fullName").toString());
authors.add(authorRef);
}
);
LOG.info("Book with authors: {}",new BookAuthors(id,bookTitle,bookDescription,authors));
return new BookAuthors(id,authors);
}
}
在回复中我得到了这个:
{
"id": 2,"title": "Hands-On Spring Security 5 for Reactive Applications","description": "Learn effective ways to secure your applications with Spring and Spring WebFlux (English Edition)","authors": [
{}
]
}
我什么时候应该得到这个:
{
"id": 2,"authors": [
{
"authorId": 2,"fullName": "Tomcy John"
}
]
}
```
Do anyone kNow what's going on in the native image? What am I missing? Please help.
Thank you very much in advance.
Best regards.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。