关于如何使用 SpringBoot 应用程序实现结构化日志记录的小问题,但使用 log4j2(使用 logback,但不使用 log4j)。
我有一个超级简单的 SpringBoot 应用程序:
@RestController
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@RequestMapping("/")
public String index(@RequestHeader("accept") String acceptHeader) {
MDC.put("acceptHeader", acceptHeader);
LoggerFactory.getLogger(getClass()).info("Hello");
return "Greetings from Spring Boot!";
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> function(ctx);
}
private void function(ApplicationContext ctx) {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
}
}
Run Code Online (Sandbox Code Playgroud)
用一个简单的 …
所以基本上我有这个函数返回:3.00000000000E000
function lang():extended;
begin
wynik := 0 ;
counter := 1;
temp :=1;
input := 2;
for i:= 1 to 4 do
begin
for k:= 1 to 4 do
begin
if i = k then counter := counter
else temp := temp * ((input - a[k]) / (a[i] - a[k]));
end;
wynik := wynik + temp*f[i];
temp := 1;
end;
Result := wynik;
end;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用 FloatToStr 在应用程序屏幕上打印它时,我只得到 3。
procedure TFormCalculator.Button1Click(Sender: TObject);
begin
Edit1.Text := FloatToStr(lang());
end;
Run Code Online (Sandbox Code Playgroud)
如何保留结果的长版本?
下面的代码可以在 PHP 中运行,但不能在 JS 中运行。你能告诉我为什么吗?我怎样才能让纯JS版本工作?
async function cccrFlow() {
response = await fetch('assets/club_mems.json');
club_mems = [];
club_mems = await response.json(); // DOESN"T WORK
}
function cccrFlow() {
club_mems = <?php include('assets/club_mems.json');?>; // WORKS PERFECTLY
}
Run Code Online (Sandbox Code Playgroud)
[{"Name":"Ahmedistan, Jamshed","clubEXP":"2022-09-15"},{"Name":"Anaizi, Paul N","clubEXP":"2021-01-27"},{"Name":"Anderson, Simon","clubEXP":"2022-06-30"},{"Name":"Ashes, Bob P","clubEXP":"2022-04-21"}]
Run Code Online (Sandbox Code Playgroud) java我正在使用bouncy castle库加载公钥,但总是出现错误Invalid point encoding 0x45。
公钥是使用 C# CNG API 在客户端生成的。
Java方法1:
public PublicKey loadPublicKey(String encodedPublicKey)
throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
byte[] keybytes = java.util.Base64.getDecoder().decode(encodedPublicKey);
Security.addProvider(new BouncyCastleProvider());
ECNamedCurveParameterSpec params = ECNamedCurveTable.getParameterSpec("P-256");
ECPublicKeySpec keySpec = new ECPublicKeySpec(params.getCurve().decodePoint(keybytes), params);
return new BCECPublicKey("ECDH", keySpec, BouncyCastleProvider.CONFIGURATION);
}
Run Code Online (Sandbox Code Playgroud)
方法二
public PublicKey loadPublicKey(String pKey) throws Exception {
byte[] keybytes = java.util.Base64.getDecoder().decode(pKey);
Security.addProvider(new BouncyCastleProvider());
ECParameterSpec params = ECNamedCurveTable.getParameterSpec("P-256");
ECPublicKeySpec pubKey = new ECPublicKeySpec(params.getCurve().decodePoint(keybytes), params);
KeyFactory kf = KeyFactory.getInstance("ECDH", "BC");
return kf.generatePublic(pubKey);
}
Run Code Online (Sandbox Code Playgroud)
例外 …
假设数组中有以下数据:
$data1 = [3,5,7,6,8,9,13,14,17,15,16,16,16,18,22,20,21,20];
$data2 = [23,18,17,17,16,15,16,14,15,10,11,7,4,5];
我们可以$data1说数据在增加,而数据在$data2减少。
使用 PHP,你如何知道数据在增加或减少,有没有一种方法可以测量增加和减少的比率,即以百分比的形式。
编辑
从我收到的评论中我得到了一个想法,这就是我尝试过的。我想要实现什么;
$data1 = [1,3,5];不一样$data2 = [1, 20, 55];。可以看到$data1增长率不一样$data2。function increaseOrDecrease($streams = []) : array
{
$streams = [3,5,7,6,8,9,13,14,17,15,16,16,16,18,22,20,21,20]; // For the increasing
//$streams = [23,18,17,17,16,15,16,14,15,10,11,7,4,5]; // For the decreasing
$first = 0;
$diff = [];
foreach ($streams as $key => $number) {
if ($key != 0) {
$diff[] = $number - $first;
}
$first = $number; …Run Code Online (Sandbox Code Playgroud) 我想测试(使用 PHPUnit)一个包含 foreach 循环的方法。我想要完整的路径覆盖。原始代码有点太复杂,所以我在下面创建了一个最小的示例来说明我的问题。foreachPHP中的循环有3种情况。(我使用 PHP 8.2。)
public function dodo(array $a)\n {\n foreach ($a as $one) {\n return $one;\n }\n\n return null;\n }\nRun Code Online (Sandbox Code Playgroud)\n很容易涵盖前两个:非空数组和空数组。但是我如何传递一个不可迭代的东西作为函数参数呢?我尝试了几种方法,但我\xe2\x80\x99已经得到了类型错误。
\n$something->dodo(null); # TypeError\n\ncall_user_func([$something, 'dodo'], null); # TypeError\n\n$rClass = new ReflectionClass($something);\n$rMethod = $rClass->getMethod('dodo');\n$rMethod->invoke($something, null); # TypeError\nRun Code Online (Sandbox Code Playgroud)\n我不想\xe2\x80\x99 不想从方法定义中删除或更改类型。这会使代码的可读性降低一些。有办法解决吗?如何编写一个涵盖 foreach 循环的所有情况的测试?
\n换句话说:\n我如何使用dodo错误类型的参数调用?我想编写具有非常高的代码路径覆盖率的测试。
我在反序列化响应期间遇到问题。假设我使用 webclient 来自第三方的响应。
Response :
{
"name":"FirstName",
"type":"Steel",
"Fee":{
"id":"1234",
"name":"FeeFirstName"
},
"address":"2nd Street"
}
Run Code Online (Sandbox Code Playgroud)
这就是我的 pojo 类的样子
public class Fee{} //generic OR empty class
public class Foo{
private String name;
private String type;
private Fee fee;
private String address;
}
Run Code Online (Sandbox Code Playgroud)
我的网络客户端获取响应代码:
@Autowired
private WebClient fooWebClient;
public Foo getFoo()
{
try{
return fooWebClient.get()
.uri(uriBuilder -> uriBuilder.path("/foo/fee").build("123"))
.header(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Foo.class)
.block();
}catch(Exception e){throw new ApiClientException(e.getMessage());}
}
Run Code Online (Sandbox Code Playgroud)
上面的 webclient getFoo() 代码没有给我完整的响应,费用是空白的,说明“类没有字段”。其余的值都会正确响应。费用需要为空,因为任何其他对象也可以出现。
请让我知道如何反序列化整个响应。
我的程序需要将一个 xml 文件转换为另一个与通过我们公司程序发送发票兼容的 xml 文件。
代码的编译没有问题,而当我启动 .bat 文件时,出现此错误:
Exception in thread "main" java.lang.IllegalAccessError:
class controller.ConversionWorker (in unnamed module @0x71c8becc)
cannot access class com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl (in module java.xml)
because module java.xml does not export com.sun.org.apache.xerces.internal.jaxp.datatype to unnamed module @0x71c8becc
Run Code Online (Sandbox Code Playgroud)
这是生成异常的代码:
private XMLGregorianCalendar stringToXMLGregorian(String data, String pattern) {
Calendar date = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat(pattern);
try {
date.setTime(format.parse(data));
} catch (ParseException e) {
e.printStackTrace();
Log.debug("ERRORE DI CONVERSIONE DATA: " + data);
}
XMLGregorianCalendar result = new XMLGregorianCalendarImpl();
result.setYear(date.get(Calendar.YEAR));
result.setMonth(date.get(Calendar.MONTH) + 1); …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取过去 48 小时内至少有 2 条评论的所有帖子。我正在使用以下代码:
$posts= Post::has( 'comments', '>', 1 )->whereHas( 'comments', function( $comments ) {
return $comments->where( 'created_at', '>', Carbon::now()->subDays(2) );
})->get()->toArray();
Run Code Online (Sandbox Code Playgroud)
我有一个名为的集合Dataframe,本质上是一个std::vector<char>. 它包含records特定的长度record_size,可以由1个或多个不同类型的字段组成。的定义Dataframe是不可协商的,因为它与代码库的其余部分紧密耦合。一般来说,该结构可以包含数百万数量级的大量记录和数百数量级的大量列。
根据我上面所说的,可能只有一个列或多列。单例列,就是我所说的简单情况,因为字符向量可以转换为实际类型,并且排序非常有效。
我遇到的问题是,对于多个列,我需要有一个指向记录的指针向量,应用一个跳转到内存中访问实际数据的比较器函数,然后交换指针,当排序过程结束时,应用到真实数据由指针标识的排列。这会比较慢,尤其是当Dataframe包含真实世界数据时。
下面的代码摘录可以更好地解释这种情况。有没有其他方法可以解决这个问题?
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <functional>
class Dataframe {
public:
enum class Base : char
{
SIGNED = 'S',
UNSIGNED = 'U',
CHAR = 'A',
// and other types like floats, date, timestamp, etc.
};
class Dtype
{
public:
Dtype(Base base_dtype, std::size_t size) : m_base_dtype(base_dtype), m_size(size) {}
auto base_dtype() const { return m_base_dtype; }
auto …Run Code Online (Sandbox Code Playgroud) java ×4
php ×3
algorithm ×2
bouncycastle ×1
c# ×1
c++ ×1
cryptography ×1
delphi ×1
eloquent ×1
fetch-api ×1
javascript ×1
laravel ×1
lazarus ×1
log4j2 ×1
math ×1
pascal ×1
performance ×1
php-8.2 ×1
phpunit ×1
sorting ×1
spring-boot ×1
statistics ×1
type-hinting ×1