我的Mongo数据库中有两个集合,Foos包含对一个或多个Bars的引用:
Foo: {
prop1: true,
prop2: true,
bars: [
{
"$ref": "Bar",
"$id": ObjectId("blahblahblah")
}
]
}
Bar: {
testprop: true
}
Run Code Online (Sandbox Code Playgroud)
我想要的是找到所有Foo至少有一个Bar将testprop设置为true 的s .我已经尝试过这个命令,但它没有返回任何结果:
db.Foo.find({ "bars.testprop" : { "$in": [ true ] } })
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我有一个String,我将自动装配为bean.该值的值String通过属性文件设置,并在运行时加载.我可以验证这一点.这是我的XML:
<context:property-placeholder location="classpath:my-app.properties" />
<bean id="loadedProp" class="java.lang.String">
<constructor-arg>
<value>${loaded-prop}</value>
</constructor-arg>
</bean>
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我在bean中自动装配:
@Component
public class Foo {
@Autowired
private String loadedProp;
}
Run Code Online (Sandbox Code Playgroud)
一切都很好看.我有多个组件在这个bean中自动装配.我正在尝试做的是,在应用程序运行时,将bean的值更新为其他内容,以便在bean自动装配的任何地方,它使用最新的值.是否可以这样做,或者我只是需要在每次想要更改值时重新启动?
我正在使用Grails Webflow插件.以下是我正在使用的域对象:
class Foo implements Serializable {
String fooProp1,
fooProp2
static constraints = {
fooProp2 nullable: false
}
}
class Bar implements Serializable {
Foo fooObject
static constraints = {
fooObject nullable: false
}
}
Run Code Online (Sandbox Code Playgroud)
在webflow中的某个点上,我需要确保fooObject.fooProp1不为null.如果是,我想抛出一个错误并强制用户为它提供一个值.我尝试使用validate()来执行此操作(在Bar和Foo对象上),但由于fooProp1具有nullable:true属性,因此它会通过验证.有任何想法吗?
我正在尝试将Criteria查询导出为CSV,Excel,你有什么.我遇到的问题是类别代码运行干净(如,不会抛出任何错误),但它不会生成任何数据.我知道这data是一个列表的ArrayList.任何人都有解决方法,或告诉我,如果我做错了什么?
这是我的域对象:
class Machine {
String name,
category
// constraints, etc
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器动作(主要来自插件页面):
def categories = {
if(params?.format && params.format != "html"){
response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
response.setHeader("Content-disposition", "attachment; filename=categories.${params.extension}")
def data = Machine.createCriteria().list {
projections {
groupProperty("category")
countDistinct("id")
}
}
exportService.export(params.format, response.outputStream, data, [:], [:])
}
Run Code Online (Sandbox Code Playgroud) 这是我的示例类,它使用Java 1.6.0_14版编译(并运行):
import java.util.List;
import java.util.ArrayList;
public class Sample {
List<InnerSample> iSamples;
public Sample() {
iSamples = new ArrayList<InnerSample>();
iSamples.add(new InnerSample("foo"));
iSamples.add(new InnerSample("bar"));
}
public static void main(String[] args) {
System.out.println("Testing...");
Sample s = new Sample();
for (InnerSample i : s.iSamples) {
System.out.println(i.str);
}
}
public class InnerSample {
String str;
public InnerSample(String str) {
this.str = str;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道你应该在Java中每个文件只有一个公共类,但这更像是一个约定而不是一个规则?
我真正想要做的是创建一个不同时运行的Quartz作业,但也可以访问它JobExecutionContext以获得previousFireTime.这是我的目标:
// imports...
public class UtilityObject {
private SomeService someService;
@Autowired
public UtilityObject(SomeService someService) {
this.someService = someService;
}
public void execute(JobExecutionContext ctx) throws JobExecutionException {
Date prevDate = ctx.getPreviousFireTime();
// rest of the code...
}
}
Run Code Online (Sandbox Code Playgroud)
这是我如何配置我的bean:
<bean name="utilityBean" class="UtilityObject" />
<bean id="utilityJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetOjbect" ref="utilityBean" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean name="utilityTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="utilityJob" />
<property name="startDelay" value="5000" />
<property name="repeatInterval" value="20000" />
</bean>
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,它在创建bean时失败了
NoSuchMethodException:UtilityJob.execute() …
真是愚蠢的问题.这是我的示例代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct sample {
int a;
int b;
} SAMPLE_T;
int main() {
int i, max = 4;
for (i = 0; i < max; i++)
{
SAMPLE_T * newsamp = (SAMPLE_T *)malloc(sizeof(SAMPLE_T));
printf("addr: %x\n", &newsamp);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试每次循环时"创建"一个新变量,我认为这样做会有效,因为malloc会在堆上创建一个新变量.但是,似乎我搞砸了一些东西.这是输出:
addr: bfc29c4
addr: bfc29c4
addr: bfc29c4
addr: bfc29c4
Run Code Online (Sandbox Code Playgroud)
我不明白怎么malloc工作?