java map存储格式化_如何将TreeMap与内容转换为JSON格式Spring REST Controller JAVA(How to convert TreeMap with contents...

如何将TreeMap与内容转换为JSON格式Spring REST Controller JAVA(How to convert TreeMap with contents to JSON format Spring REST Controller JAVA)

您好我有一个代码,我想将我的Collection公开为JSON格式。 我以为Spring会自动完成。 这是代码:

@RestController

public class BirthdayController extends BaseController{

@RequestMapping("/api/v1/birthday")

public TreeMap>> getBirthdays(@RequestParam(value="startYear") Integer startYear,

@RequestParam(value="startMonth") Integer startMonth,

@RequestParam(value="endYear") Integer endMonth,

@RequestParam(value="endMonth") Integer endYear) {

BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();

return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);

}

}

我在访问端点时只获得空{}

Hello I have a code where I want to expose my Collection as JSON format. I thought Spring does it automatically. Here is the code:

@RestController

public class BirthdayController extends BaseController{

@RequestMapping("/api/v1/birthday")

public TreeMap>> getBirthdays(@RequestParam(value="startYear") Integer startYear,

@RequestParam(value="startMonth") Integer startMonth,

@RequestParam(value="endYear") Integer endMonth,

@RequestParam(value="endMonth") Integer endYear) {

BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();

return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);

}

}

I get only empty {} on accessing endpoint

原文:https://stackoverflow.com/questions/40465118

2019-12-05 09:12

满意答案

尝试,

@RequestMapping("/api/v1/birthday")

public @ResponseBody TreeMap>> getBirthdays(@RequestParam(value="startYear") Integer startYear,

@RequestParam(value="startMonth") Integer startMonth,

@RequestParam(value="endYear") Integer endMonth,

@RequestParam(value="endMonth") Integer endYear) {

BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();

return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);

}

try,

@RequestMapping("/api/v1/birthday")

public @ResponseBody TreeMap>> getBirthdays(@RequestParam(value="startYear") Integer startYear,

@RequestParam(value="startMonth") Integer startMonth,

@RequestParam(value="endYear") Integer endMonth,

@RequestParam(value="endMonth") Integer endYear) {

BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();

return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);

}

2016-11-07

相关问答

这是一篇关于如何序列化JSON日期的优秀文章。 http://www.baeldung.com/jackson-serialize-dates 选项12:自定义序列化程序应该是最后的选择,但在该页面上有许多可供选择的解决方案。 Here's an excellent article on how to serialize JSON dates. http://www.baeldung.com/jackson-serialize-dates Option 12: Custom Serializer ...

最后,我使用Jackson库和Spring MVC一起获得了解决方案。 我从Journal Dev的一个例子中得到了这个解决方案( http://www.journaldev.com/2552/spring-restful-web-service-example-with-json-jackson-and-client-program ) 所以,我所做的代码更改是: 将库包含在Maven中。 将JSON转换Servlet添加到servlet-context.xml中。 将模型更改为可序列化。 我没...

您可以直接调用外部URL,并且必须使用第三方库进行xml转换,因为angular不会使用手动http提供转换本身。 我推荐x2js,因为它很简单,很容易理解,例如如何使用它如下所示,如果你想了解更多细节,请浏览文档。 调节器 module.controller('exampleCtrl', function($scope,exampleSvc){

function loadExternalXml(){

var x2js = new X2JS();

ex...

如果你想使用Map你必须执行以下操作: @GetMapping("temp")

public String temp(@RequestParam Map blah) {

System.out.println(blah.get("a"));

return "Hello";

}

而这个URL是: http://localhost:8080/temp?a=b 使用Map您将可以访问您提供的所...

指定控制器来处理索引页时,应该使用@Controller而不是@RestController 。 虽然@RestController是一个@Controller但它不会解析为视图,而是将结果返回给客户端。 在返回String时使用@Controller时,它将解析为视图的名称。 @Controller

public class IndexController {

@RequestMapping("/")

public String index() {

return...

你想要@RequestPart而不是@RequestParam 。 根据文件...... 主要区别在于,当method参数不是String时,@ RequestParam依赖于通过已注册的Converter或PropertyEditor进行类型转换,而@RequestPart依赖于HttpMessageConverters,并考虑请求部分的“Content-Type”标头。 @RequestParam可能与名称 - 值表单字段一起使用,而@RequestPart可能与包含更复杂内容的部分一起使用(...

查看端点映射到的代码 public static final String GET_ALL_EMPLOYEES = "/rest/employee/";

在哪里访问的网址是 /SpringMVC/rest/employee

org.springframework.web.servlet.PageNotFound noHandlerFound警告:在名为“springmvc”的DispatcherServlet中找不到带有URI [/ SpringMVC / rest / employee]的H...

您可以将日期转换为JSON响应所需的任何格式。 在您的情况下,您一直在使用java.util.Date类型字段的默认JSON日期转换器。 这基本上是Spring Roo为您生成的内容。 看看你的* _Roo_Json方面,你会发现smth。 喜欢这个: public java.lang.String PizzaOrder.toJson() {

return new JSONSerializer().exclude("*.class").serialize(this);

}

这样的实现使用...

根据我在mvc-showcase上看到的messageconverter示例,在application/json请求中尝试使用Accept标头 这是一个相关的问题: 使用spring mvc3 @ResponseBody有415个Unsupported Media Type为什么? Try with a Accept header in your request of application/json, based on what I see with the messageconverter s...

尝试, @RequestMapping("/api/v1/birthday")

public @ResponseBody TreeMap>> getBirthdays(@RequestParam(value="startYear") Integer startYear,

@RequestParam(value=...

相关文章

web.xml <servlet> <servlet-name>test&

...

下载ueditor1_4_3_3里有一个jsp的文件夹,那是官方提供的java 工具类,有一个lib目

...

一个页面上有很多输入框,我想把这些值通过json格式传到controller中,通过注解应该如何实现?

...

看一下领悟书生的代码,在spring的类注解上有Component,Service等,既然是重构,必须

...

我做了一个这样的框架: spring+hibernate+spring mvc 想让spring

...

1、首先创建数据绑定器,在此此会创建ServletRequestDataBinder类的对象,并设置m

...

直接上图,金山的APP“微信导航”,从界面上看有粉丝数等关键数据,实现了直接关注功能,莫不是rest接

...

Controller控制器,是MVC中的部分C,为什么是部分呢?因为此处的控制器主要负责功能处理部分:

...

@Controllerpublic class OAuthController { @RequestM

...

这里我们要注意的是当用户跳转到页面2时页面1的信息是需要保存起来的,还记得AbstractFormCo

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值