我有使用Spring Boot和thymeleaf的以下问题,我无法解决它.在错误发生后立即运行Application类时发生错误.
我与百里香的布局在于
主\资源\模板
HomeController的
@Controller
public class HomeController {
@GetMapping("/")
public String root() {
return "page/home";
}
}
Run Code Online (Sandbox Code Playgroud)
应用
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
LOG ERROR
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewResolver' defined in class path resource …Run Code Online (Sandbox Code Playgroud) SELECT Count(1) AS total,
'hello' AS filter,
field1 AS field1,
Count(DISTINCT field2) AS total_field2
FROM table
WHERE field = true
AND status = 'ok'
GROUP BY field1
Run Code Online (Sandbox Code Playgroud)
怀疑如何使用java8制作地图来存储以下结果。映射键必须是字段field1,映射值必须是total_field2字段。
也就是说,我需要使用字段 field1 和计数字段 field2 对列表进行分组
对于我的总字段
myList.stream().collect(Collectors.groupingBy(MyObject::getField1, Collectors.counting()))
// this is just counting the records grouped by field1
Run Code Online (Sandbox Code Playgroud)
我的结果是正确的total_field1:{4=55, 6=31}
对于 field2,我需要这样的东西,但它只是给我一个记录
myList.stream().filter(distinctByKey(MyObject::getField2))
.collect(Collectors.groupingBy(MyObject::getField1, Collectors.counting()));
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
Run Code Online (Sandbox Code Playgroud)
结果total_Field2:{4=31}
应该返回 …