@Min
and @Max
are used for validating numeric fields which could be String
(representing number), int
, short
, byte
etc and their respective primitive wrappers.
@Size
is used to check the length constraints on the fields.
As per documentation @Size
supports String
, Collection
, Map
and arrays
while @Min
and @Max
supports primitives and their wrappers. See the documentation.
手動(dòng)觸發(fā):
https://blog.csdn.net/justyman/article/details/89857577
如果是自動(dòng)觸發(fā)BUILD時(shí),則可以以最新建立的TAG為基礎(chǔ)進(jìn)行BUILD,而無(wú)需人手選TAG進(jìn)行BUILD。
配置,注意應(yīng)取消參數(shù)化配置工程:
- Add the following refspec to the Git plugin:
+refs/tags/*:refs/remotes/origin/tags/*
- Add the following branch specifier:
*/tags/*
- Enable SCM polling, so that the job detects new tags.
定義一個(gè)事件,因SPRING中可以有不同的事件,需要定義一個(gè)類以作區(qū)分:
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class JavaStackEvent extends ApplicationEvent {
/**
* Create a new {@code ApplicationEvent}.
*
* @param source the object on which the event initially occurred or with
* which the event is associated (never {@code null})
*/
public JavaStackEvent(Object source) {
super(source);
}
}
定義一個(gè)此事件觀察者,即感興趣者:
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
/**
* 觀察者:讀者粉絲
*/
@RequiredArgsConstructor
public class ReaderListener implements ApplicationListener<JavaStackEvent> {
@NonNull
private String name;
private String article;
@Async
@Override
public void onApplicationEvent(JavaStackEvent event) {
// 更新文章
updateArticle(event);
}
private void updateArticle(JavaStackEvent event) {
this.article = (String) event.getSource();
System.out.printf("我是讀者:%s,文章已更新為:%s\n", this.name, this.article);
}
}
注冊(cè)感興趣者(將自身注入SPRING容器則完成注冊(cè)),并制定發(fā)布機(jī)制(通過CONTEXT發(fā)布事件):
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Slf4j
@Configuration
public class ObserverConfiguration {
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext context) {
return (args) -> {
log.info("發(fā)布事件:什么是觀察者模式?");
context.publishEvent(new JavaStackEvent("什么是觀察者模式?"));
};
}
@Bean
public ReaderListener readerListener1(){
return new ReaderListener("小明");
}
@Bean
public ReaderListener readerListener2(){
return new ReaderListener("小張");
}
@Bean
public ReaderListener readerListener3(){
return new ReaderListener("小愛");
}
}
Excel 在讀取 csv 的時(shí)候是通過讀取文件頭上的 bom 來(lái)識(shí)別編碼的,這導(dǎo)致如果我們生成 csv 文件的平臺(tái)輸出無(wú) bom 頭編碼的 csv 文件(例如 utf-8 ,在標(biāo)準(zhǔn)中默認(rèn)是可以沒有 bom 頭的),Excel 只能自動(dòng)按照默認(rèn)編碼讀取,不一致就會(huì)出現(xiàn)亂碼問題了。
掌握了這點(diǎn)相信亂碼已經(jīng)無(wú)法阻擋我們前進(jìn)的步伐了:只需將不帶 bom 頭編碼的 csv 文件,用文本編輯器(工具隨意,推薦 notepad++ )打開并轉(zhuǎn)換為帶 bom 的編碼形式(具體編碼方式隨意),問題解決。
當(dāng)然,如果你是像我一樣的碼農(nóng)哥哥,在生成 csv 文件的時(shí)候?qū)懭?bom 頭更直接點(diǎn),用戶會(huì)感謝你的。
附錄:對(duì)于 utf-8 編碼,unicode 標(biāo)準(zhǔn)中是沒有 bom 定義的,微軟在自己的 utf-8 格式的文本文件之前加上了EF BB BF三個(gè)字節(jié)作為識(shí)別此編碼的 bom 頭,這也解釋了為啥大部分亂碼都是 utf-8 編碼導(dǎo)致的原因
SPRING BATCH中生成CSV文件時(shí)的解決方案:
new FlatFileItemWriterBuilder<T>()
.name(itemWriterName)
.resource(outputResource)
.lineAggregator(lineAggregator)
.headerCallback(
h -> {
System.out.println(header);
h.write('\uFEFF');//只需加這一行
h.write(header);
}
)
.build();
https://stackoverflow.com/questions/48952319/send-csv-file-encoded-in-utf-8-with-bom-in-java