我想从MongoDB中的文档中检索子文档.我有以下文件:
{
"_id" : "10000",
"password" : "password1",
"name" : "customer1",
"enabled" : true,
"channels" : [
{
"id" : "10000-1",
"name" : "cust1chan1",
"enabled" : true
},
{
"id" : "10000-2",
"name" : "cust1chan2",
"enabled" : true
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
{
"id" : "10000-1",
"name" : "cust1chan1",
"enabled" : true
}
Run Code Online (Sandbox Code Playgroud)
但是,到目前为止我能做的最好的事情是使用以下查询:
db.customer.find({"channels.id" : "10000-1"}, {"channels.$" : 1, "_id" : 0})
Run Code Online (Sandbox Code Playgroud)
但这给了我以下结果:
{
"channels" : [
{
"id" : "10000-1",
"name" : "cust1chan1",
"enabled" : true
}
] …Run Code Online (Sandbox Code Playgroud) 我已经将spring jsp security taglib添加到freemarker模板,因为我使用freemarker来查看我的web应用程序而不是jsps.对于任何搜索如何进行设置的人,我发现添加弹簧库以便在Freemarker中使用JSP Taglibs以获得安全性是一个非常有用的问题.总之,将以下内容添加到您希望使用标记的*.ftl文件中:
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
Run Code Online (Sandbox Code Playgroud)
然后假设您正在使用maven将以下内容添加到您的pom.xml:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
一旦我设置了它,我运行了我的弹簧控制器单元测试,他们都失败了.问题是他们需要el-api.jar和jsp-api.jar来解决如何呈现Jsp标签.它们作为Web应用程序运行的容器(tomcat)的一部分包含在内,因此应用程序的正常运行不需要它们.所以我在测试范围内添加了这些作为maven依赖项.
<!-- Required for spring controller junit tests, due to use of jspTagLib for security -->
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<!-- Required for spring controller junit tests, due to use of jspTagLib for security -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
通过这个修复,我的测试也抛出了一个错误,即他们无法找到.tld文件的映射,即使在添加spring-security-taglibs maven依赖项时它也包含在内.
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is freemarker.template.TemplateModelException: No mapping defined for http://www.springframework.org/security/tags
The failing instruction (print stack trace …Run Code Online (Sandbox Code Playgroud) 我想运行ec2 describe-instances命令并以表格格式获取输出,如下所示(其中name是带有Key'Name'的Tag的值):
----------------------------------------------------------
| DescribeInstances |
+-------------+----------------+--------------+----------+
| instance_id | ip_address | name | state |
+-------------+----------------+--------------+----------+
| i-g93g494d | 99.99.99.01 | name1 | running |
| i-a93f754c | 99.99.99.02 | name2 | running |
+-------------+----------------+--------------+----------+
Run Code Online (Sandbox Code Playgroud)
我可以运行以下命令:
aws ec2 describe-instances --instance-ids i-g93g494d i-a93f754c --query "Reservations[*].Instances[*].{name: Tags[?Key=='Name'].Value, instance_id: InstanceId, ip_address: PrivateIpAddress, state: State.Name}" --output json
Run Code Online (Sandbox Code Playgroud)
并获得输出:
[
[
{
"instance_id": "i-g93g494d",
"state": "running",
"ip_address": "99.99.99.01",
"name": [
"name1"
]
}
],
[
{
"instance_id": "i-a93f754c",
"state": "running",
"ip_address": "99.99.99.02",
"name": [ …Run Code Online (Sandbox Code Playgroud) 我有一个 Jenkins 工作,在 99% 的时间里都没有问题,但偶尔我会在尝试获取时收到 Git 插件生成的错误。有问题的 Git 存储库托管在 GitLab 中。
此错误的来源可能是 Jenkins、网络连接或 GitLab。
我的问题是有没有人在 GitLab 或其他地方使用 Jenkins 和托管的 Git 看到过类似的问题?
堆栈跟踪(出于安全原因进行了编辑):
Building remotely on [MACHINE_NAME] (build) in workspace c:\workspace\location
> C:\location\of\git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> C:\location\of\git\bin\git.exe config remote.origin.url git@git.<gitlab-server>:My/project.git # timeout=10
Fetching upstream changes from git@git.<gitlab-server>:My/project.git
> C:\location\of\git\bin\git.exe --version # timeout=10
using GIT_SSH to set credentials
> C:\location\of\git\bin\git.exe fetch --tags --progress git@git.<gitlab-server>:My/project.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed …Run Code Online (Sandbox Code Playgroud) 我使用 Groovy DSL 定义了一个简单的 Jenkins 管道。我的目的是它只会检查我的 git 存储库。但是我收到错误。
鉴于我的 DSL 常规定义:
stage 'build'
node
{
git branch: '*/mybranch', credentialsId: 'my credentials', url: 'git@git.servername:pathto/myrepo.git'
}
Run Code Online (Sandbox Code Playgroud)
我希望 Jenkins 管道能够简单地检查我的 git 存储库。
但是我收到以下错误:
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?
我努力为这个问题命名.我试图解决的问题与此处描述的问题非常相似,但我没有提交bean的列表,而是提交表示模型对象中的地图的http请求参数,让框架(Spring)负责构建地图来自http请求参数.有人可以建议最好的做法/最干净的方法吗?任何帮助将非常感激.
目前我传递两个String数组,然后在保存到模型对象之前将它们转换为映射.我认为必须有一个更好的方法来做到这一点.
我使用Spring MVC和Freemarker进行视图渲染.
说明代码:
模型对象:
public class Foo {
private Map<String, String> barMap;
// other member variables...
}
Run Code Online (Sandbox Code Playgroud)
查看fremarker模板:
<#list foo.barMap?keys as currKey>
<tr id="barList_${currKey_index}">
<td><input name="key" type="text" value="${currKey}"/></td>
<td><input name="value" type="text" value="${foo.barMap[currKey]}"/></td>
</tr>
</#list>
Run Code Online (Sandbox Code Playgroud)
控制器:
@RequestMapping(value = "/foo", method = RequestMethod.POST)
public String foo (Model model,
@RequestParam(value="key", required=false) String[] keys,
@RequestParam(value="value", required=false) String[] values) {
Foo foo = new Foo();
Map<String, String> barMap = new HashMap<String, String>();
if (keys != null && values != null && …Run Code Online (Sandbox Code Playgroud) freemarker ×2
java ×2
jenkins ×2
spring ×2
amazon-ec2 ×1
git ×1
gitlab ×1
groovy ×1
jsp-tags ×1
mongodb ×1
spring-mvc ×1