小编Hir*_*oki的帖子

PUT方法(RESTful)不能用作更新资源的方法

根据这篇文章(http://restcookbook.com/HTTP%20Methods/put-vs-post/),PUT应该作为更新资源的方法.

但是,使用JAX_RS 2.0和Jersey 2.0练习RESTful,我认为它不会更新特定资源.(即我正在使用JAX_RS 2.0和Jersey 2.0学习RESTful)

这是一个这样的资源.

<customer>
    <name>Before</name>
    <postcode>111</postcode>
</customer>
Run Code Online (Sandbox Code Playgroud)

我想要做的是更新(也许我应该说"替换")这个资源.

    ClientConfig config = new ClientConfig();
    Client client = ClientBuilder.newClient(config);
    WebTarget target =  client.target("http://xxx/yyy/zzz/end.cust");

    Customer cust = new Customer();
    cust.setName("After");
    cust.setPostcode(222);

    target.path("Before").request().put(Entity.xml(cust));
Run Code Online (Sandbox Code Playgroud)

@Id注释在"Customer"类中设置为"Name",因此路径"Before"应该作为ID工作,第一个资源(名为"Before")应该替换为第二个资源(名为"After") ").

但是,在执行上面的编码之后,"之前"资源仍然存在,并且有一个新的"After"resrouce.似乎PUT方法可以创建一个新资源,而不是更新某些东西.(即有"之前"和"之后"资源,并且没有更新任何内容)

我测试了一个POST方法以创建一个新资源,并按照我的预期创建了一个新资源.

如果你看到我做错了什么或需要做什么,你能提出一些建议吗?

编辑

我将添加服务器端代码.用@PUT注释的方法是这样的.

 @PUT
 @Path("{id}")
 @Consumes({"application/xml", "application/json"})
 public void edit(@PathParam("id") String id, Customer entity) {
     super.edit(entity);
 }
Run Code Online (Sandbox Code Playgroud)

这是在一个名为CustomerFacadeREST.java的类中,在我创建"来自数据库的RESTful服务"后自动创建.

根据NetBeans的文档,super.edit()方法最初是这样的.

 public void edit(T entity) {
 getEntityManager().merge(entity);
 }
Run Code Online (Sandbox Code Playgroud)

在"Customer"类中,@ Id以这种方式设置为"name"值.

 public class Customer implements Serializable {
     private static final long serialVersionUID = 1L; …
Run Code Online (Sandbox Code Playgroud)

java rest jax-rs put http-method

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

C#如何创建和保存resx文件

根据Microsoft Developer Network,可以通过这种方式生成resx文件.(http://msdn.microsoft.com/en-us/library/gg418542%28v=vs.110%29.aspx)

using (ResXResourceWriter resx = new ResXResourceWriter("filename.resx"))
  {
     resx.AddResource("KeyString", "ValueString");         
  }
resx.Generate();
Run Code Online (Sandbox Code Playgroud)

但是,我找不到新生成的resx文件.(我认为生成的文件是在本地机器中设置的,但它似乎并不存在.)

我一直在寻找(1)如何检查生成的resx文件的位置,以及(2)如何将其保存到文件夹中.(即将以编程方式生成的resx文件保存到文件夹中,因为我们可以使用"XmlDocument.Save("FileName")"方法创建并保存xml文件.)

这是我编码的一部分.

    if (saveFileDialog.ShowDialog() == DialogResult.OK) {
        using (ResXResourceWriter resx = new ResXResourceWriter("resxfile.resx")) {                   

            for (int i = 0; i < rowArray.Length; i++) {                    
                string keyStrings = rowArray[i][Key].ToString();     
                string valueStrings = rowArray[i][Value].ToString();
                resx.AddResource(keystrings, valueStrings);
            }
            resx.Generate();
        }                                     
    }
Run Code Online (Sandbox Code Playgroud)

这不保存应该从"for"循环生成的resx文件.如果您愿意提供任何见解,我将不胜感激.

c# xml resx

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

实现Comparable接口会产生"UnsupportedOperationException:ListIterator不支持set"错误

我想要做的是用Java中的属性(Integer)对对象的arraylist进行排序.

我发现了几篇关于使用Comparable/Comparator进行此操作的帖子,但它们似乎都与"java.lang.UnsupportedOperationException"错误无关.所以,我在这里写一个问题.

我按照这个页面,一直在尝试使用Comparable接口.

这是我编码的一部分

public class Word implements Comparable<Word>{

private String wordName;
private int number;

 // There are only simple constructers, getters and setters 

@Override
public int compareTo(Word word) {
    int compareNumber = ((Word) word).getNumber();
    return compareNumber - this.number;

    }
}
Run Code Online (Sandbox Code Playgroud)

主要方法是这样的.

public static void main(String[] args) {
    //There are some irrelevant methods and fields

    List newWordList = new ArrayList<>();

    for (String wordName : WordList) {
        //WordList is of List<String>, containing several "wordName" (i.e. string values)

        //Get how …
Run Code Online (Sandbox Code Playgroud)

java

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

react-navigation:是否可以将回调传递给子级(egchangeHandler)?

我一直在尝试将回调传递到屏幕中

这是我的实验摘录...

export default class Test extends React.Component {
    constructor(props) {
        super(props);
    };

    handleOnPress(data){
    //How do we pass this callback to "Home" or "Sub"?
    }

    render() {
        const Navigator = StackNavigator({
            Home: {screen: Home},
            Sub:  {screen: Sub}
        });
        let data = {blah:"blah blah"};

        return (<Navigator screenProps={data} />);
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我可以this.props.screenProps.blah在这两个HomeSub。我认为能够传递道具也意味着能够传递回呼,但我觉得我不对。

有没有人遇到这个问题?

任何建议将被认真考虑。

reactjs react-navigation

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

React Navigation:从其导航器调用屏幕功能 - 有可能吗?

我一直在尝试从其屏幕调用导航器屏幕中的函数

为了澄清这一点,这是我的代码片段...

//ScreenA.js
export default class ScreenA extends React.Component {
    showWarning(){
        this.setState({showWarning: true});
        setTimeout(function() {
            this.setState({showWarning: false});
        }.bind(this), 3000);
    }

    render() {
        return (
          <View  style={{backgroundColor : this.state.showWarning ? "#red" : "#blue"}}>
              {this.state.showWarning && <Warning />}
          </View>
        )
    }
}

//Nagigator.js
default export const Navigator = StackNavigator({
  ScreenA: {screen: ScreenA},
  ScreenB: {screen: ScreenB},
});

//App.js
export default class App extends React.Component {
    handleSubmit(qrCode){
        if(qrCodeIsInvalid){
            this.navigator.ScreenA.showWarning();
            //This is just a sudo code.
            //How do we call ScreenA.showWarning here?
        } …
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-navigation

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

Scrapy:抓取多个页面并在单个数组中生成结果

我想做的是抓取多个页面并在单个数组中产生结果。

我找到了这篇文章,它描述了如何抓取多个页面并从每个抓取的页面中生成文本。

我参考了这种方法(并对其进行了一些修改),这是我的蜘蛛看起来像......

from scrapy import Request
from test_project.items import PriceSpiderItem

class RoomsSpider(scrapy.Spider):
    name = 'rooms'
    allowed_domains = ['sample.com']
    start_urls = ['http://sample.com/rooms']

    def parse(self, response):
        for resource in response.xpath('.//*[@class="sample"]'):
            item = PriceSpiderItem()
            item['result'] = resource.xpath("text()").extract_first()
            yield item

        nextUrl = response.xpath('//*[@label="Next"]/@href').extract_first()

        if(nextUrl is not None):
            absoluteNextUrl = response.urljoin(nextUrl)
            yield Request(url=absoluteNextUrl, callback=self.parse)
Run Code Online (Sandbox Code Playgroud)

然而,通过这种方法,结果将看起来像......

{
 "items" : [
  {"result": "blah blah"},
  {"result": "blah blah blah blah blah"},
  {"result": "blah blah blah blah"},
  ...
  etc.
  ...
  {"result": "blah blah blah …
Run Code Online (Sandbox Code Playgroud)

python scrapy

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

在setTimeout中更新状态(React和React-Native)

我一直试图实现的是state基于Javascript的计时器更新并再次更新相同的状态.

我无法实现这一点的原因似乎是stateReact.js 的本质.

这是我的实验片段......

render() {
    if (this.props.hasError) {
        setTimeout(function(){this.setState({showWarning: true}); }.bind(this), 3000);
    }
    return (
      <View>
        <Blah warning={this.state.showWarning} />
      </View>
    );
}
Run Code Online (Sandbox Code Playgroud)

所以,目标是改变状态only just a few seconds if there is a specific props provided.

如果this.props.hasError过于频繁地更新,这种方法似乎达到了更新状态的极限.

如果这个问题太基础,请道歉.任何建议将不胜感激.

javascript reactjs react-native

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

我可以根据使用情况使 Dynamo DB 表不可用吗?

我是 AWS 新手,现在我想在我的爱好项目中以按需模式使用 DynamoDB 表。

是否可以在发出一百万个读/写请求单元后停止该表?我只是想确保每月为写入请求支付的费用不会超过 1.25 美元,为读取请求支付的费用不会超过 0.25 美元,这在本页中有记录。(我使用俄亥俄州美国东部)

amazon-web-services amazon-dynamodb

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

Google Drive API:如何获得指向Google文档的可共享链接?(alternateLink,webViewLink返回null)

我提到了这个帖子这个帖子,对于如何获得一个链接仍然毫无头绪Google Doc

根据官方文档, webViewLink “用于在相关的Google编辑器或浏览器中打开文件的链接”。但是,除了之外,它什么都不返回null,而其他属性(例如id或mimeType)则返回期望值。(也webContentLink返回null。)

我可以简单地使用此URL,https://drive.google.com/open?FILE_ID_HERE但不确定在其他人的浏览器中是否可以使用。

我将不胜感激任何建议!

php google-drive-api

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

ReactJS:this.setState会立即生效吗?

我想知道this.setState改变是否立即出现,因为它似乎没有这样做.

为了说明,我们假设有一个复选框....

class Example extends React.Component {
  constructor(props) {
  super(props);
  this.state = {
    switch: false
  };
  this.switch = this.switch.bind(this);
}

clickCoverSwitch(){
  console.log("Before clicking - ", this.state.switch);
  this.setState({switch: !this.state.switch});
  console.log("Now, the state is - ", this.state.switch);
}

render() {
    return (
       <input onClick={this.clickCoverSwitch} defaultChecked={this.state.coverSwitch} type="checkbox">
       </input>
    );
}
Run Code Online (Sandbox Code Playgroud)

在此示例中,默认情况下该复选框处于关闭状态 - 这是正常的.

但是,单击开关(即复选框)时,我在控制台中看到以下消息.

Before clicking - false

Now, the state is - false

应该显示第二行true,因为this.state.switch应该已经改变了this.setState({switch: !this.state.switch}).

我不确定我应该怎么解释这一点.任何建议将被认真考虑!

reactjs react-native

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