是否可以OR
在Doctrine findBy()
方法中使用语句?我知道给定的数组被解释为case1 AND case2...
像这样
$this->repos['notif']->findBy(array('status' => 1, 'status' => 2, 'status' => 3);
Run Code Online (Sandbox Code Playgroud)
代表
SELECT * FROM `notif` WHERE status=1 AND status=2 AND status=3;
Run Code Online (Sandbox Code Playgroud)
现在我需要一些东西代表:
SELECT * FROM `notif` WHERE status=1 OR status=2 OR status=3;
Run Code Online (Sandbox Code Playgroud)
有办法获得所有案件吗?
我为什么要用@FindBy
vs driver.findElement()
?
@FindBy
强迫我将所有变量移动到类级别(当大多数变量只需要在方法级别时).它似乎唯一能给我买的是我可以调用PageFactory.initElements()
,它为我处理延迟初始化.
我错过了什么?
我有两个域对象,
@Document
public class PracticeQuestion {
private int userId;
private List<Question> questions;
// Getters and setters
}
@Document
public class Question {
private int questionID;
private String type;
// Getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我的JSON文档是这样的,
{
"_id" : ObjectId("506d9c0ce4b005cb478c2e97"),
"userId" : 1,
"questions" : [
{
"questionID" : 1,
"type" : "optional"
},
{
"questionID" : 3,
"type" : "mandatory"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我必须更新基于userId和questionId的"类型",所以我在自定义Repository接口中编写了一个findBy查询方法,
public interface CustomRepository extends MongoRepository<PracticeQuestion, String> {
List<PracticeQuestion> findByUserIdAndQuestionsQuestionID(int userId,int questionID);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是当我执行此方法时userId为1而questionID为3,它返回整个问题列表而不管questionID.查询方法名称是有效的,还是应该如何为嵌套对象编写查询.
谢谢你的任何建议.
谁能给我解释一下关于注释@FindBy
中WebDriver
?
使用的地点和原因?
我想问一下如何使用带有List属性的class的exampleMatcher.让我们假设,我们有一个可以同时拥有多个角色的用户.我希望从DB获得具有用户角色的所有用户
实体
@Entity(name = "UserEntity")
public class User {
Private Long id;
private String name;
private String surname;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn
private Address address;
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
@JoinColumn
private List<UserRole> roles;
}
@Entity
public class UserRole {
private Long id;
private String name;
}
Run Code Online (Sandbox Code Playgroud)
我发送一个带有一些属性的User类到getExampleEntity.我正在尝试从UI发送所选角色的列表.
控制器中的功能
@Override
protected User getExampleEntity() {
User clonedUser = new User();
List<UserRole> selectedRole = new ArrayList<>();
// this cycle just find and add all roles in db based on selection from …
Run Code Online (Sandbox Code Playgroud) 我有3个实体:
样式
颜色
文章
一篇文章与两个实体都有一个ManyToOne关系(一篇文章是风格和颜色的独特组合).所有实体都具有自动递增的代理整数索引.
我有一个样式实体和一个颜色实体,我想创建一个链接这两个实体的新文章(如果还没有).鉴于没有办法使用doctrine进行等效的('INSERT on DUPLICATE KEY UPDATE'),我需要找到任何与我的Style和Color实体有关系的文章.如果没有匹配,则创建一个新实体.
如何在我的系统中找到与样式和颜色实体相关的任何文章实体?
/**
* @Entity
*/
class Style{
/** @Id @GeneratedValue @Column (type="integer") */
private $id;
/** @Column (name="name", type="string") */
private $name;
/**
* @OneToMany(targetEntity="Article", mappedBy="style", cascade={"persist"})
*/
private $articles;
}
class Colour{
/** @Id @GeneratedValue @Column (type="integer") */
private $id;
/** @Column (name="name", type="string") */
private $name;
}
class Article{
/** @Id @GeneratedValue @Column (type="integer") */
private $id;
/**
* @ManyToOne(targetEntity="Style", inversedBy="articles", cascade={"persist"})
*/
private $style;
/**
* @ManyToOne(targetEntity="Colour", …
Run Code Online (Sandbox Code Playgroud) 我想findBy
用IN
-Operator来创建一个in science,就像在 SQL 中一样:
...WHERE column_name IN (value1,value2,...);
Run Code Online (Sandbox Code Playgroud)
是否可以在实体存储库的标准数组中执行此操作findBy
?
this->entityRepository->findBy($criteria, $orderBy, $limit, $offset);
Run Code Online (Sandbox Code Playgroud)
还是我必须用 DQL 来做这件事?
我在Mongo的文档结构是这样的:
db.user.find()
{
"_id" : ObjectId("560fa46930a8e74be720009a"),
"createdAt" : ISODate("2015-10-03T09:47:56.333Z"),
"message" : "welcome",
}
{
"_id" : ObjectId("560fa46930a8e723e720009a"),
"createdAt" : ISODate("2015-10-03T09:48:25.048Z"),
"message" : "thank you"
}
Run Code Online (Sandbox Code Playgroud)
当我在Mongo Shell中使用以下查询来查找两个给定时间戳之间的文档时,我得到了正确的结果:
db.user.find({createdAt:{$gte:ISODate("2015-10-03T09:40:25.048Z"),$lte:ISODate("2015-10-03T09:50:56.333Z")}})
Run Code Online (Sandbox Code Playgroud)
我在我的REST服务中使用带有Spring的MongoRepository来使用Java驱动程序.以下是用户存储库:
public interface UserRepository extends MongoRepository<User, String>
{
ArrayList<User> findbyCreatedAtBetween(Date d1, Date d2);
}
Run Code Online (Sandbox Code Playgroud)
当我打电话在我的服务中进行以下呼叫时,它不会返回任何结果
userRepository.findbyCreatedAtBetween(2015-10-03T09:40:25.048Z, 2015-10-03T09:50:29.006Z)
但是当我在前一天给出d1时它会返回结果:userRepository.findbyCreatedAtBetween(2015-10-02T09:40:25.048Z,2015-10-03T09:50:29.006Z)
关于如何解决这个问题的任何想法?请帮忙!
这是我们的代码
private IdentificationMaster validateIdentificationType(String idType) {
if(!StringUtils.isNotBlank(idType))
throw new IllegalArgumentException("Invalid idType");
Optional<IdentificationMaster> op1 = specRepo.findById(idType); //testing purpose
Optional<IdentificationMaster> op2 = specRepo.findByIdentificationType(idType); //testing purpose
return specRepo.findById(idType)
.orElse(specRepo.findByIdentificationType(idType)
.orElseThrow(() -> new ResourceNotFoundException("Id Type Not Found " + idType)));
}
Run Code Online (Sandbox Code Playgroud)
因为idType
我们期待两个值,它可以是主键 id或其对应的identificationType
. 表只有两列id
和identificationType
。问题是ResourceNotFoundException
即使op1
或op2
不为空它也会抛出。现在如果我像这样改变我的回报
return specRepo.findByIdentificationType(idType)
.orElse(specRepo.findById(idType)
.orElseThrow(() -> new ResourceNotFoundException("Id Type Not Found " + idType)));
Run Code Online (Sandbox Code Playgroud)
它再次抛出相同的异常!
存储库
@Repository
public interface IdentificationSpecRepository extends CrudRepository<IdentificationMaster, String>{
Optional<IdentificationMaster> findByIdentificationType(String …
Run Code Online (Sandbox Code Playgroud) 我在 SO 和其他地方查看了这个问题的一堆答案,但我能找到的只是人们只想找到最高 id、最大 dateCreated 或最新数据库条目的情况,但我想做的是检索创建的最新对象也符合另一个条件。我的域类具有以下属性:id
、number
、company
、type
和dateCreated
。content
该company
属性只能设置为“OYG”或“BAW”,并且该number
属性是一个自动递增的 int。number
我想要做的是检索属性设置为“OYG”或“BAW”的最高记录company
。
这是一个例子:
+----------------------------------------------------------+
| id | number | company | type | dateCreated | content |
+----------------------------------------------------------+
| 1 | 0 | OYG | TsAndCs | 15/09/2016 | stuff |
| 2 | 0 | BAW | TsAndCs | 15/09/2016 | stuff |
| 3 | 1 | OYG | TsAndCs | 16/09/2016 | …
Run Code Online (Sandbox Code Playgroud) findby ×10
doctrine-orm ×3
java ×3
annotations ×2
mongodb ×2
mysql ×2
spring-data ×2
arraylist ×1
grails ×1
grails-orm ×1
optional ×1
orm ×1
page-factory ×1
php ×1
selenium ×1
spring-boot ×1
webdriver ×1