我的任务是使用Spring Data REST进行高级搜索.我该如何实现它?
我设法做了一个简单的搜索方法,就像这样:
public interface ExampleRepository extends CrudRepository<Example, UUID>{
@RestResource(path="searchByName", rel="searchByName")
Example findByExampleName(@Param("example") String exampleName);
}
Run Code Online (Sandbox Code Playgroud)
如果我必须简单地去网址,这个例子很有效:
.../api/examples/search/searchByName?example=myExample
Run Code Online (Sandbox Code Playgroud)
但是,如果要搜索多个字段,我该怎么做?
例如,如果我的Example类有5个字段,那么我应该使用所有possibiles文件进行高级搜索?
考虑一下这个:
.../api/examples/search/searchByName?filed1=value1&field2=value2&field4=value4
Run Code Online (Sandbox Code Playgroud)
还有这个:
.../api/examples/search/searchByName?filed1=value1&field3=value3
Run Code Online (Sandbox Code Playgroud)
我需要做些什么才能以适当的方式实现此搜索?
谢谢.
我试图了解Spring Data Rest Controller的确切行为.
我做了一个简单的实现,测试4种注解控制器:@BasePathAwareController
,@RepositoryRestController
,@RestController
,@Controller
控制器具有存储库中实体"作者"的映射.
这是控制器:
@BasePathAwareController
//@RepositoryRestController
//@RestController
//@Controller
public class MyController {
@RequestMapping(value="authors/mycontroller/test")
public void handleRequest(){
System.out.println("handleRequest of class MyController");
}
@RequestMapping(value="/authors/mycontroller/testslash")
public void handleSlashRequest(){
System.out.println("handleSlashRequest of class MyController");
}
@RequestMapping(value="api/authors/mycontroller/test")
public void handleApiRequest(){
System.out.println("handleApiRequest of class MyController");
}
@RequestMapping(value="/api/authors/mycontroller/testslash")
public void handleSlashApiRequest(){
System.out.println("handleSlashApiRequest of class MyController");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在测试4种方法,因为我对要使用的正确映射有一些疑问.
对于每个实验,我使用具有相同映射的不同控制器,只需取消注释该实验所需的注释.
我用HTTP GET调用这两个URL:
http://localhost:8080/myApp/api/mycontroller/test
http://localhost:8080/myApp/api/mycontroller/testslash
Run Code Online (Sandbox Code Playgroud)
这是我获得的结果@BasePathAwareController
:
http://localhost:8080/myApp/api/mycontroller/test
White page, No errors, No print on console
http://localhost:8080/myApp/api/mycontroller/testslash
White page, …
Run Code Online (Sandbox Code Playgroud) 我知道关于这个论点有很多类似的问题,但我真的需要一个可行的解决方案。
我正在尝试配置 Spring Boot 和 Spring Data JPA,以便批量插入。
目标是:在执行操作时提交每条 N 条记录,而不是每条记录repository.save()
。
我从现在开始在以下方面尝试过的application.properties
:
spring.jpa.properties.hibernate.jdbc.batch_size=100
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.generate_statistics=true
Run Code Online (Sandbox Code Playgroud)
但没有成功。我已经监视了数据库,并且记录被一个一个地保存在表中,而不是像我配置的那样 100 x 100。
更新
这是实现:
@Component
public class BulkInsert {
@Autowired
MyRepository repository;
public void process() {
PodamFactory podamFactory = new PodamFactoryImpl();
for(int i=0;i<10000;i++) {
MyEntity myEntity = podamFactory.manufacturePojo(MyEntity.class);
repository.save(myEntity);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是实体:
@Entity
@Table(name="MYTABLE")
@NamedQuery(name="MyEntity.findAll", query="SELECT m FROM MyEntity m")
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="DESCRIPTION")
private …
Run Code Online (Sandbox Code Playgroud) 我正在尝试_source
使用Spring Data Elasticsearch禁用该字段,以便添加此属性:
"_source": {
"enabled": false
}
Run Code Online (Sandbox Code Playgroud)
我在@Configuration
课堂上做以下事情:
@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws IOException {
ElasticsearchTemplate template = new ElasticsearchTemplate(getNodeClient());
Map<Object, Object> mapping = new LinkedHashMap<Object, Object>();
if (template.indexExists(Computer.class)){
mapping = template.getMapping(Computer.class);
} else {
template.createIndex(Computer.class);
}
LinkedHashMap<String, Boolean> hashMap = new LinkedHashMap<String, Boolean>();
hashMap.put("enabled", false);
mapping.put("_source", hashMap);
template.putMapping(Computer.class, mapping);
return template;
}
Run Code Online (Sandbox Code Playgroud)
但我获得以下例外:
java.lang.IllegalArgumentException: Can't merge because of conflicts: [Cannot update enabled setting for [_source]]
at org.elasticsearch.index.mapper.internal.SourceFieldMapper.doMerge(SourceFieldMapper.java:458) ~[elasticsearch-2.2.0.jar:2.2.0]
at org.elasticsearch.index.mapper.FieldMapper.merge(FieldMapper.java:380) ~[elasticsearch-2.2.0.jar:2.2.0]
at …
Run Code Online (Sandbox Code Playgroud) 我有一个由 remote 获得的远程 MediaStream
对象WebRTC Peer Connection
。
我想检查遥控器何时 MediaStream
变为非活动状态(由于原因而独立)。
我已阅读,为了这个目的,我应该使用的事件active
和inactive
的的MediaStream
对象。
但是这两个事件永远不会被触发:即使我为这两个事件设置了特定的处理程序,也永远不会执行这些处理程序。
这是我的实现:
function onRemoteStream(event) {
event.stream.addEventListener("active", function(){
console.log('The video is active');
}, false);
event.stream.addEventListener("inactive", function(){
console.log('The video is not active');
}, false);
remoteVideo.src = window.URL.createObjectURL(event.stream);
}
Run Code Online (Sandbox Code Playgroud)
这两条消息永远不会显示。
我也试过:
function onRemoteStream(event) {
event.stream.onactive = function(){
console.log('The video is active');
};
event.stream.oninactive = function(){
console.log('The video is not active');
}
remoteVideo.src = window.URL.createObjectURL(event.stream);
}
Run Code Online (Sandbox Code Playgroud)
但行为是一样的。
我不明白为什么没有触发这两个事件。
我正在使用谷歌浏览器 52.0.2743.116 m
我有一个使用以下语法的bash脚本:
if [ ! -z ${ARGUMENT+x} ]; then
Run Code Online (Sandbox Code Playgroud)
参数名称后面的"+ x"语法是什么意思?
我有一个带有 Spring Data REST 的应用程序,它返回以下 JSON:
{
"_embedded" : {
"persons" : [ {
"personDetail" : {
"name" : "Alex",
"surname" : "Red",
"id" : {
"group" : "A",
"subclass" : "1"
},
"_links" : {
"self" : {
"href" : "https ://localhost:8080/myApp/api/personDetails/A_1"
}
}
}
}]
}
}
Run Code Online (Sandbox Code Playgroud)
当我访问网址时:
https://localhost:8080/myApp/api/personDetails/A_1
或访问此网址:
https://localhost:8080/myApp/api/persons/04ee99a5-1578-400a-84be-d1ca87cda752/personDetail
该应用程序返回此 JSON:
{
"name" : "Alex",
"surname" : "Red",
"_links" : {
"self" : {
"href" : "https ://localhost:8080/myApp/api/personDetails/A_1"
},
"personDetail" : {
"href" : "https ://localhost:8080/myApp/api/personDetails/A_1" …
Run Code Online (Sandbox Code Playgroud) 在Spring Data Rest 文档的这一部分中有一些不够清楚的地方:
Spring Data REST 导出器在创建输出表示之前执行任何发现的 ResourceProcessor。
对于我所注意到的,这是真的:在 RepositoryEntityController 相应方法完成后,在处理请求期间调用 ResourceProcessor。
它通过
Converter<Entity, Resource>
向内部 ConversionService注册一个实例来实现这一点。
我不明白什么时候使用 this Converter<Entity,Resource>
。
这是负责创建指向引用实体(例如,对象的 JSON 表示中 _links 属性下的那些对象)的链接的组件。它接受一个@Entity 并迭代它的属性,为那些由 Repository 管理的属性创建链接,并在任何嵌入的或简单的属性之间进行复制。
当然?我注意到引用实体的_links是在RepositoryEntityController
. 我没有看到构建这些链接的任何其他组件:不涉及 ConversionService 或 Converter。
但是,如果您的项目需要以不同格式输出,则可以用您自己的格式完全替换默认的传出 JSON 表示。如果您在 ApplicationContext 中注册您自己的 ConversionService 并注册您自己的 Converter,那么您可以返回您选择的 Resource 实现。
我不明白怎么可能做到这一点。
我试图完全按照文档中所写的去做:我已经在 ApplicationContext 和我自己的 Converter 中注册了我自己的 ConversionService。
我已经在扩展 RepositoryRestMvcConfiguration 的自定义类中注册了 ConversionService:
@Configuration
public class RepositoryConfiguration extends RepositoryRestMvcConfiguration {
@Autowired
AuthorConverter authorConverter;
@Bean(name="conversionService")
public ConversionService getConversionService() {
DefaultFormattingConversionService conversionService = …
Run Code Online (Sandbox Code Playgroud) 我对Eclipse和Subversive有问题。
我正在尝试将项目的一个分支重新整合到主干中。
这些是我要执行的操作:
Merge operation failed.
Can't overwrite cause with org.tmatesoft.svn.core.SVNException: svn: E195016:
Cannot merge into a working copy with a switched subtree
Run Code Online (Sandbox Code Playgroud)
我不明白怎么了
我正在使用此Eclipse和SVN配置:
Eclipse Java EE IDE for Web Developers.
Version: Neon.1 Release (4.6.1)
Build id: 20160913-0900
Subversive SVN Team Provider 4.0.3.I20161129-1700
SVNKit 1.8.14 Implementation (Optional) 6.0.3.I20161124-1700
SVN 1.9
Run Code Online (Sandbox Code Playgroud)
提前致谢。
VOLUME
我想在Dockerfile
指定源(主机)和目标(容器)路径中挂载。
docker-compose.yml
该操作可以通过以下方式完成:
volumes:
- /path/source/on/host:/path/destination/on/container
Run Code Online (Sandbox Code Playgroud)
我怎样才能用 Dockerfile 做同样的事情?
spring ×5
spring-mvc ×3
java ×2
spring-boot ×2
bash ×1
bulkinsert ×1
docker ×1
dockerfile ×1
html ×1
html5-video ×1
java-8 ×1
mediastream ×1
merge ×1
subversive ×1
svn ×1
svn-merge ×1
svnkit ×1
webrtc ×1