私たちは、Freemakerは静的テストを達成祭のウェブサイト上にあった、そして今、私たちは、プロジェクトのアプリケーションで実現しています。
前のセクションを参照してください:
Freemarkerのは、静的なページ(A)を達成
オリジナルリンク:https://blog.csdn.net/qq_36335126/article/details/103881330
- 商品の詳細の静的なページ
2.1静的スキームページ
製品ID +「HTML。」:出力ファイルの名前
出力ファイルのパス:プロジェクト外部の任意のディレクトリ。
Webアクセス:nginxのWebアクセスを使用して。このシナリオでのみTomcatの役割は、静的なページを生成することです。
プロジェクトの展開:E3-アイテムウェブことができ、複数のサーバー上に展開します。
とき静的なページを生成します:静的なページを生成するために商品を追加した後。あなたは、トピックをサブスクライブ、ActiveMQのを使用することができます(アイテムが追加します)
静的アーキテクチャ図:
2.2。FreeMarkerのテンプレートJSPの変換
次のJSP FTLフォルダにフォルダのコピーがすべての内容、およびその代わりエンディングに.ftl .jspという接尾辞:テンプレートを作成します。代わりFTLの対応する構文内部JSP対応するオリジナルコンテンツ。
次のような対応する変更のFTLの構文は、導入していません。
JSP削除は、直接、値をデジタル形式にフォーマット。
代わりFTL構文の配列をforeachループ。
2.3。実現するMessageListener
依存するJARパッケージを追加するためにPOMファイル:
Documentsディレクトリ構造:
MessageListenerのクラス
@Override
public void onMessage(Message message) {
try {
TextMessage textMessage = null;
Long itemId = null;
// 取商品id
if (message instanceof TextMessage) {
textMessage = (TextMessage) message;
itemId = Long.parseLong(textMessage.getText());
// 等待事务提交
Thread.sleep(1000);
//取Item内容
TbItem tbItem = itemService.getItemById(itemId);
//对图片的处理用我们新创建的pojo
Item item = new Item(tbItem);
//取商品描述
TbItemDesc itemDesc = itemService.getItemDescById(itemId);
//创建一个Configuration对象。
Configuration configuration = freeMarkerConfigurer.getConfiguration();
//加载一个模板,创建一个模板对象。
Template template = configuration.getTemplate("item.ftl");
//创建一个模板使用的数据集,可以是pojo也可以是map。一般是Map。
Map dataModel = new HashMap<>();
//向数据集中添加数据
dataModel.put("item", item);
dataModel.put("itemDesc", itemDesc);
//创建一个输出流,指定输出的目录及文件名。
Writer out = new FileWriter(HTML_GEN_PATH + itemId + ".html");
//调用模板对象的process方法输出文件。
template.process(dataModel, out);
//第八步:关闭流。
out.close();
}
} catch (Exception e) {
// TODO: handle exception
}
2.4。MessageListenerのモニターの設定項目は、メッセージを追加します
resource.p ropertiesのファイル構成
のApplicationContext-activemq.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd ">
<!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供 -->
<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://192.168.25.131:61616" />
</bean>
<!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->
<bean id="connectionFactory"
class="org.springframework.jms.connection.SingleConnectionFactory">
<!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->
<property name="targetConnectionFactory" ref="targetConnectionFactory" />
</bean>
<!--这个是主题目的地,一对多的 -->
<bean id="topicDestination" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="item-change-topic" />
</bean>
<!-- 接收消息 -->
<!-- 配置监听器 -->
<bean id="htmlGenListener" class="cn.e3mall.item.listener.HtmlGenListener" />
<!-- 消息监听容器 -->
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="topicDestination" />
<property name="messageListener" ref="htmlGenListener" />
</bean>
</beans>
* サーブレット開始web.xmlファイルを変更するための設定ファイルをロードします
2.5。テストの静的なページ
、プログラムを実行して商品管理ページを追加し、テストが成功であることを示す、ディレクトリ内のitemId .htmlファイルを生成した対応を表示します。
2.6。プロジェクトへの静的なページを展開。
(私たちは便利なのnginxのテストWindows版です)
(指定したディレクトリに窓直接nginx-1.8.0.zipエキスのnginxのバージョンをインストールします。ディレクトリは、中国を含めることはできません実行するために)オープン。
nginxの起動モードおよびLinux版、それについて多くの話がありません。
Nginx.conf設定(ディレクトリ変更)
コンフィギュレーションをリロードします。
HTTPの方法を介した静的ファイル:
対応するCSS、画像、jsはEにフォルダ:\ TEMP \ FreeMarkerの\完全な静的なページを生成することができます(ルートディレクトリ)。
表示効果:
その後、動的に変更生成された元のURL 生成されたURL nginxのでは、静的なファイルを達成することができます。