public class FreeMarkerView extends AbstractUrlBasedView
View
実装。 アプリケーションコンテキストでアクセス可能な FreeMarkerConfigurer
などの単一の FreeMarkerConfig
オブジェクトに依存します。または、FreeMarker Configuration
は、setConfiguration(freemarker.template.Configuration)
を介してこのクラスに直接設定できます。
url
プロパティは、FreeMarkerConfigurer の templateLoaderPath
に対する FreeMarker テンプレートの位置です。
メモ: Spring の FreeMarker サポートには FreeMarker 2.3 以上が必要です。
修飾子と型 | フィールドと説明 |
---|---|
static StringSE | SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE テンプレートモデルの RequestContext インスタンスの属性名。Spring のマクロで使用可能 — たとえば、BindStatus オブジェクトの作成用。 |
logger, REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
BINDING_CONTEXT_ATTRIBUTE
コンストラクターと説明 |
---|
FreeMarkerView() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterPropertiesSet() |
protected FreeMarkerConfig | autodetectConfiguration() ApplicationContext で FreeMarkerConfig オブジェクトを自動検出します。 |
boolean | checkResourceExists(LocaleSE locale) このビューに使用される FreeMarker テンプレートが存在し、有効であることを確認してください。 |
protected freemarker.template.Configuration | getConfiguration() このビューで使用される FreeMarker Configuration を取得します。 |
protected StringSE | getEncoding() FreeMarker テンプレートのエンコードを取得します。 |
protected reactor.core.publisher.Mono<MapSE<StringSE, ObjectSE>> | getModelAttributes(MapSE<StringSE,?> model, ServerWebExchange exchange) Spring FreeMarker マクロで使用する RequestContext を潜在的に公開し、このメソッドの継承された実装に委譲することにより、レンダリングに使用するモデルを準備します。 |
protected freemarker.template.ObjectWrapper | getObjectWrapper() 設定された FreeMarker ObjectWrapper を取得します。指定されていない場合はデフォルトのラッパーを取得します。 |
protected freemarker.template.Template | getTemplate(LocaleSE locale) このビューでレンダリングされる、指定されたロケールの FreeMarker テンプレートを取得します。 |
protected freemarker.template.SimpleHash | getTemplateModel(MapSE<StringSE, ObjectSE> model, ServerWebExchange exchange) 指定されたモデルマップの FreeMarker テンプレートモデルを作成します。 |
protected freemarker.template.Configuration | obtainConfiguration() 実際の使用のために FreeMarker Configuration を取得します。 |
protected reactor.core.publisher.Mono<VoidSE> | renderInternal(MapSE<StringSE, ObjectSE> renderAttributes, MediaType contentType, ServerWebExchange exchange) ビューを実際にレンダリングするには、サブクラスでこのメソッドを実装する必要があります。 |
void | setConfiguration(freemarker.template.Configuration configuration) このビューで使用される FreeMarker Configuration を設定します。 |
void | setEncoding(StringSE encoding) FreeMarker テンプレートファイルのエンコーディングを設定します。 |
void | setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) "springMacroRequestContext" という名前で、Spring のマクロライブラリが使用する RequestContext を公開するかどうかを設定します。 |
getUrl, setUrl, toString
createRequestContext, formatViewName, getApplicationContext, getBeanName, getDefaultCharset, getRequestContextAttribute, getRequestDataValueProcessor, getSupportedMediaTypes, obtainApplicationContext, render, resolveAsyncAttributes, resolveAsyncAttributes, setApplicationContext, setBeanName, setDefaultCharset, setRequestContextAttribute, setSupportedMediaTypes
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
isRedirectView
public static final StringSE SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE
RequestContext
インスタンスの属性名。Spring のマクロで使用可能 — たとえば、BindStatus
オブジェクトの作成用。setExposeSpringMacroHelpers(boolean)
, 定数フィールド値 public void setConfiguration(@Nullable freemarker.template.Configuration configuration)
Configuration
を設定します。 通常、このプロパティは直接設定されません。代わりに、FreeMarker 構成を取得するために使用される Spring アプリケーションコンテキストで単一の FreeMarkerConfig
が期待されます。
@Nullable protected freemarker.template.Configuration getConfiguration()
Configuration
を取得します。protected freemarker.template.Configuration obtainConfiguration()
Configuration
を取得します。null
)IllegalStateExceptionSE
- Configuration
オブジェクトセットがない場合 getConfiguration()
public void setEncoding(@Nullable StringSE encoding)
デフォルトでは、FreeMarkerConfigurer
は FreeMarker 構成のデフォルトのエンコードを "UTF-8" に設定します。すべてのテンプレートが共通のエンコーディングを共有している場合、テンプレートごとではなく、FreeMarker Configuration
でエンコーディングを指定することをお勧めします。
public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers)
RequestContext
を公開するかどうかを設定します。 デフォルトは true
です。
Spring の FreeMarker のデフォルトマクロに必要です。Spring ヘルパーマクロを利用する場合を除き、これは HTML フォームを使用するテンプレートには必要ないことに注意してください。
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE
public void afterPropertiesSet() throws ExceptionSE
InitializingBean
BeanFactoryAware
、ApplicationContextAware
などを満たした後、包含 BeanFactory
によって呼び出されます。このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。
InitializingBean
の afterPropertiesSet
AbstractUrlBasedView
の afterPropertiesSet
ExceptionSE
- 構成の誤り(必須プロパティの設定の失敗など)の場合、またはその他の理由で初期化が失敗した場合 protected FreeMarkerConfig autodetectConfiguration() throws BeansException
ApplicationContext
で FreeMarkerConfig
オブジェクトを自動検出します。FreeMarkerConfig
インスタンス BeansException
- FreeMarkerConfig
インスタンスが見つからなかった場合 setConfiguration(freemarker.template.Configuration)
public boolean checkResourceExists(LocaleSE locale) throws ExceptionSE
オーバーライドして動作をカスタマイズできます。たとえば、複数のテンプレートを単一のビューにレンダリングする場合などです。
AbstractUrlBasedView
の checkResourceExists
locale
- 探している希望のロケール false
、存在しないことがわかっている場合は false
ExceptionSE
- リソースは存在するが無効である場合 (たとえば解析できませんでした)protected reactor.core.publisher.Mono<MapSE<StringSE,ObjectSE>> getModelAttributes(@Nullable MapSE<StringSE,?> model, ServerWebExchange exchange)
RequestContext
を潜在的に公開し、このメソッドの継承された実装に委譲することにより、レンダリングに使用するモデルを準備します。AbstractView
の getModelAttributes
setExposeSpringMacroHelpers(boolean)
, AbstractView.getModelAttributes(Map, ServerWebExchange)
protected reactor.core.publisher.Mono<VoidSE> renderInternal(MapSE<StringSE,ObjectSE> renderAttributes, @Nullable MediaType contentType, ServerWebExchange exchange)
AbstractView
AbstractView
の renderInternal
renderAttributes
- 静的な属性よりも動的な値が優先される、結合された出力マップ(非 null
)contentType
- レンダリングするために選択されたコンテンツ型。サポートされているメディア型のいずれかと一致する必要があります exchange
- 現在の交換 Mono
protected freemarker.template.SimpleHash getTemplateModel(MapSE<StringSE,ObjectSE> model, ServerWebExchange exchange)
デフォルトの実装は SimpleHash
を構築します。
model
- レンダリングに使用するモデル exchange
- 現在の交換 SimpleHash
またはそのサブクラスとしての FreeMarker テンプレートモデル protected freemarker.template.ObjectWrapper getObjectWrapper()
ObjectWrapper
を取得します。指定されていない場合はデフォルトのラッパーを取得します。Configurable.getObjectWrapper()
protected freemarker.template.Template getTemplate(LocaleSE locale) throws IOExceptionSE
デフォルトでは、"url" Bean プロパティで指定されたテンプレートが取得されます。
locale
- 現在のロケール IOExceptionSE