小编Sir*_*its的帖子

Postgres中的Generate_series从表中的开始和结束日期开始

我一直在尝试从时间戳字段中的第一个日期到最后一个日期生成一系列日期(YYYY-MM-DD HH).我有generate_series()我需要的东西,但是在尝试从表中获取开始和结束日期时遇到了问题.我有以下几点给出一个粗略的想法:

with date1 as
(
SELECT start_timestamp as first_date
FROM header_table
ORDER BY start_timestamp DESC
LIMIT 1
),
date2 as
(
SELECT start_timestamp as first_date
FROM header_table
ORDER BY start_timestamp ASC    
LIMIT 1
)
    select generate_series(date1.first_date, date2.first_date
                         , '1 hour'::interval)::timestamp as date_hour

from
(   select * from date1
    union
    select * from date2) as foo
Run Code Online (Sandbox Code Playgroud)

Postgres 9.3

sql postgresql aggregate-functions generate-series

7
推荐指数
2
解决办法
2万
查看次数

在Thymeleaf中动态创建的消息参考?

所以我有以下代码:

 <h3 th:if="#{${'footer.message.' + receiptProperties.url}? : '(NOTHING)'}"  th:utext="#{${'footer.message.' + receiptProperties.url}}"></h3>
Run Code Online (Sandbox Code Playgroud)

acceptingProperties.url =给租户的名称,例如ABC,DEF等。因此messages.properties文件中的密钥将类似于footer.message.ABC = Hello ABC!

动态创建的消息密钥正确显示,但是,如果属性文件中不存在诸如footer.message.GHI之类的密钥,则页面上将显示以下内容,而不是根本不显示任何内容:?footer.message .GHI_en ??

Thymeleaf中有什么方法可以准确检查属性文件中是否存在动态创建的密钥?

thymeleaf

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

Spring Boot - 在应用程序启动期间/之前运行代码的正确方法?

对于启动时在 Spring Boot Web 应用程序中实现逻辑似乎存在不同意见。但对于“最佳实践”或优于其他方法的首选方式没有达成共识等。

我有以下代码在启动时实现 ApplicationRunner 接口(带有一些虚拟输出):

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AppStartupRunner implements ApplicationRunner {

    public static int counter;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("Application started with option names : {}",
                args.getOptionNames());
        log.info("Increment counter");
        counter++;
    }
}
Run Code Online (Sandbox Code Playgroud)

这种方法是否被认为是“正确的”(因为缺乏更好的术语)?我的目的是运行一些代码来在启动时从数据库获取值,使用 Ehcache 和其他一些“初始化”位将它们存储在其中。

这看起来很黑客,所以不确定是否有更干净或更合适的方法来解决这个问题。

java spring spring-mvc spring-boot

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

直接在列中添加换行符或回车符到Postgres中的分隔符值

我有以下查询:

SELECT id,
concat_ws(', ',
            case when isBlue then 'Blue' end,
            case when isMale then 'Male' end,
            case when isAdult then 'Adult' end) as Person1,
concat_ws(', ',
            case when isBrown then 'Brown' end,
            case when isFemale then 'Female' end,
            case when isAdult then 'Adult' end) as Person2          
from misc_table  
where id <> NULL 
order by id
Run Code Online (Sandbox Code Playgroud)

哪个会输出以下内容

| id | Person1             | Person2
----------------------------------------------
| 1  | Blue, Male, Adult   | Brown, Female, Adult
----------------------------------------------
| 2  | Blue, Male, …
Run Code Online (Sandbox Code Playgroud)

sql string postgresql

4
推荐指数
2
解决办法
5158
查看次数