查询DB并以Json格式返回结果的通用Java方法 [英] General Java Method that Queries DB and Returns Results in Json Format

查看:200
本文介绍了查询DB并以Json格式返回结果的通用Java方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要找的东西对我来说似乎很简单,但是我的Google失败了.

What I'm looking for seems pretty straight forward to me, but my googles have failed.

我想要一个允许我运行任何查询并以json格式获取结果的方法.

I want a method that allows me to run any query and get the results in json format.

诀窍是我希望结果需要Java对象作为流程的一部分(DTO,VO等).

The trick is I don't want the results to need java objects as part of the process (DTOs, VOs, etc).

是否有任何快速/简便/干净的方法?

Any quick/easy/clean ways of doing this?

推荐答案

杰克逊(Jackson)有一些不错的方法.在此答案中有一些示例可以为您带来奇迹

Jackson has some pretty nice ways of doing it. There's some examples in this answer that should work wonders for you.

或者,如果您无法使用Jackson,您可以查看

Alternatively, if Jackson isn't available to you, you could check out this

这篇关于查询DB并以Json格式返回结果的通用Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆