jquery 的 flexigrid - 希望通过带有 gson 的 Serlet 来传递数据

发布于 2024-08-19 03:02:19 字数 891 浏览 2 评论 0原文

java新手,但很想实现我的工作jsp,该jsp生成由可爱的jquery flexigrid使用的xml以使用json版本(由gson生成)。我基本上刚刚开始使用java,但想学习最好的方法来做到这一点。我一直在研究内部类,但想看看什么被认为是最佳实践。

json 预期格式(我从这里的另一篇文章中得到了这个)是:

total: (no of rec)
 page : (page no)
 rows : {id: 1, cell: [ (col1 value) , (col2 value) ,.. ] },
        {id: 2, cell: [ (col1 value) , (col2 value) ,.. ] }

而且,到目前为止我的不可编译的 java 是:

private class _JsonReturn {
    int page ;
    int total ;
    class Rows {
        String id = new String();
        MultiMap cell = new MultiValueMap() ;
        private Rows( String newCell ) {
            this.id = newCell ;
        }
        private void _addRowValue( String cellValue ){
            this.cell.put( this.id, cellValue );
        }
        private Object _getRows() {
            return this ;
        }

    }      
}

帮助 - 我认为我在这里把事情复杂化了!提前非常感谢!

New to java, but would love to implement my working jsp that generates xml used by a lovely jquery flexigrid to use a json version (generated by gson). I'm just starting out w/ java basically, but would like to learn the best way to do this. I've been looking at inner classes, but wanted to check out what would be considered best practice.

The json expected format (I got this from another post here) is:

total: (no of rec)
 page : (page no)
 rows : {id: 1, cell: [ (col1 value) , (col2 value) ,.. ] },
        {id: 2, cell: [ (col1 value) , (col2 value) ,.. ] }

And, so far my non compilable java is:

private class _JsonReturn {
    int page ;
    int total ;
    class Rows {
        String id = new String();
        MultiMap cell = new MultiValueMap() ;
        private Rows( String newCell ) {
            this.id = newCell ;
        }
        private void _addRowValue( String cellValue ){
            this.cell.put( this.id, cellValue );
        }
        private Object _getRows() {
            return this ;
        }

    }      
}

Help - I think I'm over complicating things here! Thanks a ton in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-08-26 03:02:19

Xstream 是一个非常方便且有用的库,用于将 java 类或 POJO 编组为 xml 或 json。而且速度也非常快。

编辑
对于您的java结构要求,我建议您一个简单的结构(也许我得到-1,但这是最简单的:)

Vector rowsVector = new Vector();
Map row = new HashMap();
row.put("id", "1");
row.put("cellValue", "Hola");
rowsVector.add(row);

Map mapToJson = new HashMap();
mapToJson.put("page", 3);
mapToJson.put("total", rowsVector.size());
mapToJson.put("rows", rowsVector);

然后您可以使用任何JsonParser解析它。
我希望它对你有帮助:)

Xstream is a very handly and useful library to marshall java classes or POJO to xml or json. And it also very fast.

EDIT
For your java structure requeriments, I propose you a simple structure (perhaps I get a -1, but it's the simplest :)

Vector rowsVector = new Vector();
Map row = new HashMap();
row.put("id", "1");
row.put("cellValue", "Hola");
rowsVector.add(row);

Map mapToJson = new HashMap();
mapToJson.put("page", 3);
mapToJson.put("total", rowsVector.size());
mapToJson.put("rows", rowsVector);

Then you can parse it with any JsonParser.
I hope it helps you :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文