我怎么能有类似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) 我的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)
我配置错了吗?
@GetMapping("item")
public @ResponseBody String get(@ModelAttribute Item item)
Run Code Online (Sandbox Code Playgroud)
Item 有属性
name
itemType
当我访问/item?name=foo&item_type=bar了item被只填充name 未用itemType.
我尝试了很多东西来获取itemType映射的属性item_type.
Item的itemType属性.这里描述.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) 我将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)
错误功能始终触发.有谁知道问题可能是什么?
我想缓存一个具有可选参数的简单 getter 的结果(下面示例中的 user-agent)。如何在不考虑可选用户代理参数的情况下指示创建密钥?
@Cacheable(value="bookCache")
public Book getBooks(@RequestHeader(value = "user-agent", required = false) String userAgent)
...
Run Code Online (Sandbox Code Playgroud) 这是我的客户端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,我希望引用被删除.我错了吗?
我必须如何设置 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) 无论 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) 我想使用角度材料步进器,但在进行第二步之前我需要进行一些异步服务调用。我怎样才能做到这一点?我可以向下一个按钮添加一个点击处理程序,但这不会等待异步调用返回并继续进行。这是一个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)
有没有办法使用已完成的步骤属性?
我在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命令使其工作.由于克隆已经检出指定的分支,这在我之前并不清楚.
jquery ×3
maven ×2
spring ×2
ajax ×1
angular ×1
aspectj ×1
branch ×1
caching ×1
cross-domain ×1
filter ×1
git ×1
http ×1
jackson ×1
java ×1
jetty ×1
jgit ×1
json ×1
key ×1
mongodb ×1
naming ×1
parsing ×1
plugins ×1
push ×1
resources ×1
return ×1
spring-boot ×1
spring-cache ×1
spring-mvc ×1
string ×1
version ×1