我的目标是world-service从config-service.
架构:
config-service依赖spring-cloud-config-server于localhost:8888world-service依赖于spring-web和spring-cloud-starter-config。我做了什么:
http://localhost:8888/hello-service/master配置服务器hello-service.properties从config-repo 存储库中获取。(如果你需要它config-service的源代码,我会把它推送到这个仓库。)我的预期结果:world-service使用端口 8081。
我的实际结果:world-service使用端口 8080。
bootstrap.properties
spring.application.name=world-service
spring.cloud.config.uri=http://localhost:8888
Run Code Online (Sandbox Code Playgroud)
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>world-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>world-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.0-M5</spring-cloud.version>
</properties>
<dependencies>
<dependency> …Run Code Online (Sandbox Code Playgroud) 我的目标是将函数嵌入到现有类型中。
我正在关注Effective Go
问题是它发出警告var parent *embedding.Parent github.com/kidfrom/learn-golang/embedding.Child struct literal uses unkeyed fields。
当前的解决方案是创建NewChild(parent *Parent) *Child. 但是,我担心这只是欺骗编译器,将来它会意外地恐慌,那么我做错了什么?
func NewChild(parent *Parent) *Child {
return &Child{parent}
}
Run Code Online (Sandbox Code Playgroud)
cmd/测试/main.go
package main
import "github.com/kidfrom/learn-golang/embedding"
func main() {
parent := &embedding.Parent{}
child := &embedding.Child{parent} // it warns `var parent *embedding.Parent
github.com/kidfrom/learn-golang/embedding.Child struct literal uses unkeyed fields`
child.CallParentMethod()
}
Run Code Online (Sandbox Code Playgroud)
嵌入.go
package embedding
import "fmt"
type Parent struct{}
func (p *Parent) parentMethod() {
fmt.Println("parent method")
}
type Child struct {
*Parent
}
func …Run Code Online (Sandbox Code Playgroud) 我的目标是了解 volatile 关键字的工作原理。
我的预期结果: assertEquals 没有失败。
我的实际结果: assertEquals 失败。(有时实际计数值在 9991 到 9999 之间)。
我假设这是因为增量运算符 /count++等于
public void increment() {
int temp = count;
count = temp + 1;
}
Run Code Online (Sandbox Code Playgroud)
考虑到这一点,该temp属性是线程本地存储的。我是真的吗?
计数器.java
public class Counter implements Runnable {
private volatile int count = 0;
public int getCount() { return count; }
public void increment() { count++; }
@Override
public void run() { increment(); }
}
Run Code Online (Sandbox Code Playgroud)
CounterTest.java
public class CounterTest {
@Test
void increment() {
ExecutorService service = …Run Code Online (Sandbox Code Playgroud) 我的目标是将带有密码的私钥存储在 GitHub 机密中,但我不知道如何通过 GitHub 操作输入密码。
我尝试过的:
.github/workflows/docker-build.yml
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs …Run Code Online (Sandbox Code Playgroud) 我的目标是理解为什么会有nginx图像和nginx:alpine图像。
我知道的:
nginx更大,52.79 MB。nginx使用debian:bullseye-slim.nginx:alpine较小,为 9.51 MB。nginx:alpine使用alpine.docker run -p 8080:80 -v ${PWD}:/usr/share/nginx/html nginx:alpine我无法理解为什么默认图像使用debian:bullseye-slim而不是alpine.
我的目标是学习笔记本。它的召回率高达 97%,而我却在 F1 分数“流失的客户”77.9% 中苦苦挣扎。问题是笔记本使用LightGBM。我无法安装 LightGBM。
\n我尝试过的:
\npip install lightgbm-> 它抛出错误python setup.py egg_info did not run successfully.pip install wheel-> 现在它抛出错误python setup.py bdist_wheel did not run successfully.pip install Cmake,,pip install --upgrade pip setuptoolsbrew install libomp >错误仍然存在。完整错误
\n \xc3\x97 python setup.py bdist_wheel did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [80 lines of output]\n INFO:root:running bdist_wheel\n /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install …Run Code Online (Sandbox Code Playgroud) 我的目标是为 提供顶部和底部导航栏Home, Dashboard, and Album,但不为SignIn. 问题是,我希望将按钮放在底部而不是顶部。
最后剩下的难题是如何Sign In向底部导航栏添加按钮。
障碍是,如果您编写<Tab.Screen name="Sign In component={SignIn} />并按下带有参数的按钮onPress={() => navigation.navigate('SignIn')},它会将您导航到Tab.Screen而不是Stack.Screen。
const Tab = createBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Dashboard" component={Dashboard} />
<Tab.Screen name="Album" component={Album} />
</Tab.Navigator>
);
}
const Stack = createStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen options={{title: ''}} name="MyTabs" component={MyTabs} />
<Stack.Screen name="SignIn" component={SignIn} />
</Stack.Navigator>
);
}
export default function …Run Code Online (Sandbox Code Playgroud) 我用来ResponseEntity返回 GET“api/v1/name”和 POST“api/v1/name”请求的响应。
我的目标不是返回空值响应,例如在 POST“api/v1/name”请求中,当前响应正文为:
{
"id": null,
"name": "who",
"newid": "A8C90A53-78F6-4BD6-9628-CBA8FC349C08"
}
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像:
{
"name": "who",
"newid": "A8C90A53-78F6-4BD6-9628-CBA8FC349C08"
}
Run Code Online (Sandbox Code Playgroud)
在我看来,使用下面的代码重新创建对象只会使代码的可读性降低,并且可能会使用更多内存(我不确定,如果我错了,请告诉我):
...
Map<String, String> responseBody = new HashMap<>();
responseBody.put("name", nameModel.getName());
responseBody.put("newid", nameModel.getNewId());
return new ResponseEntity<>(responseBody, HttpStatus.OK);
Run Code Online (Sandbox Code Playgroud)
==== 下面是完整的存储库,如果您想查看更新的存储库:https ://github.com/kidfrom/g2_java/tree/main/etc/mssqlserver
控制器/NameController.java
package com.example.mssqlserver.controller;
import com.example.mssqlserver.mapper.NameMapper;
import com.example.mssqlserver.model.NameModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class NameController {
@Autowired
private NameMapper nameMapper;
@GetMapping("api/v1/name")
public ResponseEntity<?> selectAll() {
return new ResponseEntity<>(nameMapper.selectAll(), HttpStatus.OK);
}
@PostMapping("api/v1/name")
public ResponseEntity<?> insert(@RequestBody …Run Code Online (Sandbox Code Playgroud) 我的目标是将 2 个字节转换为 Char。
输入将从 abyte[]然后转换为 char。我最初的策略是使用按位运算。
我的预期结果:0xFF << 8 | 0xFF等于0xFFFF。确实如此。但是,实际上并非如此,因为在按位运算之前,我需要将数据存储在byte[].
我的实际结果:由于我访问数据的方式。(byte) 0xFF << 8 | (byte) 0xFF将等于-1。
byte[] bytes = new byte[]{(byte) 0xFF, (byte) 0xFF};
int integer = bytes[0] << 8 | bytes[1]; // -1 or 0xFFFFFFFF
Run Code Online (Sandbox Code Playgroud) 我的目标是了解字节在 Java 中的存储方式。
System.out.println("(byte) 0xFF:\r\n" +
Integer.toBinaryString((byte) 0xFF));
Run Code Online (Sandbox Code Playgroud)
我的预期结果(byte) 0xFF是0xFF。
我的实际结果(byte) 0xFF是0xFFFFFFFF
输出:
(byte) 0xFF:
11111111111111111111111111111111
Run Code Online (Sandbox Code Playgroud)
如果这是真的,那么在 in 中存储负数byte实际上与在 中存储负数没有区别int吗?
java ×5
spring ×2
spring-boot ×2
alpine-linux ×1
apple-m1 ×1
debian-based ×1
docker ×1
go ×1
kaggle ×1
lightgbm ×1
mybatis ×1
nginx ×1
pip ×1
python ×1
react-native ×1
spring-cloud ×1
ssh ×1