在 Angular4 中,您可以使用loadChildren路由配置中的属性延迟加载模块pathToMyModule#MyModule。我想知道是否可以指定任何属性来始终加载我的模块(因此基本上禁用延迟加载)。
在解析文件并转换为 POJO 时遇到问题。以下异常我得到。
com.fasterxml.jackson.databind.JsonMappingException:无法构造 java.util.LinkedHashMap 的实例:没有从字符串值反序列化的字符串参数构造函数/工厂方法 ('{\"hosturl_path\":\"/images\"} ')
示例 json 文件:
{"test": [{
"a112a": "testhost",
"a112b": "{\"hosturl_path\":\"/images\"}"
}]}
Run Code Online (Sandbox Code Playgroud)
POJO -
import java.io.Serializable;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.ANY,
setterVisibility = JsonAutoDetect.Visibility.ANY)
public class TestPojo implements Serializable
{
private static final long serialVersionUID = 638312139361412L;
@JsonProperty("a112a")
private String host;
@JsonProperty("a112b")
private Map<String,String> parameterMap;
public TestPojo()
{
}
public TestPojo(String host, Map<String, String> parameterMap)
{
this.host = host; …Run Code Online (Sandbox Code Playgroud) 我有一个基本的 SpringBoot 2.0.3.RELEASE 应用程序,它使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎和包作为可执行 JAR 文件,在 pom.xml 中有这些依赖项。
我有一个名为 Company 的域对象:
@Entity
@Table(name="t_company")
public class Company implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Company() {
}
/**
* @param companyName
*/
public Company(String companyName) {
super();
this.name = companyName;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotEmpty
@Length(max = 100)
private String name;
@OneToMany(mappedBy = "company", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<User> users = new HashSet<>(); …Run Code Online (Sandbox Code Playgroud) 我有一个数组列表,其中包含构造函数所需的所有参数.引用数组中的每个项目然后分别提供参数似乎很多工作.我想知道我是否可以通过在构造函数的括号内迭代它来传递数组列表中的每个项目.
我问我是否可以这样做,或类似的东西传递参数.
constructor object =new constructor(for(String item: parts));
Run Code Online (Sandbox Code Playgroud)
parts是这里的数组列表.列表中的所有项目都是字符串.
我正在做一项作业,并使用 thymeleaf 和 spring 创建网页。我已经完成了大部分工作,但我似乎无法加载图像。
我的HTML:
<!DOCTYPE html>
<html xmlns:th="https//www.thymeleaf.org">
<head>
<title>A Course</title>
<link rel="stylesheet" type="text/css"
href="/css/ReviewPageStyleSheet.css" />
</head>
<body>
<h1 id="heading">A Single Course</h1>
<img th:src="@{${'/images/' + review.image}}">
<div id="list" th:each="review: ${reviews}">
<p th:text="${review.title}"></p>
<p th:text="${review.category}"></p>
<a href="http://localhost:8080/show-all-reviews">Back to home</a>
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我的控制器:
package org.wecancodeit.reviewsite;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class ReviewSiteController {
@Resource
ReviewSiteRepository reviewsRepo;
@RequestMapping("/show-all-reviews")
public String findAllReviews(Model model) {
model.addAttribute("reviews", reviewsRepo.findAll());
return "reviews";
}
@RequestMapping("review")
public String findOneReview(@RequestParam(value = …Run Code Online (Sandbox Code Playgroud) 我试图从二维数组下面找到最佳平均分数:
String[][] scores = { { "Amit", "70" }, { "Arthit", "60" }, { "Peter", "60" }, { "Arthit", "100" } };
Run Code Online (Sandbox Code Playgroud)
输出为: 80(Arthit得分(60 + 100)/ 2)
直到现在我用下面的方法解决了这个问题,但是我正在寻找带流的优雅解决方案:
public static void main(String[] args) {
String[][] scores = { { "Amit", "70" }, { "Arthit", "60" }, { "Peter", "60" }, { "Arthit", "100" } };
int highestAvg = Integer.MIN_VALUE;
Function<String[], Integer> function = new Function<String[], Integer>() {
@Override
public Integer apply(String[] t) {
int sum = 0, count = 0; …Run Code Online (Sandbox Code Playgroud) import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Delete
{
public static void main(String[] args)
{
List<List<String>> list = new ArrayList<>();
list.add(List.of("A","B","C","R"));
list.add(List.of("E","F","G","F"));
list.add(List.of("A","B","C","D"));
System.out.println(list.stream().distinct().count());
Map<String, Long> countMapOfColumn = list.stream()
.filter(innerList -> innerList.size() >= 3)
.map(innerList -> innerList.get(3 - 1))
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
System.out.println(countMapOfColumn.keySet());
}
}
Run Code Online (Sandbox Code Playgroud)
我想找出第3列中的唯一元素,第3列中"C","G"有2唯一元素.
这可以使用loop但我不能使用循环.使用java stream可能有一个解决方案.
另外,我如何获得一次"A","B"列中列的行数以及列中的行数?1,2N
我试图在更改时将每个字符串输入转换为 null。因此,我创建一个指令来监听每个更改并将 null 分配给空字符串。
这是 HTML
<form [formGroup]="form" class="mt-4 p-2" (ngSubmit)="onSubmit()">
<input nbInput fullWidth fieldSize="small" shape="semi-round" formControlName="AuthorityNum" EmptyToNull>
</form>
Run Code Online (Sandbox Code Playgroud)
这是指令代码:
import { Directive, Input, HostListener, ElementRef } from
'@angular/core';
@Directive({
selector: '[EmptyToNull]'
})
export class NullValueDirective {
constructor() {
}
@HostListener('change', ['$event.target.value']) onKeyDowns(value) {
if (value === '') {
value = null;
console.log(value) // print: null
}
}
}
Run Code Online (Sandbox Code Playgroud)
看起来它会将值更改为 null
但是当我提交表单并检查 form.value 时,它再次显示为空字符串。
为什么?
更新:
这是我的提交功能:
onSubmit() {
// TODO: Send to server
this.form.value.AuthorityNum === '' // true …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 stable/fluent-bit 作为图表中的子图表。该图表在 values.yaml 中有一个值:
backend:
es:
host: elasticsearch
Run Code Online (Sandbox Code Playgroud)
如何在不更改流畅位图的情况下将 backend.es.host 的值设置为 {Release.Name}-elasticsearch 之类的值?
我正在构建一个 Spring 系统,其中涉及用户和他们正在服用的药物。我有一个包含表的数据库:用户,药物
我正在创建一个新的数据类型名称 UserMed,它由复合主键组成 - 药物的 ID 和用户的用户名(上表的主键)
以下是 UserMed 实体代码:
@Entity
@Table(name = "userMeds")
public class UserMed implements Serializable {
@Id
@EmbeddedId
private UserMedId userMedId;
public UserMed(int drugID, String username) {
this.userMedId.drug_id = drugID;
this.userMedId.username = username;
}
public UserMed() {
}
public String getUsername() {
return this.userMedId.username;
}
public void setUsername(String username) {
this.userMedId.username = username;
}
}
Run Code Online (Sandbox Code Playgroud)
这是 EmbeddedID UserMedId 数据类型:
@RequiredArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@EqualsAndHashCode
@Embeddable
public class UserMedId implements Serializable {
@NonNull
public …Run Code Online (Sandbox Code Playgroud) java ×6
spring-boot ×3
angular ×2
java-8 ×2
java-stream ×2
lambda ×2
arraylist ×1
constructor ×1
directive ×1
events ×1
fluent-bit ×1
fluentd ×1
hibernate ×1
image ×1
jackson ×1
junit ×1
objectmapper ×1
spring ×1
spring-mvc ×1
thymeleaf ×1
typescript ×1