我有以下代码片段,我想知道是否以及如何用Streams/Java 8 API替换它
for (State state : states) {
for (City city : cities) {
if (state.containsPoint(city.getLocation())) {
System.out.printf("%30s is part of %-30s\n",
city.getName(), state.getName());
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Boot 1.3.X并具有以下内容:
@RestController
@RequestMapping(path = "/foo")
public class FooController {
@RequestMapping(method = RequestMethod.GET, params = { "fooBar" })
public Collection<Entry> firstFoo() {
//Do something
}
@RequestMapping(method = RequestMethod.GET, params = { "anotherFooBar" })
public Collection<Entry> secondFoo() {
//Do something other
}
}
Run Code Online (Sandbox Code Playgroud)
哪个按预期工作.传递错误的参数时,会引发以下异常:
{
"error": "Bad Request",
"exception": "org.springframework.web.bind.UnsatisfiedServletRequestParameterException",
"message": "Parameter conditions \"fooBar\" OR \"anotherFooBar\" not met for actual request parameters: elementalFormulae={C11}",
"path": "/foo",
"status": 400,
"timestamp": 1455287433961
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了ExceptionHandler如下所示:
@ControllerAdvice
public class ExcptionController {
@ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Invalid …Run Code Online (Sandbox Code Playgroud) 我们的spring-boot项目如下所示
project
|__ build.gradle
|__ settings.gradle
|__ module_a
|__ module_b
|__ ...
|__ module_a
|__ module_b
Run Code Online (Sandbox Code Playgroud)
module_a仅包含SpringApplication类和文件application.properties
运行./gradlew build工作正常,但问题是,对于每个模块(大约10)gradle生成一个包含所有依赖项的胖jar.
我们想要只有一个远罐(在模块a中)
buildscript {
ext {
springBootVersion = '1.2.0.RELEASE'
springLoadedVersion = '1.2.0.RELEASE'
}
repositories {
// NOTE: You should declare only repositories that you need here
mavenCentral()
maven { url "http://repo.spring.io/release" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.springframework:springloaded:${springLoadedVersion}")
}
}
allprojects {
group = "example.group"
version = "0.0.1"
repositories() {
mavenCentral()
}
} …Run Code Online (Sandbox Code Playgroud)