是否可以使用webpart GET值创建类实例

时间:2017-02-02 11:18:04

标签: f# get suave

我创建了一个游戏"我尝试使用我的webpart路径中的值来创建它的实例。

我的实例需要一个playerName,所以我尝试创建一个名为value

的实例
class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
                <property name="connectionTimeout" value="900000" />
                <property name="readTimeout" value="0" />
                <property name="httpClient" ref="httpClient" />
                <property name="credentials" ref="credentials"/>
            </bean>
        </property>



<bean id="httpClient" class="org.apache.http.client.HttpClient">
        <!-- Not Sure what configuration to add here -->
    </bean>

    <bean id="credentials" class="org.apache.http.auth.UsernamePasswordCredentials">
        <constructor-arg value="${userName}:${password}" />
    </bean>

但它不起作用,因为这个表达式应该是HttpContext类型而不是游戏类型。

我想创建一个实例,并根据我的路径值调用类的方法。

1 个答案:

答案 0 :(得分:3)

首先:你不能从你的功能中返回2种不同的类型

let php =
    request (fun r ->
        match r.queryParam "playerName" with
        | Choice1Of2 name ->  new game.Game(1,name,"hyy")
                              ^^^^^^^^^^^
                              //should probably be a OK 
        //OK (sprintf "playerName: %s" name)
        | Choice2Of2 msg -> BAD_REQUEST msg)

然后你也应该Jsonify你的Game对象。所以你的代码可能看起来像这样

| Choice1Of2 name ->  
      new game.Game(1,name,"hyy")
      |> toJson
      |> OK

请将toJson替换为您选择的Json图书馆

相关问题