我想ArrayCollection在Symfony2 Controller中迭代实例,最简单的方法是什么?
编辑:
我认为它会像PHP中的普通数组一样工作,但我在这段代码上有错误:
foreach ($arrayCollectionInc as $Inc) {
}
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我添加了两个不同的JmsListener但是当我在ActiveMQ面板中运行项目时,只有其中一个主题有消费者!
那么我应该为每个JmsListener添加单独的jmsListenerContainerFactory配置吗?
@JmsListener(destination = "foo1")
public void foo1(final Message jsonMessage) throws JMSException {
...
}
@JmsListener(destination = "foo2")
public void foo12(final Message jsonMessage) throws JMSException {
...
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是来自JMS配置文件:
@Configuration
@EnableJms
public class FooJmsConfig {
@Bean
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(BROKER_URL);
connectionFactory.setPassword(BROKER_USERNAME);
connectionFactory.setUserName(BROKER_PASSWORD);
connectionFactory.setUseCompression(true);
connectionFactory.setClientID("FPP_API");
connectionFactory.setConnectionIDPrefix("DRR");
connectionFactory.setUseAsyncSend(true);
return connectionFactory;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setConcurrency("1-1");
factory.setPubSubDomain(true);
factory.setSubscriptionDurable(true);
return factory;
}
}
Run Code Online (Sandbox Code Playgroud) 如何在Laravel 5迁移中向表(ot列)添加注释?
我目前知道如何向列添加注释,如:
$table->tinyInteger('status')->comment('0: requested; -1: rejected; 1:confirmed');
Run Code Online (Sandbox Code Playgroud)
但桌子怎么样?
如何计算MongoDB中许多GeoJSON点之间的路径距离?我可以使用数据库查询按日期字段对项目进行排序,然后计算点之间的距离,最后总计所有时间来计算总距离吗?
以下是我的数据的一些示例:
{
_id: 599cfc236ed0d81c98007f66
tracerId: 59a07ea26ed0d81d78001acd
loc {
type: "2dsphere",
coordinates: [ 159.9, -37.92 ]
},
date: 2017-08-26 00:16:42,
speed: 58,
}
{
_id: 59a074d46ed0d81d78001acc
tracerId: 59a07ea26ed0d81d78001acd
loc {
type: "2dsphere",
coordinates: [ 160, -38.20 ]
},
date: 2017-08-26 00:18:42,
speed: 75,
}
{
_id: 59a074d46ed0d81d78ac11cc
tracerId: 59a07ea26ed0d81d78001acd
loc {
type: "2dsphere",
coordinates: [ 160.222, -38.92 ]
},
date: 2017-08-26 00:20:42,
speed: 60,
}
Run Code Online (Sandbox Code Playgroud) Liquibase 在给定的包中找不到我的实体类(JPA 注释)来生成差异。
当我使用mvn liquibase:diff命令时它说 没有发现任何变化,无事可做,但我的实体有新字段
我使用 spring 框架、JPA(hibernate)、Liquibase、liquibase-hibernate
这是我的代码:
liquibase.properties
referenceUrl=hibernate:spring:model.entity.persistent?dialect=org.hibernate.dialect.OracleDialect
changeLogFile=src/main/resources/liquibase-changeLog.xml
url=jdbc:oracle:thin:@localhost:1521:xe
username=username
password=password
driver=oracle.jdbc.OracleDriver
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog-8.xml
Run Code Online (Sandbox Code Playgroud)
pom.xml liquibase-hibernate 配置
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
<executions>
<execution>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate4</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.19</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud) spring hibernate database-migration liquibase liquibase-hibernate
我在laravel 5中有两个实体Eloquent,Foo和FooType与oneToMany关系.
class Foo {
public function fooTypes(){
return $this->hasMany('App\FooType');
}
}
Run Code Online (Sandbox Code Playgroud)
和FooType
class FooType{
public function foo(){
return $this->belongsTo('App\Foo');
}
}
Run Code Online (Sandbox Code Playgroud)
问题1:
如何使用eloquent查询构建器进行查询并返回具有type_id(此列在FooType表中)为5的Foos ;
我试过的东西:
Foo::fooTypes()->where('type_id', 5);
Run Code Online (Sandbox Code Playgroud)
和任何关于这样的查询的好关键的链接.
问题二: 我发现这很难用Eloquent查询构建器使用正常的laravel查询与DB 是不好的做法,我的意思是使用db我不能使用orm或类似的东西(或者使用eloquent查询构建器的好处是什么):
$foos = DB::table('foos')
->join('fooTypes', 'foo_id', '=', 'foos.id')
->where('fooTypes.type_id', '=', '5')
->select('foos.*')
->get();
Run Code Online (Sandbox Code Playgroud)
这种类型的查询非常简单,并且有更多关于它的教程.
我正在为我的项目使用php laravel 5.2.我想用数据库表设计购物车(表名是购物车).cart表具有列名session_id,用于确定每个用户的购物车.
问题是:
或任何其他购物车设计与数据库的想法?
java枚举是单例吗?
例如 :
public enum State {
ACTIVE(0),
PENDING(1),
DELETED(2),
}
State s = State.ACTIVE;
State s2 = State.PENDING;
State s3 = State.PENDING;
Run Code Online (Sandbox Code Playgroud)
每次我们使用 State.FOO 时,java 都会创建新实例吗??