WebX学习笔记2--项目基础文件配置

1. 利用maven命令创建一个webx的模板。

 mvn archetype:generate 
 -DgroupId=com.alibaba.webx3 
 -DartifactId=messageboard
 -Dversion=1.0-SNAPSHOT 
 -Dpackage=com.alibaba.webx3
 -DarchetypeArtifactId=archetype-webx-quickstart 
 -DarchetypeGroupId=com.alibaba.citrus.sample 
 -DarchetypeVersion=1.0 
 -DinteractiveMode=false

archetype是模板的意思,即该命令用于下载maven仓库中存在的模板。


mvn archetype:generate 生成一个工程
-DgroupId=com.alibaba.webx3 当前应用程序隶属的Group的ID,通常是公司所有应用程序的根目录,例如:com.alibaba
-DartifactId=message_board 项目名称,当前应用程序的ID
-Dversion=1.0-SNAPSHOT  项目的版本

-Dpackage=com.alibaba.webx3 项目中java类的包名[ 代码生成时使用的根包的名字,如果没有给出,默认使用archetypeGroupId ]


-DarchetypeArtifactId=archetype-webx-quickstart  项目模板的类型 [模板(archetype)ID ]

-DarchetypeGroupId=com.alibaba.citrus.sample  模板(archetype)的Group ID,

-DarchetypeVersion=1.0 模板的版本

-DinteractiveMode=false  不用进行交互的设置


2. 下载完后在项目目录下用mvn eclipse:eclipse可使下载的包变成eclipse项目,然后可以在eclipse中import进去。

import完后项目的目录结构是:


我们创建一个目录:message_board,用于保存子应用message_board的文件配置。

以下是建完后的目录结构:



包com.alibaba.webx3.messageboard就是留言板系统的代码包;

 

代码分为三个部分:module,service,dao

  1)由于webx前端使用的是turbine框架,所以创建module实现接受页面数据和渲染页面的作用;

  2)service主要负责业务逻辑的控制;

  3)dao主要负责数据的操作。

 

webapp/messageboard/templates用来存放页面的模板vm文件;

WEB-INF/messageboard/form.xml是表单验证的配置文件;

WEB-INF/webx-messageboard.xml是子应用的webx配置;


配置文件:

webx-messageboard.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Webx Sub Context Configuration.  -->
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:services="http://www.alibaba.com/schema/services"
    xmlns:ml-adapters="http://www.alibaba.com/schema/services/module-loader/adapters"
    xmlns:ml-factories="http://www.alibaba.com/schema/services/module-loader/factories"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
        http://www.alibaba.com/schema/services/module-loader/adapters http://localhost:8080/schema/services-module-loader-adapters.xsd
        http://www.alibaba.com/schema/services/module-loader/factories http://localhost:8080/schema/services-module-loader-factories.xsd
        http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
    ">

    <!-- 支持${xxx}替换。 -->  <img alt="" border="0" src="http://openwebx.org/docs/images/callouts/1.png" style="font-family: monospace; line-height: 25px; text-align: left; background-color: #ffffff; font-size: x-small; border-color: initial; border-color: initial; vertical-align: baseline;">
    <services:property-placeholder>
        <services:property key="component">messageBoard</services:property>
    </services:property-placeholder>

    <!-- 共享配置。 --> <img alt="" border="0" src="http://openwebx.org/docs/images/callouts/2.png" style="font-family: monospace; line-height: 25px; text-align: left; background-color: #ffffff; font-size: x-small; border-color: initial; border-color: initial; vertical-align: baseline;">
    <beans:import resource="common/webx-component-and-root.xml" />
    <beans:import resource="common/webx-component.xml" />

    <!-- 执行管道。 --> <img alt="" border="0" src="http://openwebx.org/docs/images/callouts/3.png" style="font-family: monospace; line-height: 25px; text-align: left; background-color: #ffffff; font-size: x-small; border-color: initial; border-color: initial; vertical-align: baseline;">
    <beans:import resource="common/pipeline.xml" />

    <!-- 表单验证。 --> <img alt="" border="0" src="http://openwebx.org/docs/images/callouts/4.png" style="font-family: monospace; line-height: 25px; text-align: left; background-color: #ffffff; font-size: x-small; border-color: initial; border-color: initial; vertical-align: baseline;">
    <beans:import resource="messageBoard/form.xml" />

    <!-- 装载模块。 --> <img alt="" border="0" src="http://openwebx.org/docs/images/callouts/1.png" style="font-family: monospace; line-height: 25px; text-align: left; background-color: #ffffff; font-size: x-small; border-color: initial; border-color: initial;"><img alt="" border="0" src="http://openwebx.org/docs/images/callouts/1.png" style="font-family: monospace; line-height: 25px; text-align: left; background-color: #ffffff; font-size: x-small; border-color: initial; border-color: initial; vertical-align: baseline;">
    <services:module-loader>
        <ml-factories:class-modules>
            <ml-factories:search-packages type="$1" packages="com.alibaba.webx3.messageboard.module.*" />
        </ml-factories:class-modules>
    </services:module-loader>

</beans:beans>


form.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:services="http://www.alibaba.com/schema/services"
    xmlns:fm-conditions="http://www.alibaba.com/schema/services/form/conditions"
    xmlns:fm-validators="http://www.alibaba.com/schema/services/form/validators"
    xmlns="http://www.alibaba.com/schema/services/form/validators"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.alibaba.com/schema/services http://localhost:8080/schema/services.xsd
        http://www.alibaba.com/schema/services/form/conditions http://localhost:8080/schema/services-form-conditions.xsd
        http://www.alibaba.com/schema/services/form/validators http://localhost:8080/schema/services-form-validators.xsd
        http://www.springframework.org/schema/beans http://localhost:8080/schema/www.springframework.org/schema/beans/spring-beans.xsd
    ">

    <services:form postOnlyByDefault="true">
        <!--
          - ===============================================
          - 用来检查csrf token。
          - ===============================================
         -->
        <services:group name="csrfCheck">
            <services:field name="csrfToken">
                <csrf-validator>
                    <message>提交的数据已过期</message>
                </csrf-validator>
            </services:field>
        </services:group>
        <!--
          - ===============================================
          - login form
          - ===============================================
         -->
        <services:group name="login" extends="csrfCheck">
            <services:field name="username" displayName="你的名字">
                <required-validator>
                    <message>必须填写 ${displayName}</message>
                </required-validator>
            </services:field>
            <services:field name="password" displayName="你的密码">
                <required-validator>
                    <message>必须填写 ${displayName}</message>
                </required-validator>
            </services:field>
        </services:group>
        <!--
          - ===============================================
          - register form
          - ===============================================
         -->
        <services:group name="register" extends="csrfCheck">
        
            <services:field name="username" displayName="你的名字">
                <required-validator>
                    <message>必须填写 ${displayName}</message>
                </required-validator>
            </services:field>
            
            <services:field name="password" displayName="你的密码">
                <required-validator>
                    <message>必须填写 ${displayName}</message>
                </required-validator>
            </services:field>
            
            <services:field name="repassword" displayName="确认密码">
                <required-validator >
                	<message>必须填写 ${displayName}</message>
                </required-validator>
                <string-compare-validator equalTo="password" >
               		<message>两次密码不一致 </message>
                </string-compare-validator>
            </services:field>
            
        </services:group>
        
        
    </services:form>

</beans:beans>

webx.xml

    ......

    <!-- 资源装载。 -->
    <beans:import resource="common/resources.xml" />

    <!-- URI生成。 -->
    <beans:import resource="common/uris.xml" />

   <span style="color: #ff6600;"> <!-- 综合设置。 --> 
    <services:webx-configuration>
        <!-- 默认将productionMode设为true,建议在jetty插件中设置-DproductionMode=false。 -->
        <services:productionMode>${productionMode:true}</services:productionMode>
     <!-- <services:components defaultComponent="app1" />   -->   
        <services:components defaultComponent="messageboard" />  
    </services:webx-configuration></span>

     ......



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值