2024年9月11日 星期三

做 Hibernate envers 設定時遇到的坑

這篇算是延續先前《SpringBoot 使用多個資料庫連線》的狀況

我今天想要使用Hibernate envers來處理資料的版控。

原先我是這樣處理的:

  1. pom.xml 加上library

    <dependency>
    	<groupId>org.hibernate</groupId>
    	<artifactId>hibernate-envers</artifactId>
    </dependency>
  2. application.properties 加上設定

    spring.jpa.properties.hibernate.envers.audit_table_suffix=_rev
    spring.jpa.properties.hibernate.envers.revision_field_name=rev
    spring.jpa.properties.hibernate.envers.revision_type_field_name=revtype
    
  3. Hibernate Entity 加上 @Audit
    import javax.persistence.Entity;
    import javax.persistence.Table;
    
    import org.hibernate.envers.Audited;
    
    @Entity
    @Audit
    @Table(name = "my_entity")
    class MyEntity{
    	// 中略
    }

然而,實際執行時,Hibernate 處理版控資料時,都想要存入 my_entity_AUD,即

insert into `my_entity_AUD` 
# 下略

2024年8月16日 星期五

以數字開頭的 class element

如果 HTML code 如下

<span>Hello</span>&nbsp;
<span class="123">John Smith</span>

而 CSS 寫成如下,是無法作用的

.123{
	font-weight: bold;
	color: CornflowerBlue;
}

2024年8月12日 星期一

Logback 設定

最近在調整自己開發的系統的 log。程式使用 Spring Boot,log 使用 logback。

我的目的是要讓其 log 到一定量就自動壓縮成 .gz檔、每天壓縮。

2024年7月19日 星期五

OAuth 2.0 的 PKCE 筆記

PKCE 詳細規格請參閱 RFC7636

我在撰寫 OAuth 2.0 的登入時,會遇到 code_verifiercode_challenge 一直對不起來的狀況。

舉例來說,我請求 token 的參數為

client_id=aaa&
client_secret=bbb&
code=thisisasimpletoken&
code_verifier=HelloWorld&
grant_type=authorization_code

按照規範,我取得 authorization code 的 request 應該是 

client_id=aaa&
response_type=code&
scope=User.Read.All&
response_mode=form_post&
code_challenge_method=S256&
code_challenge=<將“HelloWorld”以 S256 加密後的字串>

2024年6月7日 星期五

SVG 文字置中

首先是個普通的 SVG:

Hi! quick fox
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 200" width="300">
	<g fill="none" stroke="rgba(22, 22, 22, 0.5)">
		<path d="M 90 90 L 110 110 Z"/>
		<path d="M 110 90 L 90 110 Z"/>
	</g>
	<text font-family="Arial, sans-serif" x="100" y="100" font-size="30">Hi! quick fox</text>
</svg>

為了方便辨識,在 (100, 100) 的位置打了個叉。



上面的 SVG 可以看出來,文字無論是 x 軸還是 y 軸都沒有置中。

2024年5月29日 星期三

Microsoft Email SMTP 設定

不知為何還蠻難找到 MS 365 的 SMTP 設定,在此紀錄

host outlook-apaccentral.office365.com
port 587
protocol smtp
username 你的 Outlook mail,例如 john.smith@live.com
password Outlook 密碼
from username


另外,我是使用 Java + spring, spring 有兩個參數不確定是在其他程式語言對應的數值,所以在這邊先列一下:

spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true

2024年5月8日 星期三

multipart Email 的 Content-Disposition 差異

如果我今天要寄一封 E-Mail,內文要有圖片,那整封信的內容可能如下:

Subject: This is a test mail!
From: test@example.com
Content-Type: multipart/mixed; boundary="qwertyuio"

--qwertyuio
Content-Type: text/html; name="example.html"

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8"/>
		<title>Example</title>
	</head>
	<body>
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
		<img alt="" src="cid:28ce9652-4476-4e3c-8e9a-5d1bbae4cd05" />
	</body>
</html>

--qwertyuio
Content-Type: image/jpeg; name="example.jpg"
Content-Disposition: attachment; filename="example.jpg"
Content-ID: 28ce9652-4476-4e3c-8e9a-5d1bbae4cd05

<image content>

--qwertyuio--