RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-10815

typemoon's questions

Martin Hope
typemoon
Asked: 2024-09-18 21:01:12 +0000 UTC

使用feign客户端,经过jwt授权并为每个请求使用jwt令牌

  • 5

我正在编写微服务。系统中央微服务的 API 通过基于 JWT 令牌(不是 oauth 2)的简单授权进行保护。要访问此微服务的 API,您需要将带有登录名和密码的 POST 请求发送到 /auth/login 地址,接收令牌并在每个资源请求中发送此令牌。该令牌是从服务器在 x-csrf-token 标头中返回的。这是不正确的,但却是事实。从一个新的微服务中,我需要访问该服务的 API,为此我需要登录。对于请求,我将使用 feign 客户端。如何配置 feign 在每个请求上进行身份验证并使用 jwt 令牌?

java
  • 1 个回答
  • 25 Views
Martin Hope
typemoon
Asked: 2024-07-27 19:59:36 +0000 UTC

从 Java 中的资源文件夹获取文件 (JavaFX)

  • 6

我正在泄露的课程中学习 JavaFX 编程。我在 Intellij IDEA 中有这个标准项目结构:

在此输入图像描述

这是主类:

package aoizora.book;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application
{
    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception
    {
        var fxml = getClass().getResource("book.fxml");
        Parent root = FXMLLoader.load(getClass().getResource("../../../resources/book.fxml"));
        stage.setTitle("Address Book");
        stage.setMinHeight(600);
        stage.setMinWidth(400);
        stage.setScene(new Scene(root, 300, 275));
        stage.show();
    }
}

问题是我无法book.fxml从资源文件夹访问该文件。 getResource 方法返回 null。我应该怎么做才能得到这个文件而不出错?

如果它很重要,我的虚拟机选项是:

--module-path C:\JavaFX\lib --add-modules=javafx.controls,javafx.fxml

java
  • 1 个回答
  • 16 Views
Martin Hope
typemoon
Asked: 2024-06-10 18:53:03 +0000 UTC

从一个列表中的不同表列返回值

  • 5

我有一个订单表,其中列出了订单的组成部分:

create table order
(
    goods_id bigint,
    dish_id bigint,
    combo_id bigint
)

我需要以列表的形式从订单中获取所有此类 ID。是否可以在一个请求中完成此操作?如何?

也就是说,如果订单表中有一个条目

goods_id    dish_id    combo_id
123          456        789

那么你需要归还它

result
123
456
789

比如像这样。

mysql
  • 1 个回答
  • 18 Views
Martin Hope
typemoon
Asked: 2024-06-01 02:16:25 +0000 UTC

使用附加标志重构链接表

  • 3

我需要重构与餐厅菜肴修饰符一起使用的代码。例如,调节剂是各种披萨酱,它们可以改变这些相同披萨的成本。

有餐桌修饰(modifiers)和产品(dishes)。他们之间的联系是多对多的。之前的一位同事制作了一个拐杖,以增强连接表的形式将修改器与菜肴连接起来:

create table modification_product
(
    disabled bit,
    modification_id int,
    product_id int
)

该表允许您关闭单个菜肴的修改器,而无需从数据库中删除记录或向修改表全局添加标志。但是相同的标志不允许我应用hibernate的@ManyToMany注释并配置@JoinTable。

如何重构这个地方,使得存在多对多关系,但同时又可以专门针对所选菜肴禁用修改器?

java
  • 1 个回答
  • 63 Views
Martin Hope
typemoon
Asked: 2024-05-31 20:39:31 +0000 UTC

在 Java 中使用 var

  • 6

varJava 中的类型推断有什么问题?一位同事问我经常用什么var,这是否是动态类型 Javascript 的回声。

对我来说,这些都是autoC++ 中类型推断的回声。我应该使用 Java 项目var而不是显式指定类型吗?优缺点都有什么?您正在使用var?

java
  • 2 个回答
  • 78 Views
Martin Hope
typemoon
Asked: 2024-05-25 02:09:50 +0000 UTC

子查询返回错误的行数

  • 5

我的 mysql 查询中发生了一些奇妙的事情。这是我计算成本的查询:

select inv.price_for_one
from invoice inv,
     posinfo pi,
     goods g,
     stock_item si,
     warehouses w
where g.id = :id
  and pi.id = w.pos_info_id
  and si.warehouses_id = w.id
  and g.id = si.goods_id
  and inv.stock_item_id = si.id
  and pi.client_legal_informations_id = 12
  and inv.id = (select max(inv_sub.id)
                from invoice inv_sub,
                     stock_item si_sub
                where inv_sub.id in (inv.id)
                  and inv_sub.warehouses_id = w.id
                  and inv_sub.archive = false
                  and inv_sub.expense = false
                  and inv_sub.stock_item_id = si_sub.id
                  group by inv_sub.id,
                  limit 1);

目前还不清楚为什么它返回两行,但应该只返回一行,这是一个重要的条件。我发现子查询返回两行,因此外部查询也返回两张发票。但是为什么内部查询返回两行呢?

我将真实值插入到子查询中查看它返回的内容,结果如下:

select min(inv_sub.id)
from invoice inv_sub,
     stock_item si_sub
where inv_sub.id in (285, 286)
  and inv_sub.warehouses_id = 623
  and inv_sub.archive = false
  and inv_sub.expense = false
  and inv_sub.stock_item_id = si_sub.id
  group by inv_sub.id,
  limit 1;

这个查询返回了两行。这是怎么回事,这是为什么?

不知怎的,这个建议没有帮助。此查询仍然返回两行,但我们需要最后一张未注销的发票的数据

SELECT inv.price_for_one AS costPriceGoods
            FROM invoice inv,
                 posinfo pi,
                 goods g,
                 stock_item si,
                 warehouses w
            WHERE si.goods_id = g.id
              AND pi.client_legal_informations_id = 12
              AND w.pos_info_id = pi.id
              AND si.warehouses_id = w.id
              AND inv.stock_item_id = si.id
              AND inv.id = (SELECT DISTINCT inv_sub.id
                            FROM invoice inv_sub,
                                 stock_item si_sub
                            WHERE inv_sub.id in (inv.id)
                              AND inv_sub.warehouses_id = w.id
                              AND inv_sub.archive = FALSE
                              AND inv_sub.expense = FALSE
                              AND inv_sub.stock_item_id = si_sub.id
                            ORDER BY inv_sub.id
                            LIMIT 1)
              AND g.id = 10121
            ORDER BY inv.id;

而且内部查询返回一行

SELECT DISTINCT inv_sub.id
                            FROM invoice inv_sub,
                                 stock_item si_sub
                            WHERE inv_sub.id in (287, 288)
                              AND inv_sub.warehouses_id = 205
                              AND inv_sub.archive = FALSE
                              AND inv_sub.expense = FALSE
                              AND inv_sub.stock_item_id = si_sub.id
                            ORDER BY inv_sub.id
                            LIMIT 1
mysql
  • 1 个回答
  • 51 Views
Martin Hope
typemoon
Asked: 2024-05-20 23:15:53 +0000 UTC

不使用内连接来连接表,它是如何工作的?

  • 5

请解释一下在查询中连接这样的表而不是连接是如何工作的?表格只是简单列出。此外,在业务逻辑中,带有 and 和 or 的条件可以附加到该查询、where 块,因此,正如我所知,这里不适合使用联接,并且表必须以这种方式联接。为什么?这是我第一次看到这样没有连接的表连接。

SELECT SUM(`order`.total )  as count
FROM `check`, `order`, `posinfo`
WHERE `check`.id = `order`.order_check_id
    AND `order`.canseled=false

mysql
  • 1 个回答
  • 53 Views
Martin Hope
typemoon
Asked: 2024-05-15 21:59:42 +0000 UTC

如果我添加了所需的依赖项,为什么在记录日志时会出现找不到记录器的错误?

  • 4

很长一段时间以来,我一直担心记录器会出现同样的错误,但现在才开始写下来。这是错误:

SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.

这个问题有一个解决方案,就是为记录器添加依赖项,但是这个解决方案不适合我,因为我无论如何都添加了logback依赖项,而且Spring也有记录器,我也出现了这个错误。

这是我的项目的代码:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.aoizora</groupId>
    <artifactId>camel-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>22</maven.compiler.source>
        <maven.compiler.target>22</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-core</artifactId>
                <version>4.6.0</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.5.6</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
    </dependencies>

</project>

主要类别:

package aoizora;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class Main
{
    public static void main(String[] args) throws Exception
    {
        CamelContext camel = new DefaultCamelContext();

        camel.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception
            {
                from("timer:foo")
                        .log("Hello, Camel");
            }
        });

        camel.start();

        Thread.sleep(10000);

        camel.stop();
    }
}

可以看到,pom.xml添加了logback,但是还是出现错误。虽然在这个视频https://www.youtube.com/watch?v=ZY3dJ3e9vDo依赖项是相同的,但没有错误。

如何消除这个错误,让它看起来很漂亮?

java
  • 1 个回答
  • 25 Views
Martin Hope
typemoon
Asked: 2024-05-14 03:34:56 +0000 UTC

Spring Boot应用程序无法连接到docker-compose内的mysql

  • 5

我需要使用 docker-compose 在带有 mysql 数据库的 Spring Boot 上运行我的应用程序。为什么通过这样的服务配置,应用程序(app)无法连接到mysql(db)?

Dockerfile:

FROM openjdk:23-slim
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

docker-compose.yml:

version: "3"

services:
  db:
    image: mysql:5.7
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=123
      - MYSQL_DATABASE=catalogue
    ports:
      - "3306:3306"
    expose:
      - 3306
    volumes:
      - db:/var/lib/mysql
    networks:
      - net

  app:
    depends_on:
      - db
    build:
      context: .
      dockerfile: Dockerfile
    restart: on-failure
    ports:
      - "8080:8080"
    networks:
      - net

volumes:
  db:

networks:
  net:
    driver: bridge

Java应用程序配置:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/catalogue
    username: root
    password: 123
    driver-class-name=com: com.mysql.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.MySQL8Dialect
    defer-datasource-initialization: true
  sql:
    init:
      mode: always

错误是这样的:The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

mysql
  • 1 个回答
  • 15 Views
Martin Hope
typemoon
Asked: 2024-01-06 19:47:30 +0000 UTC

无法通过 HTTPS 代理访问该站点错误代码:SSL_ERROR_RX_RECORD_TOO_LONG

  • 5

我无法通过 HTTPS 代理访问该网站。我在这里获取了代理列表:https ://hidemy.io/ru/proxy-list/?type=s#list

我选择了第一个代理95.56.254.139:3128,在 Firefox 的附加组件中,Foxy Proxy我指定了代理的标题、类型 HTTPS、主机名 95.56.254.139、端口 3128 并启用了该代理。但是当我尝试访问该网站时收到错误:

Secure Connection Failed

An error occurred during a connection to 2ip.ru. SSL received a record that exceeded the maximum permissible length.

Error code: SSL_ERROR_RX_RECORD_TOO_LONG

为什么会出现这个错误并且无法通过代理访问网站?

为什么在Python中,当通过requests库发出请求时,请求也不通过代理发送?

proxies = {
        'https': '95.56.254.139:3128'
    }

response = requests.post(url=url, headers = headers, data=data, proxies = proxies)
python
  • 1 个回答
  • 26 Views
Martin Hope
typemoon
Asked: 2024-01-04 05:57:40 +0000 UTC

Qt6 以及信号和槽的新语法

  • 6

我想了解如何在 Qt5 中基于方法指针使用信号和槽的新语法。我从书中获取了以下代码:

#include <QApplication>
#include <QHBoxLayout>
#include <QSlider>
#include <QSpinBox>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWidget* window = new QWidget;
    window->setWindowTitle("Set your age");

    QSpinBox* spinBox = new QSpinBox;
    QSlider* slider = new QSlider(Qt::Horizontal);
    spinBox->setRange(0, 130);
    slider->setRange(0, 130);

    QObject::connect(spinBox, &QSpinBox::valueChanged, slider, &QSlider::setValue);
    QObject::connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int)));
    spinBox->setValue(35);

    QHBoxLayout* layout = new QHBoxLayout;
    layout->addWidget(spinBox);
    layout->addWidget(slider);
    window->setLayout(layout);

    window->show();

    return app.exec();
}

我稍微更正了该行,以便使用指向方法的指针而不是宏:

QObject::connect(spinBox, &QSpinBox::valueChanged, slider, &QSlider::setValue);

此后,代码停止编译并抛出错误

错误:没有匹配的函数可用于调用 'QObject::connect(QSpinBox*&, <未解析的重载函数类型>, QSlider*&, void (QAbstractSlider::*)(int))' 17 |
QObject::connect(spinBox, &QSpinBox::valueChanged, slider, &QSlider::setValue); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~

如何在新语法中正确使用信号和槽以避免出现此错误?

c++
  • 1 个回答
  • 39 Views
Martin Hope
typemoon
Asked: 2023-12-26 20:35:02 +0000 UTC

boost::asio 定时器的奇怪行为

  • 6

boost 文档有以下示例代码:

#include <iostream>
#include <boost/asio.hpp>
#include <boost/bind.hpp>

using namespace boost;

void print(const system::error_code& e, asio::steady_timer* timer, int count)
{
    if (count < 5)
    {
        std::cout << count << std::endl;
        ++count;
        timer->expires_at(timer->expiry() + asio::chrono::seconds(1));
        timer->async_wait(boost::bind(print, asio::placeholders::error, timer, count));
    }
}

int main()
{
    asio::io_context io;
    int count = 0;
    asio::steady_timer t(io, asio::chrono::seconds(1));
    t.async_wait(bind(print, asio::placeholders::error, &t, count));
    io.run();
    return 0;
}

这里,在 main 函数中,定时器的初始值是 5 秒:

asio::steady_timer t(io, asio::chrono::seconds(5));

这个初始值有什么用呢?我注意到,如果去掉这个参数,即这样做:

asio::steady_timer t(io);

那么计时器会立即显示从 0 到 5 的所有值,而不是每秒一次。为什么会有这种行为?为什么定时器需要有一个初始值才能每秒输出一次值?

c++
  • 1 个回答
  • 45 Views
Martin Hope
typemoon
Asked: 2023-11-05 02:13:21 +0000 UTC

如何通过 SSL 套接字读取数据

  • 3

我想从连接受SSL保护的服务器读取数据,并尝试实施长轮询dos攻击。如何通过SSL套接字与服务器正确通信?这段代码没有从服务器接收任何东西(以VK为例)。

package socket;

import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.util.Scanner;

    public class Main
{
    private final static String target = "vk.com";

    public static void main(String[] args) throws IOException
    {
        System.setProperty("javax.net.ssl.keyStore", "/home/aoizora/keystore.jks");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");

        try (var s = (SSLSocket) SSLSocketFactory.getDefault().createSocket(target, 443);
             var in = new Scanner(s.getInputStream());
             var out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(s.getOutputStream()))))
        {
            s.startHandshake();

            out.print("GET / HTTP/1.1\r\n");
            out.write(String.format("Host: %s", target));
            out.println();

            while (in.hasNextLine())
            {
                System.out.println(in.nextLine());
            }
        }
    }
}

我生成并连接了 SSL 证书,但没有帮助。

System.setProperty("javax.net.ssl.keyStore", "/home/aoizora/keystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
java
  • 1 个回答
  • 56 Views
Martin Hope
typemoon
Asked: 2023-09-25 16:39:16 +0000 UTC

C++HANA生成JSON

  • 5

我如何补充此代码,以便它不显示字段值,而是显示 json,例如:

'{"name":"John", "age":30}'



#include <iostream>
#include <string>
#include <boost/hana.hpp>

struct Person
{
    BOOST_HANA_DEFINE_STRUCT(Person,
        (std::string, name),
        (int, age)
    );
};


int main()
{
    namespace hana = boost::hana;

    auto serialize = [](std::ostream& os, const auto& object) {
        hana::for_each(hana::members(object), [&](auto member) {
            os << member << std::endl;
        });
    };

    Person john{"John", 30};
    serialize(std::cout, john);

    return 0;
}

我不知道如何使用 hana 获取字段名称;文档中没有这样的示例。

我的尝试无法编译:

auto serialize2 = [](std::ostream& os, const auto& object) -> std::string {
    std::string json = "{";
    hana::for_each(object, [&json](auto pair) {
        json += "\"" + hana::to<const char *>(hana::first(pair)) + "\":\"" + hana::second(pair) + "\"";
    });
    json += "}";
    os << json;
    return json;
};

错误:二进制表达式的操作数无效(“const char[2]”和“const char *”)

c++
  • 1 个回答
  • 26 Views
Martin Hope
typemoon
Asked: 2023-09-06 12:46:25 +0000 UTC

从控制台读取结构字段在输出回控制台时会产生垃圾

  • 4

我需要创建新对象,用控制台中的数据填充它们的字段。该对象包含以下字段:

struct object
{
    std::string name;
    std::string type;
    double x;
    double y;
    std::time_t time;

    double distance() const
    {
        // Расстояние от точки (0, 0) до объекта
        return std::sqrt(
            std::pow(x, 2) + std::pow(y, 2)
        );
    }
};

我读取对象并将其输出到控制台,如下所示:

inline std::ostream& operator<<(std::ostream& os, const object& o)
{
    os << "name: " << o.name
        << " type: " << o.type
        << " x: " << o.x
        << " y: " << o.y
        << " time: " << ctime(&o.time);

    return os;
}

inline object operator >> (std::istream& is, object& o)
{
    object obj;

    std::cout << "Enter name: ";
    is >> obj.name;
    std::cout << std::endl << "Enter x coordinate: ";
    is >> obj.x;
    std::cout << std::endl << "Enter y coordinate: ";
    is >> obj.y;
    std::cout << std::endl << "Enter type: ";
    is >> obj.type;
    obj.time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

    return obj;
}

问题是,当读取然后打印对象时,会输出垃圾或零值:

Enter object data: 
Enter name, x coordinate, y coordinate and type: ttt 12.5 12.5 rrr
view::update() called
Added object: name:  type:  x: 0 y: 0 time: Thu Jan  1 03:00:00 1970

这是为什么?创作日期也很奇怪——一个时代的开始。如何在对象中存储当前日期(这是对象创建的时间)?

添加了一个最小的可重现示例:

#include <string>
#include <chrono>
#include <iostream>
#include <cmath>
#include <ctime>

struct object
{
    std::string name;
    std::string type;
    double x;
    double y;
    std::time_t time;

    double distance() const
    {
        // Расстояние от точки (0, 0) до объекта
        return std::sqrt(
            std::pow(x, 2) + std::pow(y, 2)
        );
    }
};

inline std::ostream& operator<<(std::ostream& os, const object& o)
{
    os << "name: " << o.name
        << " type: " << o.type
        << " x: " << o.x
        << " y: " << o.y
        << " time: " << ctime(&o.time);

    return os;
}

inline object operator >> (std::istream& is, object& o)
{
    object obj;

    std::cout << "Enter name, x coordinate, y coordinate and type: ";
    is >> obj.name >>
            obj.x >>
            obj.y >>
            obj.type;

    obj.time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

    return obj;
}

int main()
{
    object obj;

    std::cin >> obj;

    std::cout << obj;

    return 0;
}
c++
  • 1 个回答
  • 37 Views
Martin Hope
typemoon
Asked: 2023-08-23 16:39:11 +0000 UTC

C++ Boost ASIO:没有匹配的成员函数来调用“write_some”

  • 5

我想编写一个可以建立安全连接的套接字。写了这段代码:

#pragma once

#include <boost/asio.hpp>
#include <cstdint>
#include <string>

using boost::asio::ip::tcp;

class SecureSocket
{
public:
    SecureSocket(boost::asio::io_context ctx, int port, uint32_t encryptionKey = 123);

    int send(const std::string& msg) const;
    int send(const void* msg, std::size_t size);
    int recv(std::string& msg, int length, double timeoutSecs = -1.0) const;
    int recv(void* msg, int length, double timeoutSecs = -1.0) const;

private:
    tcp::socket socket;
    int port;
    std::uint32_t encryptionKey;
    std::string encrypt(const void* message, std::size_t size) const;
    std::string decrypt(const void* message, std::size_t size) const;
};

及实施

#include "secure_socket.h"

SecureSocket::SecureSocket(boost::asio::io_context ctx, int port, uint32_t encryptionKey)
    : socket(ctx, tcp::v4()), port(port), encryptionKey(encryptionKey)
{

}


std::string SecureSocket::encrypt(const void *message, std::size_t size) const
{
    std::string msg;
    std::string encryptedMsg;

    for (int i = 0; i < size; i++)
    {
        msg.push_back(static_cast<const char *>(message)[i]);
    }

    return msg;
}

std::string SecureSocket::decrypt(const void *message, std::size_t size) const
{
    return SecureSocket::encrypt(message, size);
}

int SecureSocket::send(const std::string &msg) const
{
    auto encryptedMsg = encrypt(msg.c_str(), msg.size());
    boost::system::error_code ignoredError;

    return boost::asio::write(socket, boost::asio::buffer(encryptedMsg));
}

但是这段代码无法编译,出现错误

> /home/aoizora/QtCreator/Bot/socket/src/secure_socket.cpp:33: error: no
> matching member function for call to 'write_some' In file included
> from /home/aoizora/QtCreator/Bot/socket/src/secure_socket.cpp:1: In
> file included from
> /home/aoizora/QtCreator/Bot/socket/include/secure_socket.h:3: In file
> included from /usr/include/boost/asio.hpp:43: In file included from
> /usr/include/boost/asio/buffered_stream.hpp:22: In file included from
> /usr/include/boost/asio/buffered_write_stream.hpp:28: In file included
> from /usr/include/boost/asio/write.hpp:1246:
> /usr/include/boost/asio/impl/write.hpp:55:23: error: no matching
> member function for call to 'write_some'
>         tmp.consume(s.write_some(tmp.prepare(max_size), ec));
>                     ~~^~~~~~~~~~ /usr/include/boost/asio/impl/write.hpp:71:18: note: in instantiation
> of function template specialization
> 'boost::asio::detail::write_buffer_sequence<const
> boost::asio::basic_stream_socket<boost::asio::ip::tcp>,
> boost::asio::mutable_buffers_1, const boost::asio::mutable_buffer *,
> boost::asio::detail::transfer_all_t>' requested here   return
> detail::write_buffer_sequence(s, buffers,
>                  ^ /usr/include/boost/asio/impl/write.hpp:83:35: note: in instantiation of function template specialization
> 'boost::asio::write<const
> boost::asio::basic_stream_socket<boost::asio::ip::tcp>,
> boost::asio::mutable_buffers_1, boost::asio::detail::transfer_all_t>'
> requested here   std::size_t bytes_transferred = write(s, buffers,
> transfer_all(), ec);
>                                   ^ /home/aoizora/QtCreator/Bot/socket/src/secure_socket.cpp:33:25: note:
> in instantiation of function template specialization
> 'boost::asio::write<const
> boost::asio::basic_stream_socket<boost::asio::ip::tcp>,
> boost::asio::mutable_buffers_1>' requested here
>     return boost::asio::write(socket, boost::asio::buffer(encryptedMsg));
>                         ^ /usr/include/boost/asio/basic_stream_socket.hpp:803:15: note:
> candidate function template not viable: 'this' argument has type
> 'const boost::asio::basic_stream_socket<boost::asio::ip::tcp>', but
> method is not marked const   std::size_t write_some(const
> ConstBufferSequence& buffers,
>               ^ /usr/include/boost/asio/basic_stream_socket.hpp:777:15: note:
> candidate function template not viable: requires single argument
> 'buffers', but 2 arguments were provided   std::size_t
> write_some(const ConstBufferSequence& buffers)
>               ^

为什么会出错?我似乎一切都做对了。如何修复代码?

c++
  • 1 个回答
  • 11 Views
Martin Hope
typemoon
Asked: 2023-07-26 21:37:52 +0000 UTC

为什么在remove_const模板中删除constness?

  • 5

您能否告诉我这些模板中使用了哪些类型推断和类型操作规则,从而消除了常量性?为什么会发生这种情况?

#include <iostream>

template<typename T>
struct type_is {
    using type = T;
};

template<typename T>
struct remove_const : type_is<T> {

};

template<typename T>
struct remove_const<const T> : type_is<T> {

};

template<typename U, typename V>
constexpr bool same = std::is_same_v<U, V>;

int main(int argc, char **argv)
{
    static_assert(same<remove_const<const int>::type, int>);

    return 0;
}

据我了解,继承用于不重新定义类型字段。声明中使用了什么类型推断规则using type = T?起初我以为恒常性、参照性和波动性在这里被丢弃了,但事实证明并非如此。这是一个类型别名,这里不丢弃常量性。type模板中的字段如何专门化remove_const以const T丢弃常量?为什么她会被拒绝?

c++
  • 2 个回答
  • 44 Views
Martin Hope
typemoon
Asked: 2023-07-06 14:47:48 +0000 UTC

C++ 按字典顺序逆序对 IP 地址进行排序

  • 5

我需要比较 IP 地址列表并按逆字典顺序对它们进行排序。

字典排序的示例(按第一个字节,然后按第二个字节,依此类推):

  • 1.1.1.1
  • 1.2.1.1
  • 1.10.1.1

相应地,反过来:

  • 1.10.1.1
  • 1.2.1.1
  • 1.1.1.1

如何编写一个比较器来按此顺序比较地址,如果存储 IP 地址的数据结构是常规 int,即将八位字节打包成 int 并以整数的字节存储:

using ip = int;
using ip_pool = std::vector<ip>;

ip make_ip(const std::vector<std::string>& splitted)
{
    validate_ip(splitted);

    int _3 = std::stoi(splitted[0]);
    int _2 = std::stoi(splitted[1]);
    int _1 = std::stoi(splitted[2]);
    int _0 = std::stoi(splitted[3]);

    return _3 << 24 | _2 << 16 | _1 << 8 | _0;
}

我仍然有这个比较器,但由于某种原因,它对地址进行了错误的排序:整个地址池分为两部分,每部分都按相反的字典顺序排序,但不是连续的。这是为什么?怎样做才正确呢?

void sort_lexicographically(ip_pool& pool)
{
    std::sort(pool.begin(), pool.end(), std::greater<int>());

    /*std::sort(pool.begin(), pool.end(), [](const int& lhs, const int& rhs) {
        return ((lhs >> 24 & 0xFF) > (rhs >> 24 & 0xFF) &&
                (lhs >> 16 & 0xFF) > (rhs >> 16 & 0xFF) &&
                (lhs >>  8 & 0xFF) > (rhs >>  8 & 0xFF) &&
                (lhs & 0xFF) > (rhs & 0xFF));
    });*/
}

地址沿着这条线划分

1.231.69.33
1.87.203.225
1.70.44.170
1.29.168.152
1.1.234.8
222.173.235.246
222.130.177.64
222.82.198.61
222.42.146.225
220.189.194.162
c++
  • 1 个回答
  • 35 Views
Martin Hope
typemoon
Asked: 2020-06-20 15:44:25 +0000 UTC

在 Spring Data JPA 中定义简单键的问题

  • 0

我想编写处理来自外部源的事件的逻辑。事件处理是这样的:

  • 获取一个事件,将其存储在 postgres 表中。
  • 使用 cron,从该表中提取所有事件记录并通过电子邮件发送
  • 每次成功提交,相应的事件都会被删除。

我写了这个实体类:

@Entity
@Table(name = "invoice_warning_events")
public class InvoiceWarningEvent {

    @Id
    @Column(name = "invoice_uid")
    @JsonProperty
    private String invoiceUid;

    @Column(name = "invoice_number")
    @JsonProperty
    private String invoiceNumber;

    @Column(name ="company_msp")
    @JsonProperty
    private String companyMSP;

    @Column(name = "error_message")
    @JsonProperty
    private String errorMessage;

第一个问题出现在我写的时候JpaRepository。读取了表中的记录,但该方法 invoiceWarningRepository.delete(evt);没有删除任何内容。

然后我尝试挂在@Id-field 注释@GeneratedValue(strategy = GenerationType.AUTO)和@GeneratedValue(strategy = GenerationType.IDENTITY). 在第一种情况下,发生了错误:

id 的未知整数数据类型:java.lang.String;嵌套异常是 org.hibernate.id.IdentifierGenerationException: ids 的未知整数数据类型:java.lang.String

在第二种情况下,我得到一个错误

无法执行语句;SQL [不适用];约束[invoice_uid];嵌套异常是 org.hibernate.exception.ConstraintViolationException:无法执行语句

事实上,invoice_uid 字段必须是唯一的,它被定义为数据库中的主键。这是必要的,因此关于同一张发票的许多事件导致只出现一条记录,该记录不断更新。

如何消除此错误?

还有,如果记录已经存在,可以用什么方法来实现插入或更新操作?

hibernate
  • 1 个回答
  • 10 Views
Martin Hope
typemoon
Asked: 2020-05-22 19:39:51 +0000 UTC

java中的轻量级异步消息服务

  • 0

问题更多是关于架构而不是编程。我需要编写一个通知服务,通过REST-api 接收消息并从中制作作业,这会将它们放入作业队列中。每一项这样的工作都必须完成。如果成功,则从队列中删除作业,并向客户端返回成功消息。如果作业失败,则将其放入第二个重试队列。尝试次数不超过 3 次。必须记录这两个操作。有必要提供几种执行工作的方法。

实现这一点的最简单方法是什么?像 RabbitMQ 和 ActiveMQ 这样的消息代理是多余的。是否有创建轻量级内存代理的库?

服务的负载不会很高。

服务必须是异步的。

java
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5