有没有一种简单的方法可以将给定的整数格式化为具有固定长度和前导零的字符串?
# convert numbers to strings of fixed length 3
[1, 12, 123, 1234].map { |e| ??? }
=> ["001", "012", "123", "234"]
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案,但也许有一种更聪明的方法.
format('%03d', e)[-3..-1]
Run Code Online (Sandbox Code Playgroud) 在 Azure Pipelines 中,您可以在排队时设置管道变量。您可以像使用管道本身定义的变量一样使用此类变量。
例子:
# pipeline.yml
steps:
- checkout: none
- template: steps/some.yml
parameters:
name: $(queueTimeVar)
# steps/some.yml
parameters:
name: 'World'
steps:
- bash: |
echo "Hello ${{ parameters.name }}!"
Run Code Online (Sandbox Code Playgroud)
但是,如果未明确设置该变量,则管道会将此表达式评估为字符串本身。步骤模板将使用name: '$(queueTimeVar)'和 print调用Hello $(queueTimeVar)!。
如果未设置变量,如何设置默认值?
我尝试将默认值添加为变量,但没有按预期工作。
variables:
queueTimeVar: MyDefault
Run Code Online (Sandbox Code Playgroud)
之后,排队时间变量没有影响。变量始终是 YAML 值。
作为解决方法,我必须为每个使用该值的任务添加默认处理。
# bash task
value="MyDefault"
if [ -n "$QUEUETIMEVAR" ]; then
value="$QUEUETIMEVAR"
fi
Run Code Online (Sandbox Code Playgroud) Ruby的group_by()方法如何通过self其元素的标识(或更确切地说)对数组进行分组?
a = 'abccac'.chars
# => ["a", "b", "c", "c", "a", "c"]
a.group_by(&:???)
# should produce...
# { "a" => ["a", "a"],
# "b" => ["b"],
# "c" => ["c", "c", "c"] }
Run Code Online (Sandbox Code Playgroud) 我找不到使用Java流将一种类型(例如MyData)的集合减少到另一种类型的对象(例如)的解决方案MyResult.
@Test
public void streams() {
List<MyData> collection = Arrays.asList(
new MyData("1", "cool"),
new MyData("2", "green"),
new MyData("3", "night"));
// How reduce the collection with streams?
MyResult result = new MyResult();
collection.stream().forEach((e) -> {
if (e.key.equals("2")) {
result.color = e.value;
}
});
MyResult expectedResult = new MyResult();
expectedResult.color = "green";
assertThat(result).isEqualTo(expectedResult);
}
public static class MyData {
public String key;
public String value;
public MyData(String key, String value) {
this.key = key;
this.value = value;
} …Run Code Online (Sandbox Code Playgroud) 我创建了一个用于在多个 Spring Boot 应用程序上共享代码的库。
该库包含一个 Repository 类RequestRepository。将库添加到 Spring Boot 项目后,编译并成功运行单元测试。
// Library: RequestRepository.java
package org.test.lib;
public interface RequestRepository extends CrudRepository<Request, Integer> {}
// Application: Application.java
package org.test.app;
@SpringBootApplication
@ComponentScan(basePackages = {"org.test.app", "org.test.lib"})
public class Application {
// ...
}
Run Code Online (Sandbox Code Playgroud)
NoSuchBeanDefinitionException当 Spring 尝试自动装配存储库时,启动应用程序会引发。
原因::
org.springframework.beans.factory.NoSuchBeanDefinitionException没有可用的“ ”类型的合格 beanorg.test.lib.repositories.RequestRepository:预计至少有 1 个符合自动装配候选资格的 bean。依赖注释:{}
我为组件扫描启用了 DEBUG 日志记录,并获得了有关存储库的以下输出。
2018-07-10 08:33:25.035 DEBUG 14976 --- [ main] .isPathMatchingResourcePatternResolver :将位置模式 [classpath*:org/test/lib/**/*.class] 解析为资源 [URL [jar:file: /C:/Users/.../lib-request-1.0.0-SNAPSHOT.jar!/org/test/lib/repositories/RequestRepository.class], ...
我错过了什么?
为#<Mark:0x00000001e057d0>获取"undefined method` each'"
这是观点:
<% @current_marks.each do |m| %>
<tr>
<td class='col-md-3'><%= m.subject %></td>
<td class='col-md-3'><%= m.professor %></td>
<td class='col-md-3'><%= m.semester %></td>
<td class='col-md-3'><%= m.points %></td>
</tr>
<% end %>
Run Code Online (Sandbox Code Playgroud)
和控制器:
def show
@student = Student.find(params[:id])
@students = Student.all
@current_marks = Mark.find_by! student_id: @student.id
rescue ActiveRecord::RecordNotFound
redirect_to :action => 'set_marks'
end
Run Code Online (Sandbox Code Playgroud)
我已经检查了一个Id param并且它是正确的.我Mark也在DB中有正确的记录student_id.如何在@current_marks没有任何错误的情况下致电?
我在 Windows 机器上使用 Azure CLI 2.0,我正在尝试使用此Microsoft 文档创建 Docker VM :
az group deployment create --resource-group myResourceGroup \
--parameters '{"newStorageAccountName": {"value": "mystorageaccount"},
"adminUsername": {"value": "azureuser"},
"adminPassword": {"value": "P@ssw0rd!"},
"dnsNameForPublicIP": {"value": "mypublicdns"}}' \
--template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/docker-simple-on-ubuntu/azuredeploy.json
Run Code Online (Sandbox Code Playgroud)
将所有内容放在一行会导致“无法识别的参数”错误。用双引号替换参数单引号会导致“期望用双引号括起来的属性名称”错误,删除参数选项会导致预期的“部署模板验证失败”错误。提供参数值的正确方法是什么?
我正在使用 spring kafka 开发一个 Spring boot 应用程序,该应用程序侦听 kafka 的单个主题,然后隔离各个类别的记录,从中创建一个 json 文件并将其上传到 AWS S3。
我在 Kafka 主题中收到大量数据,我需要确保 json 文件分块得足够大,以限制上传到 S3 的 json 数量。
以下是我application.yml对 kafka 消费者的配置。
spring:
kafka:
consumer:
group-id: newton
auto-offset-reset: earliest
fetch-max-wait:
seconds: 1
fetch-min-size: 500000000
max-poll-records: 50000000
value-deserializer: com.forwarding.application.consumer.model.deserializer.MeasureDeserializer
Run Code Online (Sandbox Code Playgroud)
我创建了一个监听器来连续阅读该主题。
即使使用上述配置,我在控制台中收到的记录如下:
2019-03-27T15:25:56.02+0530 [APP/PROC/WEB/0] OUT 2019-03-27 09:55:56.024 INFO 8 --- [ntainer#0-0-C-1] c.s.n.f.a.s.impl.ConsumerServiceImpl : Time taken(ms) 56. No Of measures: 60
2019-03-27T15:25:56.21+0530 [APP/PROC/WEB/2] OUT 2019-03-27 09:55:56.210 INFO 8 --- [ntainer#0-0-C-1] c.s.n.f.a.s.impl.ConsumerServiceImpl : Time taken(ms) 80. No Of measures: …Run Code Online (Sandbox Code Playgroud) 我有一个普通 bean,它是 (a)@Scope("request")或 (b) 放置在一个HttpServletRequestvia 过滤器/拦截器中。
如何在@Service一种应用程序范围的单例中访问这个 bean ?
这样做的原因是,因为我有一个RequestContext带有一些请求元数据的自定义对象(主要是来自自定义 httpHeaders 的信息)。要知道,我将此对象作为参数传递给每个服务的每个方法,这是很多样板代码。
ruby ×3
spring-boot ×3
java ×2
spring ×2
apache-kafka ×1
azure ×1
azure-cli ×1
azure-cli2 ×1
azure-devops ×1
format ×1
grouping ×1
identity ×1
java-8 ×1
java-stream ×1
spring-bean ×1
spring-kafka ×1
spring-mvc ×1
string ×1