小编han*_*nsi的帖子

mongoDB查询"WHERE _id>阈值"

我怎么能有类似SQL"... WHERE _id>阈值"的mongo查询

我试过以下,但它没有给我任何结果.

 db.things.find(_id: {$gt: someid} });
Run Code Online (Sandbox Code Playgroud)

是因为_id字段有点特殊,因为它有格式吗?

_id : {"$oid" : "someid"} 
Run Code Online (Sandbox Code Playgroud)

filter mongodb

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

maven项目中的getClass().getResourceAsStream()

我的maven项目的pom.xml如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>groupId</groupId>
  <artifactId>artifactId</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <build>
   <sourceDirectory>src/main/java</sourceDirectory>
   <resources>
    <resource>
     <directory>src/main/resources</directory>
    </resource>
   </resources>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

在src/main/resources目录中,我有一个名为test的文件.在src/main/java目录中,我有一个包含以下行的类:

System.out.println(this.getClass().getResourceAsStream("test"));
Run Code Online (Sandbox Code Playgroud)

当代码行在Eclipse中运行时,我得到输出

java.io.BufferedInputStream@1cd2e5f 
Run Code Online (Sandbox Code Playgroud)

当我将项目导出为.jar并运行它时,我得到输出

 null
Run Code Online (Sandbox Code Playgroud)

我配置错了吗?

resources maven

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

(Spring MVC/Jackson)将查询参数映射到@ModelAttribute:LOWERCASE_WITH_UNDERSCORE到SNAKE_CASE失败

@GetMapping("item")
public @ResponseBody String get(@ModelAttribute Item item)
Run Code Online (Sandbox Code Playgroud)

Item 有属性

  • name

  • itemType

当我访问/item?name=foo&item_type=baritem被只填充name itemType.

我尝试了很多东西来获取itemType映射的属性item_type.

  • 新增@JsonProperty( "ITEM_TYPE")里面ItemitemType属性.这里描述.
  • 添加了一个JackonConfiguration,将propertyNamingStrategy设置为PropertyNamingStrategy.SNAKE_CASE.这里描述.
  • 将spring.jackson.property-naming-strategy = SNAKE_CASE添加到我的Spring Boot application.properties文件中.这里描述
  • Item类级别添加了PropertyNamingStrategy .这里描述.

我怎么解决这个问题?

顺便说一句.对于传入的不是传出的JSON序列化我只有这个问题Item.


更新04/24/17:

下面是一个最小的示例,用于演示问题:访问时/item您会看到"传出"的JSON序列化有效,但访问时/item/search?name=foo&item_type=bar它不适用于'传入'JSON反序列化.

项目

package sample;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

@JsonNaming(SnakeCaseStrategy.class)
public class Item implements Serializable {
    private String name; …
Run Code Online (Sandbox Code Playgroud)

spring naming spring-mvc jackson spring-boot

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

jquery跨域认证

我将Jetty服务器配置为允许跨域http请求(allowedOrigins =*),并使用其CrossOriginFilter允许跨域身份验证(allowCredentials = true).没有身份验证要求的跨域http请求正常工作.现在谈到需要身份验证的http调用时,使用JQuery无法解决问题.我使用以下代码并遵循此示例:http://www.aswinanand.com/2009/01/http-basic-authentication-using-ajax/

function login(username, password) {
$.ajax({
    type: "GET",
    contentType: "application/json",
    dataType: "json",
    url: url,
    beforeSend: function(xhr) {
        var base64 = Base64.encode(username + ":" + password);
        xhr.setRequestHeader("Authorization", "Basic " + base64);
        xhr.withCredentials = true;
    },
    error: function(data){
        alert("error");
    },
    success: function(data){
        alert("success"); 
    }
});
Run Code Online (Sandbox Code Playgroud)

在HTTPFox中,我看到以下对服务器的请求:

OPTIONS /login HTTP/1.1
...
Access-Control-Request-Method   GET
Access-Control-Request-Headers  authorization,content-type
Run Code Online (Sandbox Code Playgroud)

服务器以a响应

HTTP/1.1 204 No Content
...
Allow   OPTIONS,GET,HEAD
Run Code Online (Sandbox Code Playgroud)

我也使用下面的选项,这没有什么区别.

$.ajax({
    ...
    username: username,
    password: password,
    ...
}
Run Code Online (Sandbox Code Playgroud)

错误功能始终触发.有谁知道问题可能是什么?

authentication jquery http jetty cross-domain

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

Spring Caching - 忽略键的参数

我想缓存一个具有可选参数的简单 getter 的结果(下面示例中的 user-agent)。如何在不考虑可选用户代理参数的情况下指示创建密钥?

@Cacheable(value="bookCache")
public Book getBooks(@RequestHeader(value = "user-agent", required = false) String userAgent) 
...
Run Code Online (Sandbox Code Playgroud)

spring caching key spring-cache

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

jQuery似乎不会自动解析JSON

这是我的客户端jQuery代码:

$.ajaxSetup ({
   contentType: "application/json",
   datatype: 'json'
});

$.ajax({
   type: "POST",
   url: "http://localhost:1234/path",
   data: JSON.stringify(myData),
   success: function(aString){
      alert(aString);
   },
   error: function(errorData){
      alert(errorData);
   }
});
Run Code Online (Sandbox Code Playgroud)

这是服务器发出的数据:

200
Content-Type: application/json

"aStringsData"
Run Code Online (Sandbox Code Playgroud)

在警报中,显示"aStringData"的引号.但是,由于我希望从数据类型:'json'发生自动JSON.parse,我希望引用被删除.我错了吗?

string jquery parsing json

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

aspectj-maven-plugin 和 Java 7

我必须如何设置 pom.xml 以便 aspectj-maven-plugin 使用 Java 7 进行编译?

当我使用当前配置(见下文)进行编译时,我总是收到一条消息,抱怨我使用了某些 Java 7 特定功能,例如

error: multi-catch statement is not supported in -source 1.5
Run Code Online (Sandbox Code Playgroud)

我使用 eclipse,在项目属性 -> java 编译器中它说 1.5 表示合规性级别、源代码、目标。我究竟做错了什么?

这里提出一个非常相似的问题,但该解决方案对我不起作用,我已经在 org.aspectj 的 1.7.4 版上。

这个问题也可以改写为:

如何让 maven 使用 Java 7 编译我的代码并编织方面?

我不必使用 aspectj-maven-plugin。但是还有什么其他方法有效呢?

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.stuff</groupId>
    <artifactId>artifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.5</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions> …
Run Code Online (Sandbox Code Playgroud)

java plugins aspectj version maven

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

JQuery ajax调用的返回值

无论 ajax 调用是否成功,我都希望这个函数返回。有什么办法可以做到这一点吗?我下面的代码不这样做。

function myFunction(data) {
var result = false;
$.ajax({
    type: "POST",
        contentType: "application/json",
        dataType: "json",
        url: "url",
        data: data,
        error: function(data){
             result = false;
             return false;
        },
        success: function(data){
            result = true;
            return true;
        }
     });
     return result;
}
Run Code Online (Sandbox Code Playgroud)

ajax jquery return

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

角度材料:线性步进器的编程“下一步”

我想使用角度材料步进器,但在进行第二步之前我需要进行一些异步服务调用。我怎样才能做到这一点?我可以向下一个按钮添加一个点击处理程序,但这不会等待异步调用返回并继续进行。这是一个plnkr

在 html 模板中,我会有按钮:

  <button mat-button matStepperNext (click)="onNext()">Next</button>
Run Code Online (Sandbox Code Playgroud)

在组件中:

  onNext() {
     let promise = service.validateData()
  }
Run Code Online (Sandbox Code Playgroud)

有没有办法使用已完成的步骤属性?

angular-material2 angular angular-material-stepper

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

JGit:推送到特定分支

我在github上有两个分支:master和development.我想将新创建的文件推送到开发分支.

    String user = "user";
    String password = "password";
    String localPath = "local";
    String remotePath = "https://github.com/some/git.git";
    Git.cloneRepository().setBranch("refs/heads/development").setURI(remotePath).setDirectory(new File(localPath)).call();
    Git localGit = Git.open(new File(localPath));         
    localGit.checkout().setName("origin/development").setUpstreamMode(SetupUpstreamMode.TRACK).call();

    new File("local/test").createNewFile();

    localGit.add().addFilepattern(".").call();
    localGit.commit().setMessage("message").call();
    localGit.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call();
Run Code Online (Sandbox Code Playgroud)

我得到的是一个

  TransportException: Nothing to push.
Run Code Online (Sandbox Code Playgroud)

有什么问题?

更新: 我可以通过删除checkout命令使其工作.由于克隆已经检出指定的分支,这在我之前并不清楚.

git branch push jgit

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