小编Sam*_*age的帖子

验证表单是否已更改

我正在编写一个验证器,需要测试弹簧形式对象是否已更改.

在验证程序中,如果未对表单进行任何更改,则应显示错误.

有弹簧机制吗?

这是因为我提交时会进行非常昂贵的Web服务更新调用,如果没有进行任何更改,我需要阻止进行webservice调用.

干杯.

java spring spring-webflow

8
推荐指数
1
解决办法
1770
查看次数

thymeleaf url 中的可选参数

我正在使用以下代码在 thymeleaf 中生成一个 url。

@{/schedule/data/bookableTimes/{teacherUsername}(teacherUsername=${teacher.user.username},lessonLengthType=${lessonLengthType},studentId=${#httpServletRequest.getParameter('studentId')})}
Run Code Online (Sandbox Code Playgroud)

当提供 studentId 时,这非常有效。但是,我也想满足不提供 studentId 的情况。目前,如果没有提供 studentId,它将生成一个像这样的 url

/schedule/data/bookableTimes/teacher?lessonLengthType=full&studentId=
Run Code Online (Sandbox Code Playgroud)

但是,这不是我想要的,在 studentId 为空的情况下,我宁愿根本不生成 url 的 studentId 部分。有没有一种简单的方法可以使用百里香叶来做到这一点?

thymeleaf

5
推荐指数
1
解决办法
853
查看次数

如何在grails测试中比较JSON

我在Grails中有一个控制器,它在JSON中返回一个响应.

我写了一个大致类似的测试

test(){
     def expectedResponse=JSON.parse('[{"username":"user","startDate":"2010-11-30"}]')
    ...
            def actualResponse=JSON.parse(response.text)

            println "Expecting: ${expectedResponse.toString()}"
            println "Actual: ${actualResponse.toString()}"

            assertEquals(expectedResponse.toString(), actualResponse.toString())
    ...
        }
Run Code Online (Sandbox Code Playgroud)

这按预期工作

Expecting: [{"username":"user","startDate":"2010-11-30"}]
Actual: [{"username":"user","startDate":"2010-11-30"}]
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否有更好的方法来做这个而不采用字符串比较.也许某些东西可以让我灵活地能够在不使我的测试用例无效的情况下为响应添加属性?

我可以自己构建这个,但我希望将某种JSON比较内置到该语言中.

更新:我尝试直接执行此操作,没有toString并且结果不一致,不太确定原因,它在一个阶段工作然后突然得到了这个.我看不出任何会导致差异的代码更改

groovy.lang.MissingMethodException: No signature of method: com.siggysale.MainControllerTests.assertEquals() is applicable for argument types: (org.codehaus.groovy.grails.web.json.JSONArray, org.codehaus.groovy.grails.web.json.JSONArray) values: [[], []]
Run Code Online (Sandbox Code Playgroud)

grails groovy

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

如何从枚举单例的工厂方法创建 spring bean

我试图在这里弹性化示例代码

http://xeiam.com/xchange_examplecode.jsp

  public static void main(String[] args) {

    // Demonstrate the public market data service
    // Use the factory to get the version 2 MtGox exchange API using default settings
    Exchange mtGoxExchange = ExchangeFactory.INSTANCE.createExchange(MtGoxExchange.class.getName());

    // Interested in the public market data feed (no authentication)
    PollingMarketDataService marketDataService = mtGoxExchange.getPollingMarketDataService();
Run Code Online (Sandbox Code Playgroud)

基本上我希望将 PollingMarketDataService 或 Exchange 作为 spring bean 注入。

然而上面的 ExchangeFactory 是一个枚举,当我尝试这个时:

<beans:bean id="exchangeFactory" class="com.xeiam.xchange.ExchangeFactory" factory-method="valueOf">
    <beans:constructor-arg value="INSTANCE"/>
</beans:bean>

<beans:bean id="mtGoxExchange" factory-bean="exchangeFactory" factory-method="createExchange">
    <beans:constructor-arg value="com.xeiam.xchange.mtgox.v2.MtGoxExchange"/>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)

ExchangeFactory 为空。

java spring

0
推荐指数
1
解决办法
1603
查看次数

标签 统计

java ×2

spring ×2

grails ×1

groovy ×1

spring-webflow ×1

thymeleaf ×1