我在Spring Boot应用程序内部有VueJS单页应用程序,我想让vue-router处理所有请求,而不是这些以url开头的请求/rest/**
。
因此,我编写了正则表达式^(?!/rest/).*
以匹配不以开头的所有内容,/rest/
然后尝试使请求映射如下:
@Controller
public class MainController {
@RequestMapping(value = "/{path:^(?!/rest/).*}")
public String forwardRequests() {
return "forward:/";
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用。我做错了什么?
编辑
我有休息控制器文件:
@RestController
@RequestMapping(path = "/rest/project")
public class ProjectController {
@Autowired
private ProjectService projectService;
@GetMapping(value = "/{id}")
public Project getProjectById(@PathVariable Long id) {
return projectService.getProjectById(id);
}
}
Run Code Online (Sandbox Code Playgroud)
它返回带有项目详细信息的JSON。我有一些类似的页面/login
,/projekty
因此我需要转发它们index.html
以处理vue路由。我知道我可以做这样的事情:
@Controller
public class MainController {
@RequestMapping(value = {"/login", "/projekty"}, method = RequestMethod.GET)
public String forwardRequests() {
return "forward:/";
}
} …
Run Code Online (Sandbox Code Playgroud) 我是 vue.js 的新手,我尝试将值传递给子组件。
HTML
<div id="example">
<my-component v-bind:data="parentData"></my-component>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
Vue.component('my-component', {
props: ['data'],
template: '<div>Parent component with data: {{ data.value }}!<div is="my-component-child" v-bind:data="childData"></div></div>'
});
Vue.component('my-component-child', {
props: ['data'],
template: '<div>Child component with data: {{ data.value }} </div>'
});
new Vue({
el: '#example',
data: {
parentData: {
value: 'hello parent!'
},
childData: {
value: 'hello child!'
}
}
});
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/v9osont9/2/
我有这个错误:
[Vue 警告]:属性或方法“childData”未在实例上定义,但在渲染期间被引用。确保在数据选项中声明反应数据属性。(在发现 )
[Vue 警告]:渲染函数出错:(在 中找到)
类型错误:无法读取未定义的属性“值”
这样做的正确方法是什么?
我有两个vavr列表:
List<Object> list1 = List.of("one", "two", "three", "for");
List<Object> list2 = List.of("one", "two", List.of("three", "for"));
Run Code Online (Sandbox Code Playgroud)
我怎样才能将其变换list2
为等于list1
?
编辑
我试着解释一下我想要达到的目标:
System.out.println("list1: " + list1);
System.out.println("list2: " + list2);
Run Code Online (Sandbox Code Playgroud)
输出:
list1: List(one, two, three, for)
list2: List(one, two, List(three, for))
Run Code Online (Sandbox Code Playgroud)
我想要展平所有内部列表list2
,因此展平列表应该等于list1
:
System.out.println("flattened: " + flattened);
System.out.println(list1.equals(flattened));
Run Code Online (Sandbox Code Playgroud)
应该返回:
flattened: List(one, two, three, for)
true
Run Code Online (Sandbox Code Playgroud)