小编Chr*_*ris的帖子

REST使用Java传递参数

我已经使用一些webmethods构建了一个REST Web服务.但是我没有把它传递给这些方法.

IE

@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello(String firstName, String lastName){

    return "Hello " + firstname + " " + lastname
}
Run Code Online (Sandbox Code Playgroud)

我将如何调用该方法以及如何传递参数firstname和lastname?我试过这样的事情:

ClientConfig config = new DefaultClientConfig();

Client client = Client.create(config);

WebResource service = client.resource(getBaseURI());

ClientResponse response = service.path("hello")
.accept(MediaType.TEXT_PLAIN).put(ClientResponse.class);
Run Code Online (Sandbox Code Playgroud)

但是我在哪里添加参数?

谢谢你的帮助,最好的问候,克里斯

java parameters rest

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

Android Layout_weight

也许我误解了layout_weight参数,但我无法理解为什么这样的东西不起作用......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" android:weightSum="1">

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>

<TextView
    android:id="@+id/textView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.2"
    android:text="TextView" 
    android:background="@color/apr_brightyellow"/>

<TextView
    android:id="@+id/textView3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:text="TextView" 
    android:background="@color/apr_yellow"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我在LinearLayout中有三个或更多文本视图.我想将它们放在宽度为百分比的列中.这就是它产生的东西:

layout_weight设置为0.3/0.2/0.5

Android layout_weight不正确

然后我改变了layout_weight参数,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" android:weightSum="1">

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="TextView" android:layout_weight="0.3" android:background="@color/apr_blue"/>

<TextView
    android:id="@+id/textView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.3"
    android:text="TextView" 
    android:background="@color/apr_brightyellow"/>

<TextView
    android:id="@+id/textView3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.4"
    android:text="TextView" 
    android:background="@color/apr_yellow"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

现在我按照自己的意愿得到它:

layout_weight设置为0.3/0.2/0.5

Android layout_weight正确

它是一个错误还是我真的误解了layout_weight的全部内容?

android relativelayout android-linearlayout

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

dockerized postgresql与卷

我对码头工人比较新.我想建立一个postgres数据库,但我想知道如果重新创建容器,如何确保数据不会丢失.

然后我偶然发现了命名卷(不是绑定卷)以及如何使用它们.但是......在Dockerfile中你不能使用命名卷.例如data:/ var/lib等.据我所知,使用Dockerfile它总是一个匿名卷.因此,每次我重新创建一个容器时,它都会获得自己的新卷.

所以这是我的问题:

首先:如何更新或重新创建容器,以便新容器中的postgres数据库引用相同的数据并且不会丢失对先前创建的匿名卷的引用.

其次:如何使用yml文件?是否可以将这样的数据库容器的多个副本引用到一个卷?(高可用性模式)?

如果有人能给我一些暗示或最佳实践,那真是太好了.

先感谢您.

postgresql volumes docker

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

Java Map <Integer,HashMap <String,String >>

我需要将结果集转换为地图地图.我没有使用地图列表的原因是因为我不想遍历整个List来获取特定的行.

我现在面临的问题是,如果索引大于16,则不再对HashMap的条目进行排序.

现在我尝试了以下一个简单的测试:

    public static void main(String[] args) {

    Map<Integer, String> map = new HashMap<Integer, String>();

    //creating 20 rows from 1 to 20
    for (int i = 1; i <= 20; i++){
        map.put(i, "ROW "+i);   
    }


    //returning all the rows the map contains. Look at position 16.
    for(int key : map.keySet()){
        System.out.println(key);    
    }
}
Run Code Online (Sandbox Code Playgroud)

输出如下(查看位置16到20.它们完全无序):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 16 19 18 20

我真的很感激,如果有人能解释为什么会这样.

顺便说一下:

我不能使用这样的东西:

for (int …
Run Code Online (Sandbox Code Playgroud)

java collections list hashmap map

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