小编use*_*874的帖子

RestTemplate uriVariables未展开

我尝试使用弹簧RestTemplate.getForObject()访问休息端点,但我的uri变量未展开,并作为参数附加到url.这是我到目前为止所得到的:

Map<String, String> uriParams = new HashMap<String, String>();
uriParams.put("method", "login");
uriParams.put("input_type", DATA_TYPE);
uriParams.put("response_type", DATA_TYPE);
uriParams.put("rest_data", rest_data.toString());
String responseString = template.getForObject(endpointUrl, String.class, uriParams);
Run Code Online (Sandbox Code Playgroud)

endpointUrl变量的值是,http://127.0.0.1/service/v4_1/rest.php并且它的确是它所谓的,但我希望http://127.0.0.1/service/v4_1/rest.php?method=login&input_type...被调用.任何提示都表示赞赏.

我正在使用Spring 3.1.4.RELEASE

问候.

java spring resttemplate

22
推荐指数
2
解决办法
2万
查看次数

spring resttemplate url编码

我尝试使用spring resttemplate进行简单的休息调用:

private void doLogout(String endpointUrl, String sessionId) {
    template.getForObject("http://{enpointUrl}?method=logout&session={sessionId}", Object.class,
            endpointUrl, sessionId);
}
Run Code Online (Sandbox Code Playgroud)

endpointUrl变量包含service.host.com/api/service.php之类的内容

不幸的是,我的调用导致org.springframework.web.client.ResourceAccessException:I/O错误:service.host.com%2Fapi%2Fservice.php

所以spring似乎在创建url之前编码了我的endpointUrl字符串.是否有一种简单的方法可以防止弹簧这样做?

问候

java spring resttemplate

13
推荐指数
4
解决办法
5万
查看次数

手动创建Json字符串

我正在尝试用Java手动创建一个Json结构.最后,我需要一个我的Json对象的字符串表示.由于我的项目已经依赖于GSON,我想使用它.但经过几个小时的尝试和谷歌搜索,我想,我完全误解了一些东西.

目前,我有以下(非工作)代码:

JsonObject user_auth = new JsonObject();
user_auth.addProperty("user_name", username);
user_auth.addProperty("password", password);
JsonObject rest_data = new JsonObject();
Gson gson = new Gson();
rest_data.addProperty("user_auth", gson.toJson(user_auth));
rest_data.addProperty("application", APPLICATION_NAME);
String payload = gson.toJson(rest_data);
Run Code Online (Sandbox Code Playgroud)

我面临的问题是"user_auth"元素获得转义引号(\"而不是"当它被添加到外部元素时.如何防止这种情况?我也尝试使用

rest_data.addProperty("user_auth", user_auth.toString());
Run Code Online (Sandbox Code Playgroud)

但这确实是一样的.

问候,

java json gson

4
推荐指数
1
解决办法
2万
查看次数

定期刷新日历中的事件

在arshaw的完整日历文档中,我找到了我认为需要使用的方法:.fullCalendar( 'refetchEvents' )但是由于我完全不熟悉JavaScript,因此我没有关于如何使用此函数的计划。

我想知道一种简单的方法,可以使日历从事件源重新加载事件并定期(例如每30秒)重新呈现它们。

任何提示将不胜感激。

javascript jquery fullcalendar

3
推荐指数
1
解决办法
2334
查看次数

访问注释中的静态字段

我尝试在Groovy类中使用Java注释,但很难将java类的静态字段设置为参数:

注释:Id.java

package x.y.annotations;

import java.lang.annotation.ElementType;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Id {

    public Class<Adapter> adapter();

    public Class<Object> targetType();

    public String targetAttribute();

    public String onDelete();

}
Run Code Online (Sandbox Code Playgroud)

带有静态字段的java类:XPerson.java

package x.y.static.domain;

public class XPerson {

    public static String ID;

}
Run Code Online (Sandbox Code Playgroud)

还有发生问题的groovy类:Person.groovy

package x.y.domain

import x.y.annotations.Id
import x.y.static.domain.XPerson

class Person {

    @Id(adapter = Adapter, targetType = XPerson, targetAttribute = XPerson.ID, onDelete = "delete")
    long id
}
Run Code Online (Sandbox Code Playgroud)

Eclipse标记"targetAttribute = XPerson.ID"部分:

Groovy:预期'xydomain.XPerson.ID'是java.lang.String类型的内联常量,而不是@ xyannotations.Id中的属性表达式

我也尝试了"XPerson.@ ID"之类的东西,或者为ID字段定义了一个getter,但没有任何帮助.

任何提示都会很棒.

问候,迈克尔

groovy annotations

2
推荐指数
1
解决办法
3560
查看次数