我的域名对象 -
Person{
String name;
Date born;
}
Run Code Online (Sandbox Code Playgroud)
我有一个PersonRepository
PersonRepository{
@Query(value="{'born': {$gt: new Date(?0)} }")
findPerson(Date bornAfter);
}
Run Code Online (Sandbox Code Playgroud)
我想抓住在某个约会后出生的所有人.但这不起作用.我错过了什么?mongodb控制台中"born"的日期格式如下
ISODate("2011-11-16T09:46:33.750Z")
Run Code Online (Sandbox Code Playgroud)
我试图在data-jpa源代码中寻找一个单元/集成测试.找不到任何东西.有人能指点我吗?
我正在使用spring-data-elasticsearch和elasticsearch来查询文档.我想对嵌套文档进行嵌套查询.
我在java中有这个:
@Document(indexName = "as", type = "a", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
class A {
@Id
private String Id;
@Field(type = String, index = analyzed, store = true)
private String field1;
// ... Many more Fields.
@NestedField(type = FieldType.Object, index = analyzed, store = true, dotSuffix = "accounts")
private List<B> bs;
// ... getters and setters
}
Run Code Online (Sandbox Code Playgroud)
和
class B { // some normal pojo }
Run Code Online (Sandbox Code Playgroud)
当我让spring-data进行映射时,我得到:
"a": {
"properties": {
"bs": …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Data JPA和Spring Data REST开发基于组件的CRUD应用程序.我有几个组件.例如,系统组件具有User模型和UserRepository.组件由包名称区分.喜欢com.example.app.<component_name>
因此,为了使我的REST API看起来更干净,我需要实现API URL,如下所示.
host:8080/<component_name>/<model_collection_name>
例如
host:8080/system/users
我在我的存储库中执行了以下操作
@RepositoryRestResource(collectionResourceRel = "users", path = "system/users")
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
...
}
Run Code Online (Sandbox Code Playgroud)
当我转到时,这会生成以下内容 http://localhost:8080
{
"_links": {
"users": {
"href": "http://localhost:8080/system/users{?page,size,sort}",
"templated": true
},
...
Run Code Online (Sandbox Code Playgroud)
但是当我转到 http://localhost:8080/system/users
它给出了一个错误
5月22日星期五17:56:37 IST 2015出现意外错误(type = Not Found,status = 404).没有可用的消息
注意:如果我将路径映射到system-users那么它工作正常,但是当我/在路径中使用a 时system/users,它会中断并给出错误.
我正在尝试使用spring-boot-starter-data-rest使用Spring Boot构建RESTful API.有一些实体:帐户,交易,类别和用户 - 只是通常的东西.
当我通过默认生成的API 检索http:// localhost:8080/transactions中的对象时,一切顺利,我得到一个包含所有事务的列表作为JSON对象,如下所示:
{
"amount": -4.81,
"date": "2014-06-17T21:18:00.000+0000",
"description": "Pizza",
"_links": {
"self": {
"href": "http://localhost:8080/transactions/5"
},
"category": {
"href": "http://localhost:8080/transactions/5/category"
},
"account": {
"href": "http://localhost:8080/transactions/5/account"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但现在的目标是仅检索该URL下的最新事务,因为我不想序列化整个数据库表.所以我写了一个控制器:
@Controller
public class TransactionController {
private final TransactionRepository transactionRepository;
@Autowired
public TransactionController(TransactionRepository transactionRepository) {
this.transactionRepository = transactionRepository;
}
// return the 5 latest transactions
@RequestMapping(value = "/transactions", method = RequestMethod.GET)
public @ResponseBody List<Transaction> getLastTransactions() {
return transactionRepository.findAll(new PageRequest(0, 5, new Sort(new Sort.Order(Sort.Direction.DESC, "date")))).getContent(); …Run Code Online (Sandbox Code Playgroud) spring spring-mvc spring-data-rest spring-hateoas spring-boot
我@CreatedDate在实体属性上使用,我看到它在db中插入日期.我不明白@CreatedBySpring Data JPA 中注释的目的是什么.
在参考文档中,我读到:
我们提供
@CreatedBy,@LastModifiedBy捕捉谁创建或修改该实体的用户
但是如何创建和使用这样的用户呢?
我正在使用带有mongo的spring数据和一个存储库.例如:
@Query("{ 'userName' : ?0 }")
public User findByUsername(String username);
Run Code Online (Sandbox Code Playgroud)
我想让这个案例不敏感.我使用了以下查询:
"{'userName' : { $regex : ?0, $options: 'i' } }"
Run Code Online (Sandbox Code Playgroud)
这有效,但它不仅匹配testUser,还匹配estUser.
我也试过了
"{'userName' : { $regex : ^?0$, $options: 'i' } }"
Run Code Online (Sandbox Code Playgroud)
但是这不能解析查询,因为它试图在正则表达式中插入引号.
com.mongodb.util.JSONParseException:
({ $regex : ^"testUser"$, $options: 'i' }
^
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用/.../i正则表达式,我会遇到同样的问题.
有没有解决方案,不必使用mongoTemplate,或自己构建正则表达式?
我创建了一个Spring Data Rest投影(不是摘录投影),只需要添加一些链接,因为这些链接与同一实体的其他投影和实体本身不具有重要意义.
据我所知,我们怎么能这样做ResourceProcessor呢?我只能添加链接到实体,是否可以只为该投影添加链接?
我有一个spring项目,我非常想使用Spring Data OrientDB,它是否已准备就绪?或者我应该只使用Graph API或蓝图?
有没有办法在spring data mongodb中找到针对数据库运行的查询?
我知道在 JPA 的情况下这是可能的。所以只是想知道 Spring data MongoDB 中是否有类似的东西?
我试图把我的头围绕着JPA,并且学到了很多东西.JPA是一个Java规范,提供程序实现此规范.我明白那一部分.
我不明白的是Spring Data如何进入图片.Spring Data也是像Hibernate或OpenJPA这样的提供商吗?如果没有,那是什么?Spring Data如何"让事情变得更轻松"?