Spring 4 Restfull服务用豆(Spring 4 Restfull Service with bean)
我正在尝试创建一个简单的服务器/客户端应用程序,可以将bean作为参数而不是String发送,但是下面的失败是我的代码
服务器
@Controller public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); @RequestMapping(method=RequestMethod.POST,value="/returnGreet") public @ResponseBody Greeting returnGreet( @RequestBody(required=false) Greeting greet) { if(greet == null) return new Greeting(counter.incrementAndGet(), String.format(template, greet)); else return new Greeting(0,"Testing"); } }
客户
RestTemplate restTemplate = new RestTemplate(); MultiValueMap<String,Greeting> greet = new LinkedMultiValueMap<String, Greeting>(); greet.add("greet", new Greeting(0,"XOXO")); greeting = restTemplate.postForObject("http://localhost:8080/returnGreet",greet, Greeting.class,greet); System.out.println("Content: " + greeting.getContent()); System.out.println("Id: " + greeting.getId() );
对于服务器端的对象问候,结果始终为null。
任何想法 ?
I am trying to create a simple Server / Client application that can send a bean as parameter instead of String but failing below is my code
Server
@Controller public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); @RequestMapping(method=RequestMethod.POST,value="/returnGreet") public @ResponseBody Greeting returnGreet( @RequestBody(required=false) Greeting greet) { if(greet == null) return new Greeting(counter.incrementAndGet(), String.format(template, greet)); else return new Greeting(0,"Testing"); } }
Client
RestTemplate restTemplate = new RestTemplate(); MultiValueMap<String,Greeting> greet = new LinkedMultiValueMap<String, Greeting>(); greet.add("greet", new Greeting(0,"XOXO")); greeting = restTemplate.postForObject("http://localhost:8080/returnGreet",greet, Greeting.class,greet); System.out.println("Content: " + greeting.getContent()); System.out.println("Id: " + greeting.getId() );
The result is always null for the object greet at the server side.
Any Idea ?
原文:https://stackoverflow.com/questions/21287186
更新时间:2023-09-05 17:09
最满意答案
just use
FIELD()
in theORDER BY
clauseORDER BY FIELD(user_id, 20, 24, 23, 26, 27, 28, 25) ASC
相关问答
更多-
查看两个查询并查找它如何加入。 最好的方法是使用EF查询使用Notepad REPLACE ALL [Extent1]和'g',对EF中的所有别名都做,并使用diff工具来比较和发现差异。 以下一个例子: SSMS: FROM dbo.Goal g (...) JOIN dbo.Division d ON g.DivisionKey = d.DivisionId EF: FROM [dbo].[Goal] AS [Extent1] (...) INNER JOIN [dbo].[Division] AS ...
-
MySQL查询以特定顺序返回结果而无需按顺序排序(MySQL query to return results in specific order without order by)[2022-11-12]
我建议在数据库中添加一个Sort列来强制自定义订单。 无论如何,你可以使用FIND_IN_SET函数使用一个小技巧: SELECT id_product, name FROM sample WHERE id_product IN (675,123,745,954) ORDER BY FIND_IN_SET(id_product, '675,123,745,954') 演示 I suggest adding a Sort column in the database to force a custom or ... -
第一个“处理顺序”在SQL中有点误导。 语句在执行之前编译 。 实际执行可能看起来与SQL本身非常不同(事实上,执行表示为DAG指导的非循环图 - 它看起来与SELECT语法完全不同)。 DISTINCT ON是一个Postgres扩展。 它非常方便 - 让您在括号中每个值获得一行。 而且,您可以控制哪一行。 假设你有这样的数据: a b c A1 3 1 A1 2 2 A1 4 3 A2 6 4 A2 1 5 如果要指定每个值需要一行,则使用 ...
-
如果订购订单时有联系不稳定。 LiveDemo CREATE TABLE #TestSort ( Id INT NOT NULL IDENTITY (1, 1) PRIMARY KEY, Value INT NOT NULL ) ; DECLARE @c INT = 0; WHILE @c < 100000 BEGIN INSERT INTO #TestSort(Value) VALUES ('2'); SET @c += 1; END 例: SELECT TOP 10 * FROM ...
-
SQL:根据另一个查询的值顺序对查询结果进行排序(SQL: Sort Results of a Query Based on the Order of values from another Query)[2023-09-21]
您可以使用窗口函数执行此操作: select company, department, sum(sales) from t group by company, department order by sum(sum(sales)) over (partition by company) desc, company; 您还可以在select子句中包含表达式,以查看整个公司的销售总额。 You can do this using window functions: select company, depart ... -
返回查询结果的顺序与我的`IN(...)`语句中的值相同(Return query results in same order as the values in my `IN(…)` statement)[2022-06-07]
只需在ORDER BY子句中使用FIELD() ORDER BY FIELD(user_id, 20, 24, 23, 26, 27, 28, 25) ASC MySQL FIELD() just use FIELD() in the ORDER BY clause ORDER BY FIELD(user_id, 20, 24, 23, 26, 27, 28, 25) ASC MySQL FIELD() -
按照它们在IN()语句中调用的顺序返回mySQL结果(Return mySQL results in the order they're called in an IN() statement)[2021-08-27]
是的,请查看“按SQL IN()子句中的值顺序排序”答案。 解决方案在那里得到了很好的描述。 Yes, take a look at "Ordering by the order of values in a SQL IN() clause" answers. The solution is very well described there. -
使用WITH子句IN的结果,其中主要查询的STATEMENT(Using the results of WITH clause IN where STATEMENT of main query)[2020-01-30]
这有帮助吗? ;WITH summary AS( SELECT ed2.customer,ed2.saledate, ROW_NUMBER()OVER(PARTITION BY ed2.customer ORDER BY ed2.saledate)AS rk FROM Filteredxportdocument ed2) SELECT ed.totalamountincvat, ed.saledate, ed.name AS SaleRef, ed.customer, ed.customername, ... -
ANSI意味着在ORDER BY子句中使用CASE表达式: SELECT setting_value FROM dba.system_settings WHERE setting_name IN ('RequestWebServiceURL', 'UNITS', 'FACTOR') ORDER BY CASE setting_name WHEN 'RequestWebServiceURL' THEN 1 WHEN 'UNITS' THEN 2 ...
-
可能是因为你正在使用GETDATE(),它每次都会返回一个不同的值? 您可以尝试在那里设置固定日期而不是GETDATE()吗? Could it be because you are using GETDATE() which would have returned a different value each time? Can you try putting a fixed date in there instead of GETDATE()?