velocity 巨集 macro 出現中文亂碼

2021-08-10 07:53:27 字數 646 閱讀 6545

最開始使用velocity時,輸出中文亂碼,我的解決辦法 是在呼叫 mergetemplate 方法時指定encoding為utf-8,然後就正常了。

velocity.mergetemplate(string templatename, string encoding, context

context, writer writer)

然而最近在使用velocity寫模板時發現巨集(#macro)中如果有中文,就會輸出亂碼(之前一直沒有在macro中使用過中文)。巨集之外的中文都能正常輸出。

google搜尋了一下,發現要徹底解決中文亂問題,還要設定input.encoding屬性才行,如下:

properties vprops = new properties();

vprops.put(velocity.input_encoding,"utf-8");

vprops.put(velocity.output_encoding,"utf-8");// output_encoding可以不設,因為我在呼叫mergetemplate方法時已經指定了 encoding 為utf-8

velocity.init(vprops);

巨集 macro 定義與使用

巨集的定義 巨集的替換與 展開 巨集的替換產生的問題 獲取巨集引數名稱 巨集引數的結合 巨集的取消 巨集定義的換行連線 標準預處理巨集 巨集 macro 是基於 define所實現的另一種預處理功能。與基本的 define定義的是常量相比,巨集 macro 允許多個引數化替換,引數中可以是固定的字串...

巨集 macro 定義的簡介

1.1巨集的簡單使用說明 define square x x x 下面我們就來用一下這個巨集 printf result d n square 5 無可厚非,結果就是5 5 25 int a 5 printf result1 d n square a 1 第一眼可能會脫口而出36,但是你文字替換一下...

gdb 除錯巨集定義macro

c語言中的巨集定義,有著各種好處,當然也有它不好的一面。它實現的三個主要功能是 1 字串替換 2 標頭檔案包含 3 通用 模組的擴充套件 在 除錯時候,除錯巨集定義是比較麻煩的一件事,下面就介紹一種比較簡單的方法。include define max a,b a b a b define min a...