小编Nic*_*s K的帖子

Angular4 如何以一种急切的方式加载模块

在 Angular4 中,您可以使用loadChildren路由配置中的属性延迟加载模块pathToMyModule#MyModule。我想知道是否可以指定任何属性来始终加载我的模块(因此基本上禁用延迟加载)。

angular

5
推荐指数
1
解决办法
4064
查看次数

无法构造 java.util.LinkedHashMap 的实例:无字符串参数构造函数/工厂

在解析文件并转换为 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)

java jackson objectmapper

5
推荐指数
1
解决办法
2万
查看次数

无法使用 SpringBoot 延迟初始化角色集合

我有一个基本的 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)

junit hibernate spring-mvc spring-data-jpa spring-boot

5
推荐指数
2
解决办法
6947
查看次数

我可以将循环作为参数传递给构造函数

我有一个数组列表,其中包含构造函数所需的所有参数.引用数组中的每个项目然后分别提供参数似乎很多工作.我想知道我是否可以通过在构造函数的括号内迭代它来传递数组列表中的每个项目.

我问我是否可以这样做,或类似的东西传递参数.

constructor object =new constructor(for(String item: parts));
Run Code Online (Sandbox Code Playgroud)

parts是这里的数组列表.列表中的所有项目都是字符串.

java constructor

5
推荐指数
1
解决办法
242
查看次数

使用 Thymeleaf 和 Spring 动态链接到图像

我正在做一项作业,并使用 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)

java image thymeleaf spring-boot

5
推荐指数
1
解决办法
1万
查看次数

二维数组的流操作

我试图从二维数组下面找到最佳平均分数:

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)

java lambda multidimensional-array java-8 java-stream

5
推荐指数
1
解决办法
176
查看次数

如何在java中找到2D ArrayList列的唯一值?

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

java lambda arraylist java-8 java-stream

5
推荐指数
1
解决办法
487
查看次数

为什么将空字符串设置为空反应形式成为空字符串

我试图在更改时将每个字符串输入转换为 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)

events directive typescript angular

5
推荐指数
1
解决办法
2万
查看次数

在 helm 的 values.yaml 中使用 Release.Name

我正在尝试使用 stable/fluent-bit 作为图表中的子图表。该图表在 values.yaml 中有一个值:

backend:
  es:
    host: elasticsearch
Run Code Online (Sandbox Code Playgroud)

如何在不更改流畅位图的情况下将 backend.es.host 的值设置为 {Release.Name}-elasticsearch 之类的值?

fluentd kubernetes-helm fluent-bit

5
推荐指数
1
解决办法
2819
查看次数

Spring JPA - 如何使用复合键(EmbeddedID)保存对象

我正在构建一个 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 spring spring-data-jpa spring-boot

5
推荐指数
1
解决办法
7403
查看次数