小编Ale*_*nko的帖子

在 Nest.js 中接受表单数据

我已经在 Nestjs 中编写了身份验证路由,并希望将它与表单数据一起使用。我让它与 URL-encoded-form-data、JSON、文本一起工作,但是当我使用表单数据时没有在正文中收到任何东西,并且真的希望它像在前端一样使用表单数据我正在点击带有表单数据的路由。我已经尝试了所有可以在网络上找到的方法,但在这种情况下,没有一种方法对我有帮助。所以经过数小时的搜索和尝试,当我没有得到任何线索时,我在这里发布了我的问题。任何形式的帮助表示赞赏。

注册端点代码 这是我的注册端点代码

Main.ts 配置 我的 Main.ts 配置

空荡荡的身体,我正在上邮递员 空荡荡的身体,我正在上邮递员

body-parser nestjs req

9
推荐指数
1
解决办法
7993
查看次数

Stream API,有没有办法使用 instream.range 进行降序迭代?

例如, Instream.range(0,10)- 是从 0 索引迭代到 10。

Instream.range(10,0)- 但是从 10 到 0 不起作用,如何使用 Stream API 做到这一点?

java java-stream

6
推荐指数
1
解决办法
456
查看次数

没有可用的“org.springframework.cloud.client.discovery.DiscoveryClient”类型的合格bean

DiscoveryClient 还需要什么?我正在尝试使用 DiscoveryClient 将注册服务获取到尤里卡。独立程序运行良好,但以下代码片段将与在 JBoss 上运行的 Web 应用程序集成。

这是代码

发现客户端控制器.java

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;

@Controller
public class DiscoveryClientController {
    
    @Autowired
    private DiscoveryClient discoveryClient;
        
    public DiscoveryClient getClient() {
        return discoveryClient;
    }
}
Run Code Online (Sandbox Code Playgroud)

发现客户端Bean.java

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
    
@Configuration
public class DiscoveryClientBean {      
        
    @Bean
    public  DiscoveryClientController  discoveryClientController() {
        return  new DiscoveryClientController();
    }
}
Run Code Online (Sandbox Code Playgroud)

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>Discovery</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <build>
        <!-- <sourceDirectory>src</sourceDirectory> -->
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version> …
Run Code Online (Sandbox Code Playgroud)

java spring client discovery netflix-eureka

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

React-Native 底部TabNavigation 中间有大按钮

我想创建一个像这样的bottomTabNavigation: 在此输入图像描述

我设法通过放入图像来创建这样的 tabNavigation,position:'absolute'但图像溢出了选项卡,并且溢出的部分不可单击。

在此输入图像描述

我此时的代码:

    <Tab.Navigator initialRouteName="Activity" tabBarOptions={{
        showIcon: true,
        showLabel: false,
        activeTintColor: 'blue',
      }}>

      <Tab.Screen name="Theme" component={Themes} options={{
        tabBarIcon: () => (<Image source={require('../Images/list_blue.png')} style={styles.icon}/>)
      }}/>

      <Tab.Screen name="Activity" component={Activity} options={{
        tabBarIcon: () => (<Image source={require('../Images/idea_blue.png')} style={styles.main_icon}/>)
      }}/>

      <Tab.Screen name="Add" component={Add} options={{
        tabBarIcon: () => (<Image source={require('../Images/plus_blue.png') style={styles.icon}/>)
      }}/>

  </Tab.Navigator>

    //Styles
    icon: {
      width: 40,
      height: 40,
    },
    main_icon: {
      position: 'absolute',
      bottom: -30,
      width: 115,
      height: 115,
    }
Run Code Online (Sandbox Code Playgroud)

然后我用 prop 创建了一个 cust tabNavigationtabBar={props => <CustomTabBar {...props} />} 但我仍然有同样的问题: …

navigation react-native react-navigation

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

这个While 循环可以简化吗?

考虑以下代码。它用于检查字符串是否具有有效的括号但不使用堆栈。

public boolean isValid(String input) {
       
    while(input.length() != (input = input.replaceAll("\\(\\)|\\[\\]|\\{\\}", "")).length());
    return input.isEmpty();
}
Run Code Online (Sandbox Code Playgroud)

但是有点难以理解。这可以简化吗?不添加更多新行?

java string stack parentheses java-8

4
推荐指数
1
解决办法
160
查看次数

用于匹配有效 Java 标识符的 Java 正则表达式

我需要创建一个能够在 Java 代码中查找和获取有效标识符的正则表达式,如下所示:

int a, b, c;
float d, e;
a = b = 5;
c = 6;
if ( a > b)
{
c = a - b;
e = d - 2.0;
}
else
{
d = e + 6.0;
b = a + c;
}
Run Code Online (Sandbox Code Playgroud)

我试图在一个正则表达式中添加多个正则表达式,但是如何构建一个模式来排除保留字?

我试过这个正则表达式,^(((&&|<=|>=|<|>|!=|==|&|!)|([-+=]{1,2})|([.!?)}{;,(-]))|(else|if|float|int)|(\d[\d.]))但它没有按预期工作。

在线演示

在下图中,我应该如何匹配标识符?

在此处输入图片说明

java regex

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

如何总结对象流的数字属性?

我尝试总结对象流的双重属性:

items.collect(Collectors.summingDouble(double::doubleValue)
Run Code Online (Sandbox Code Playgroud)

但我无法解析方法“doubleValue”

这是项目定义:

流项目= ...;

这是 Item 对象定义:

public class Item {
    private double price;
    private Date date;
    private String name;
}
Run Code Online (Sandbox Code Playgroud)

如何计算对象流的汇总属性?

java java-stream

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

Java 流有条件地添加多个值

我有一个像这样的对象列表,其中数量可以是负数或正数:

class Sale {
   String country;
   BigDecimal amount;
}
Run Code Online (Sandbox Code Playgroud)

我想最终得到一对所有负值和所有正值的总和,按国家/地区分类。

使用这些值:

country | amount
nl      | 9
nl      | -3
be      | 7.9
be      | -7
Run Code Online (Sandbox Code Playgroud)

有没有办法最终Map<String, Pair<BigDecimal, BigDecimal>>使用单个流?

使用两个单独的流很容易做到这一点,但我无法仅用一个流来解决。

java bigdecimal java-stream

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

Java:创建 HashMaps ArrayList 的副本,但仅包含某些键

考虑以下数据结构:

ArrayList<HashMap<String, String>> entries = new ArrayList<>();

ArrayList<String> keyNamesToInclude = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

此代码创建条目的副本但哈希映射仅包含 keyNamesToInclude 中的键:

ArrayList<HashMap<String, String>> copies = new ArrayList<>();

for (HashMap<String, String> entry: entries) {
  HashMap<String, String> copy = new HashMap<>();
  for (String keyName: keyNamesToInclude) {
    copy.put(keyName, entry.get(keyName));
  }
  copies.add(copy);
}
Run Code Online (Sandbox Code Playgroud)

如何以一种功能性的方式使用 Streams 来创建它?

java arraylist java-stream

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

找不到符号符号方法 of() 位置接口 java.util.list、unittests

我目前正在开发一个 Spring Boot 应用程序,我正在其中编写单元测试。但是当我运行命令“mvn test”时,出现以下错误:

在此输入图像描述

这是代码

BoardServiceTest.java

@Test
public void testGetBoards() {
    Set<Lists> list =  new HashSet<Lists>();
    
    List<Board> expectedBoards = List.of(
        new Board(1, "Studie", list),
        new Board(2, "Todo Applicatie", list)
    );
    
    when(this.boardRepo.findAll()).thenReturn(expectedBoards);
    
    var receivedBoards = this.boardService.getBoards();
    assertEquals(expectedBoards, receivedBoards);
    verify(this.boardRepo, times(1)).findAll();
}
Run Code Online (Sandbox Code Playgroud)

列表服务测试.java

@Test
public void testGetLists() throws Exception {   
    int boardId = 1;
    Set<Task> task = new HashSet<>();

    List<Lists> expectedLists = List.of(
        new Lists(1, "registered", new Board(), task),
        new Lists(2, "open", new Board(), task)
    );
    
    when(this.listRepository.findAll()).thenReturn(expectedLists);
    
    var receivedLists = this.listService.getLists(boardId); …
Run Code Online (Sandbox Code Playgroud)

java list spring-boot

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

在java中我想在一行流中返回映射

我正在尝试改进我已经可以运行的代码,所以这就是事情,我有一个返回 a 的方法Map

public Map<String, String> extractPartitionsValues(java.nio.file.Path marketFile) {

    Map<String, String> map = new HashMap<>();
    for (String p : this.partitions) {
        map.put(p, partitionValueFromFilePath(p, marketFile.toString()));
    }
    return map;
}
Run Code Online (Sandbox Code Playgroud)

我想使用stream和collectorsToMap在一行中重新运行它,但我真的很菜,所以我阅读了文档和我发现的所有内容,但它仍然不起作用,有人可以帮我解决这个问题吗?

java inline java-stream

0
推荐指数
1
解决办法
53
查看次数

Java 8按唯一名称过滤对象列表,同时仅保留最高ID?

假设我们有一个包含字段的 person 类:

Class Person {
  private String name;
  private Integer id (this one is unique);
}
Run Code Online (Sandbox Code Playgroud)

然后我们有一个List<Person> people这样的:

['Jerry', 993]
['Tom', 3]
['Neal', 443]
['Jerry', 112]
['Shannon', 259]
['Shannon', 533]
Run Code Online (Sandbox Code Playgroud)

我怎样才能创建一个新List<Person> uniqueNames的,使其仅过滤唯一名称并保留该名称的最高 ID。

所以最终列表将如下所示:

['Jerry', 993]
['Tom', 3]
['Neal', 443]
['Shannon', 533]
Run Code Online (Sandbox Code Playgroud)

java collections java-8 maxby java-stream

0
推荐指数
1
解决办法
2232
查看次数

如果使用java流列表中的一个变量为假,如何删除对象

我正在使用 java 8
我有一个像这样的模型类

class Student{
    String name;
    List<Subject> subjects1;
    List<Subject> subjects2;
    List<Subject> subjects3;
    // getters & setters
}

class Subject{
    String sub;
    Integer marks;
    boolean status;
    // getters & setters
}
Run Code Online (Sandbox Code Playgroud)

status可能是真的,也可能是假的。
现在,如果状态为 false,那么我必须从主题列表中删除这些对象
如何在 Streams 中执行此操作?
提前致谢。

java java-stream

0
推荐指数
1
解决办法
2542
查看次数