<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>licream&#039;s blog &#187; 网络相关</title>
	<atom:link href="http://www.licream.net/category/wp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.licream.net</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 02:46:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>解析xpo生成xml文件</title>
		<link>http://www.licream.net/convert_to_xml.html/</link>
		<comments>http://www.licream.net/convert_to_xml.html/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 02:24:12 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[dom4j]]></category>

		<guid isPermaLink="false">http://www.licream.net/?p=563</guid>
		<description><![CDATA[最近在做一个跟项目有关的小工具,是将另一种(xpo)格式的文件转化成xml文件,头几天没点头绪,一直以为用正则表达式可以快速解决这些问题,经过尝试阿根本不行. &#8230;其实我对正则表达式也不懂.哈哈. 发一部分xpo文件的格式,细心的会发现,这格式还是很有规律的,这样.我们解析过程中遇到的问题会少些.我要得到的数据是#号前后的内容,及他的类型.并将它们写在xml文件里面&#8230; 在处理xml文件上,我选用dom4j.读取xpo文件用BufferedReader的readLine方法． Exportfile for AOT version 1.0 or later Formatversion: 1 ***Element: DBE ; Microsoft Business Solutions-Axapta Enumtype...]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.licream.net/wp-content/uploads/2010/09/dom4j_xml1.png" alt="" title="dom4j_xml" width="560" height="160" class="alignnone size-full wp-image-560" /><br />
最近在做一个跟项目有关的小工具,是将另一种(xpo)格式的文件转化成xml文件,头几天没点头绪,一直以为用正则表达式可以快速解决这些问题,经过尝试阿根本不行.  &#8230;其实我对正则表达式也不懂.哈哈.</p>
<p>发一部分xpo文件的格式,细心的会发现,这格式还是很有规律的,这样.我们解析过程中遇到的问题会少些.我要得到的数据是#号前后的内容,及他的类型.并将它们写在xml文件里面&#8230;<br />
在处理xml文件上,我选用dom4j.读取xpo文件用BufferedReader的readLine方法．<br />
<span id="more-563"></span></p>
<pre class="brush: css;">
Exportfile for AOT version 1.0 or later
Formatversion: 1

***Element: DBE

; Microsoft Business Solutions-Axapta Enumtype : ABC unloaded at Tuesday 2010-08-17
; --------------------------------------------------------------------------------
  ENUMTYPEVERSION 1

  ENUMTYPE #ABC
    PROPERTIES
      Name                #ABC
      Label               #@SYS69410
      Help                #
      DisplayLength       #Auto
      Style               #Combo box
      ConfigurationKey    #
      UseEnumValue        #No
    ENDPROPERTIES

    TYPEELEMENTS
      #None
      PROPERTIES
        Name                #None
        Label               #@SYS1369
        ConfigurationKey    #
        EnumValue           #0
      ENDPROPERTIES

      #A
      PROPERTIES
        Name                #A
        Label               #@SYS22523
        ConfigurationKey    #
        EnumValue           #1
      ENDPROPERTIES

      #B
      PROPERTIES
        Name                #B
        Label               #@SYS22524
        ConfigurationKey    #
        EnumValue           #2
      ENDPROPERTIES

      #C
      PROPERTIES
        Name                #C
        Label               #@SYS22525
        ConfigurationKey    #
        EnumValue           #3
      ENDPROPERTIES

    ENDTYPEELEMENTS
  ENDENUMTYPE

***Element: DBE

; Microsoft Business Solutions-Axapta Enumtype : ABCModel unloaded at Tuesday 2010-08-17
; --------------------------------------------------------------------------------
  ENUMTYPEVERSION 1

  ENUMTYPE #ABCModel
    PROPERTIES
      Name                #ABCModel
      Label               #@SYS23230
      Help                #@SYS23230
      DisplayLength       #Auto
      Style               #Combo box
      ConfigurationKey    #
      UseEnumValue        #No
    ENDPROPERTIES

    TYPEELEMENTS
      #Revenue
      PROPERTIES
        Name                #Revenue
        Label               #@SYS10074
        ConfigurationKey    #
        EnumValue           #0
      ENDPROPERTIES

      #ContributionMargin
      PROPERTIES
        Name                #ContributionMargin
        Label               #@SYS16226
        ConfigurationKey    #
        EnumValue           #1
      ENDPROPERTIES

      #Value
      PROPERTIES
        Name                #Value
        Label               #@SYS11762
        ConfigurationKey    #
        EnumValue           #2
      ENDPROPERTIES

      #Link
      PROPERTIES
        Name                #Link
        Label               #@SYS14545
        ConfigurationKey    #
        EnumValue           #3
      ENDPROPERTIES

    ENDTYPEELEMENTS
  ENDENUMTYPE
</pre>
<p>写的一个通用方法，定义Document ,SAXReader 用于读取xml文件,定义XMLWriter 写入xml文件</p>
<pre class="brush: java;">
public static Document getDocument(String filename)
			throws DocumentException, IOException, XmlPullParserException {
		Document document = null;
		Document doc = DocumentHelper.createDocument();
		SAXReader sa = new SAXReader();
		XPP3Reader xp = new XPP3Reader();

		document = sa.read(new File(filename));

		return document;
	}

public static boolean saveDocument(String filename, Document doc) {
		try {
			OutputFormat out = OutputFormat.createPrettyPrint();
			XMLWriter writer = new XMLWriter(new FileOutputStream(filename),
					out);
			writer.write(doc);
			writer.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}
</pre>
<p>filename是xml文件.用于传入文件路径和名称.<br />
Document doc = DocumentHelper.createDocument();注意这个,虽然没有用上.但实现这步,性能上有优化的效果,一位牛人是这么说的.我在使用时没感觉到.<br />
SAXReader ,XPP3Reader ,后者处理信息快些.但是我改成它时报xml文件格式不规律.只好放弃使用改SAXReader.<br />
如果你的xml文件有中文或以后添加有中文的信息,一定要用FileOutputStream来写入.否则报类型异常.</p>
<pre class="brush: java;">
public String extendsDataTypeToXml(String filexpo, String filexml,
			String type) throws DocumentException, IOException, XmlPullParserException {

		Document document = DocumentOperator.getDocument(filexml);

		Element getroot = document.getRootElement();
		Element node = null;

		BufferedReader reader = null;
		String tempString = null;

		try {
			Element elementtion = null;
			String itemtype = null;
			String basetype = null;
			// 指定解析文件
			reader = new BufferedReader(new FileReader(new File(filexpo)));
			// 按行读取,直到读到null...
			while ((tempString = reader.readLine()) != null) {

				String str = &quot;  &quot;;// 截取字段规则,这里是获取该值后面的字符串.
				// 判断份该变量值开始,并从变值+enumtype字符串开始.此行还要包含#字符串.

				// case 1
				if (tempString.trim().equals(&quot;&quot;)
						|| tempString.trim().equals(null))
					continue;
                                    //startsWith方法是从每行内指定的地方开始执行,contains是指包含什么字符串.
				if (tempString.startsWith(str)
						&amp;&amp; tempString.startsWith(str + type)
						&amp;&amp; tempString.contains(&quot;#&quot;)) {
					int i = 0;
					// 按下标提取字符串,通过substring方法截取需要的数据.

					String EnumName = tempString.substring(i, i + 10).trim();
					String EnumValue = tempString.substring(i + 12).trim();
					// basetype=tempString.substring(i);

					if (EnumName.equals(&quot;USERTYPE&quot;)) {
						EnumName = &quot;DataType&quot;;
					}
                                        //Element,添加节点,把截取到的数据添加到节点属性里.
					node = getroot.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
							EnumValue).addAttribute(&quot;type&quot;, EnumName)
							.addAttribute(&quot;id&quot;, &quot;1&quot;).addAttribute(&quot;basetype&quot;,
									&quot;&quot;);

					if (node.attribute(&quot;basetype&quot;).getValue().equals(&quot;QUEUE&quot;)) {
						node.getParent().remove(node);
					}

				}
				// case 2
				else if (tempString.startsWith(str)
						&amp;&amp; !tempString.contains(&quot;#&quot;)
						&amp;&amp; !tempString.startsWith(&quot;   &quot;)
						&amp;&amp; !tempString.contains(&quot;USERTYPEVERSION&quot;)
						&amp;&amp; !tempString.contains(&quot;ENDUSERTYPE&quot;)) {

					System.out.println(tempString);
					basetype = tempString.trim();
					System.out.println(basetype);
                                        //截取的属性,按自已的要求改名
					if (basetype.equals(&quot;STRING&quot;)) {
						basetype = &quot;String&quot;;
					} else if (basetype.equals(&quot;INT&quot;)) {
						basetype = &quot;Int&quot;;
					} else if (basetype.equals(&quot;DATE&quot;)) {
						basetype = &quot;Date&quot;;
					} else if (basetype.equals(&quot;TIME&quot;)) {
						basetype = &quot;Time&quot;;
					} else if (basetype.equals(&quot;REAL&quot;)) {
						basetype = &quot;Double&quot;;
					} else if (basetype.equals(&quot;ENUM&quot;)) {
						basetype = &quot;Enum&quot;;
					} else if (basetype.equals(&quot;QUEUE&quot;)) {
						basetype = &quot;QUEUE&quot;;

					}
                                        //重新给该属性赋新的值.
					node.attribute(&quot;basetype&quot;).setValue(basetype);
					if (node.attribute(&quot;basetype&quot;).getValue().equals(&quot;QUEUE&quot;)) {
						node.getParent().remove(node);
					}

					System.out.println(node.asXML());
				} else if (tempString.trim().startsWith(&quot;TYPEREFERENCETYPE&quot;)) {
					int i = 0;
					int nodeid = 0;
					++nodeid;
					String dataParentName = tempString.substring(i).trim();

					if (dataParentName.equals(&quot;TYPEREFERENCETYPE&quot;)) {
						dataParentName = &quot;DataTypeRelationItem&quot;;

					}
					itemtype = tempString.substring(i).trim();
					if (itemtype.equals(&quot;TYPEREFERENCETYPE DATASET&quot;)) {
						itemtype = &quot;tablefield&quot;;
					} else if (itemtype.equals(&quot;TYPEREFERENCETYPE EXTERNFIXED&quot;)) {
						itemtype = &quot;fixedvalue&quot;;
					}

					Element reltion = node.addElement(&quot;node&quot;).addAttribute(
							&quot;name&quot;, &quot;Relation&quot;).addAttribute(&quot;type&quot;,
							&quot;DataTypeRelation&quot;);

					String name = node.attribute(&quot;name&quot;).getValue();
					// String
					// childrentablevalue=nodechildren.attribute(&quot;value&quot;).getValue();

					elementtion = reltion.addElement(&quot;node&quot;).addAttribute(
							&quot;name&quot;, &quot;&quot;).addAttribute(&quot;id&quot;,
							new Integer(nodeid).toString()).addAttribute(
							&quot;type&quot;, &quot;DataTypeRelationItem&quot;).addAttribute(
							&quot;relationtype&quot;, itemtype);
					System.out.println(node.asXML());

				}

			}

			reader.close();
			return &quot;成功&quot;;

		} catch (IOException e) {
			e.printStackTrace();
			return e.toString();
		} finally {

			if (reader != null) {
				DocumentOperator.saveDocument(filexml, document);
			}

		}

	}
</pre>
<p>上面这段代码有些雍容,管它呢先实现功能就很不错了,呵呵.这方法实现起来并不是最麻烦,在开发过程中.下面那方法才是我碰到最郁闷的&#8230;.同时也认为是该小项目中最麻烦的地方.</p>
<p>原因:上面那方法转换之后.数据并不是很完美的,还需要处理,删除多余的信息,下面就是为该功能做出了贡献- -.</p>
<pre class="brush: java;">
public String DeleteNode(String filexml) throws DocumentException,
			IOException, XmlPullParserException {

		Document document = DocumentOperator.getDocument(filexml);

		Element getroot = document.getRootElement();
               //在删除过程中.会删掉最后那个父节点root.所以新建一个root结尾的节点.
		Document docNew = DocumentHelper.parseText(&quot;&lt;root /&gt;&quot;);
		Element rootNew = docNew.getRootElement();// 定义一个新的root节点,并获取它.
		Element result;

		result = rootNew;
		for (Iterator iterator = getroot.elementIterator(); iterator.hasNext();) {
			Element ele = (Element) iterator.next();

			Element eleProperties = ele.element(&quot;node&quot;);

			if (eleProperties.attributeValue(&quot;name&quot;).equals(&quot;Name&quot;)) {
				result = eleProperties.getParent();

				if (result != rootNew)
					rootNew.add(result.detach());  //把多余的删余后,留下的信息添加到有用的节点里,这需要用detach分离
				// System.out.println(rootNew.asXML());

			} else {

				result.add(eleProperties.detach());//还是分离...

			}

		}

		DocumentOperator.saveDocument(filexml, rootNew);
		return rootNew.asXML();

	}
</pre>
<p>个人认为,这方法的难点在于新建节点上没有想到..及之类没用过detach方法.不知道他具体是什么功能.,开始用createCopy方法可以使现.但还不是最完美的..<br />
detach:用于将节点分离,并会自动删除原有的节点及父节点.(分离后不在原父节点里情况下.)<br />
createCopy:将需要的节点信息复制一份到目标节点里.并保留原有信息.</p>
<p>xml文件生成好了之后,还需要为他们的ID值配对.这样,访问就有关联数据了,方法很简单.不多解释了&#8230;.</p>
<pre class="brush: java;">
public String UpdateTreeFieldId(String filexml, int number) {

		try {
			Document doc = DocumentOperator.getDocument(filexml);
                        // 这里使用了Xpath(不知是不是这么叫),直接指定节点位置
			List&lt;Node&gt; list = doc.selectNodes(&quot;root/node/node/node&quot;);
			if (number &lt; 0) {
				return &quot;&quot;;
			}//number传入ID值.并通过递增写入xml文件
			int id = number;
			for (Iterator it = list.listIterator(); it.hasNext();) {

				Element ele = (Element) it.next();
				if (ele.attributeValue(&quot;type&quot;).equals(&quot;Field&quot;)) {

					ele.attribute(&quot;id&quot;).setValue(new Integer(++id).toString());

				}

			}

			DocumentOperator.saveDocument(filexml, doc);
		} catch (Exception e) {
		}

		return &quot;&quot;;
	}
</pre>
<p>完整代码太多了.把主要功能分享出来.小小的变动还是看自已的条件去变动.<br />
通过个小项目的锻练,对dom4j熟悉程度又进一步加深了.哈哈</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/convert_to_xml.html/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>删除xml指定的节点信息</title>
		<link>http://www.licream.net/deletexmlelement.html/</link>
		<comments>http://www.licream.net/deletexmlelement.html/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 06:44:03 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.licream.net/?p=558</guid>
		<description><![CDATA[之前做了更新功能，必然就有删除功能哈，实现起来非常简单，跟更新差不多．只是调用的方法不一样而已 还是一样先读取文件 document = sa.read(new File(tablePath)); 获得父节点信息我们下一下要通过父节点来删除子节点的信息． Element root = document.getRootElement(); 指定要删除的节点ＩＤ，ＩＤ值通过前台传值． Element element = (Element) document.selectSingleNode("/root/node[@id='" + id +...]]></description>
			<content:encoded><![CDATA[<p>之前做了更新功能，必然就有删除功能哈，实现起来非常简单，跟更新差不多．只是调用的方法不一样而已</p>
<p>还是一样先读取文件<code><br />
document = sa.read(new File(tablePath));<br />
</code><br />
 获得父节点信息我们下一下要通过父节点来删除子节点的信息．<br />
<code><br />
 Element root = document.getRootElement();<br />
</code><br />
指定要删除的节点ＩＤ，ＩＤ值通过前台传值．<br />
<code><br />
 Element element = (Element) document.selectSingleNode("/root/node[@id='" + id + "']");<br />
</code><br />
最后就是再此写入数据更新一下．．．呵呵<br />
<code><br />
OutputFormat format = OutputFormat.createPrettyPrint();<br />
 XMLWriter writer = new XMLWriter(new FileOutputStream(tablePath),format);<br />
            writer.write(document);<br />
            writer.close();<br />
            return element.asXML();<br />
</code><br />
是不是很简单哈，就这么点代码就完成了，指定详细删除的节点，还不需要遍历．省代码又省内存．是不是呢．</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/deletexmlelement.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>通过右键添加tree节点,并写入到数据到xml文件</title>
		<link>http://www.licream.net/flexwriter_tree_xml.html/</link>
		<comments>http://www.licream.net/flexwriter_tree_xml.html/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 09:10:33 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.licream.net/?p=556</guid>
		<description><![CDATA[昨天到现在.一直在折腾那个右键菜单来创建一个节点问题,可谓几经波折现在终于给搞定了,这把我鸡动的得先贴出来给大家分享下,也供自已以后备用复习用用:). 1.定义右键菜单功能 //定义右键菜单项 private function addContextMenuTables():void{ var t_tables:ContextMenu=new ContextMenu(); var M_openNewWindow:ContextMenuItem = new ContextMenuItem("Open New Windows"); var M_Tables:ContextMenuItem = new...]]></description>
			<content:encoded><![CDATA[<p>昨天到现在.一直在折腾那个右键菜单来创建一个节点问题,可谓几经波折现在终于给搞定了,这把我鸡动的得先贴出来给大家分享下,也供自已以后备用复习用用:). <img src='http://www.licream.net/wp-includes/images/smilies/icon_cool.gif' alt=':cool:' class='wp-smiley' />  </p>
<p>1.定义右键菜单功能<span id="more-556"></span><br />
<code><br />
//定义右键菜单项<br />
private function addContextMenuTables():void{<br />
				var t_tables:ContextMenu=new ContextMenu();<br />
				var M_openNewWindow:ContextMenuItem = new ContextMenuItem("Open New Windows");<br />
				var M_Tables:ContextMenuItem = new ContextMenuItem("New Table");<br />
				var M_Export:ContextMenuItem=new ContextMenuItem("Export");<br />
				var M_Compile:ContextMenuItem=new ContextMenuItem("Compile");<br />
				var M_Find:ContextMenuItem=new ContextMenuItem("Find");<br />
				var M_Addins:ContextMenuItem=new ContextMenuItem('Add-ins');<br />
				var M_Refresh:ContextMenuItem=new ContextMenuItem("Refresh");<br />
				//new Table的事件,newTableEvent是事件的方法<br />
				M_Tables.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,newTableEvent);<br />
				t_tables.customItems.push(M_Tables);<br />
				t_tables.customItems.push(M_openNewWindow);<br />
				t_tables.customItems.push(M_Export);<br />
				t_tables.customItems.push(M_Compile);<br />
				t_tables.customItems.push(M_Find);<br />
				t_tables.customItems.push(M_Addins);<br />
				t_tables.customItems.push(M_Refresh);<br />
				t_tables.hideBuiltInItems();<br />
				tree.contextMenu=t_tables;<br />
			}</p>
<p>//newTable事件的方法<br />
private function newTableEvent(event:Event):void<br />
			{</p>
<p>			try{<br />
                                //该DialogTextInput是一个组件文件.通过addElement方法打开该组件.<br />
				var dialogTextInput:DialogTextInput = new DialogTextInput();<br />
					this.addElement(dialogTextInput);</p>
<p>			}catch(e:Error){<br />
				Alert.show(e.message);<br />
			}<br />
			}<br />
</code><br />
//调用java远程的方法,createTableXmlFile()该方法是创建一个new Table.参数为table名称.<br />
<code><br />
public function newTableOK(tablename:String):void<br />
			{<br />
				addTableXml.createTableXMLFile(tablename);<br />
			}</p>
<p></code><br />
CreateTableXmlFile方法代码.<br />
<code><br />
public String createTableXMLFile(String tablename) throws DocumentException {<br />
		Document document = null;<br />
		SAXReader reader = new SAXReader();<br />
		String xmlpath = "E:\\EclipseProject\\ReadXml\\dataxml\\Tables.xml";</p>
<p>		document = reader.read(new File(xmlpath));</p>
<p>		Element getroot = document.getRootElement();</p>
<p>		GetId getId = new GetId();</p>
<p>		/** 建立document对象 */<br />
		// document = DocumentHelper.createDocument();</p>
<p>		/** 加入第一个node节点 */<br />
		Element nodeElement = getroot.addElement("node");</p>
<p>		if (tablename == "") {<br />
			return "-1";<br />
		} else {<br />
			nodeElement.addAttribute("name", tablename).addAttribute("type",<br />
					"Table").addAttribute("id", getId.getId());</p>
<p>			/** 添加node子节点fields */<br />
			Element fields = nodeElement.addElement("node").addAttribute(<br />
					"name", "Fields").addAttribute("type", "Fields")<br />
					.addAttribute("id", "1");<br />
			fields.addAttribute("name", "Fields")<br />
					.addAttribute("type", "Fields").addAttribute("id", "2");<br />
			Element itemid = fields.addElement("node").addAttribute("name",<br />
					"ItemId").addAttribute("type", "Field").addAttribute("id",<br />
					"3");<br />
			Element itemName = fields.addElement("node").addAttribute("name",<br />
					"ItemName").addAttribute("type", "Field").addAttribute(<br />
					"id", "4");<br />
			Element itemGroup = fields.addElement("node").addAttribute("name",<br />
					"ItemGroup").addAttribute("type", "Field").addAttribute(<br />
					"id", "5");</p>
<p>			/** 添加node子节点FieldGroup */<br />
			Element fieldsGroups = nodeElement.addElement("node").addAttribute(<br />
					"name", "FieldGroups").addAttribute("type", "FieldGroups")<br />
					.addAttribute("id", "6");<br />
			fieldsGroups.addAttribute("name", "Fields").addAttribute("type",<br />
					"Fields").addAttribute("id", "6");<br />
			Element autoReport = fieldsGroups.addElement("node").addAttribute(<br />
					"name", "AutoReport").addAttribute("type", "FieldGroup")<br />
					.addAttribute("id", "7");<br />
			Element itemidReport = autoReport.addElement("node").addAttribute(<br />
					"name", "ItemId").addAttribute("type", "FieldGroupItem")<br />
					.addAttribute("id", "8");<br />
			Element itemNameReport = autoReport.addElement("node")<br />
					.addAttribute("name", "ItemName").addAttribute("type",<br />
							"FieldGroupItem").addAttribute("id", "9");<br />
			Element itemGroupReport = autoReport.addElement("node")<br />
					.addAttribute("name", "ItemGroup").addAttribute("type",<br />
							"FieldGroupItem").addAttribute("id", "10");<br />
			Element configurReport = autoReport.addElement("node")<br />
					.addAttribute("name", "Configurable").addAttribute("type",<br />
							"FieldGroupItem").addAttribute("id", "11");<br />
			Element autoLookup = fieldsGroups.addElement("node").addAttribute(<br />
					"name", "AutoReport").addAttribute("type", "FieldGroup")<br />
					.addAttribute("id", "12");<br />
			Element itemidLookup = autoLookup.addElement("node").addAttribute(<br />
					"name", "ItemId").addAttribute("type", "FieldGroupItem")<br />
					.addAttribute("id", "13");<br />
			Element itemNameLookup = autoLookup.addElement("node")<br />
					.addAttribute("name", "ItemName").addAttribute("type",<br />
							"FieldGroupItem").addAttribute("id", "14");<br />
			Element bom = fieldsGroups.addElement("node").addAttribute("name",<br />
					"AutoReport").addAttribute("type", "FieldGroup")<br />
					.addAttribute("id", "15");</p>
<p>			/*** 添加node子节点Indexes */<br />
			Element indexes = nodeElement.addElement("node").addAttribute(<br />
					"name", "Indexes").addAttribute("type", "Indexes")<br />
					.addAttribute("id", "16");<br />
			;</p>
<p>			Element itemIdx = indexes.addElement("node").addAttribute("name",<br />
					"ItemIdx").addAttribute("type", "Index").addAttribute("id",<br />
					"17");<br />
			Element itemIdIndex = itemIdx.addElement("node").addAttribute(<br />
					"name", "ItemId").addAttribute("type", "IndexItem")<br />
					.addAttribute("id", "18");<br />
			/** 添加node子节点Relations */<br />
			Element relations = nodeElement.addElement("node").addAttribute(<br />
					"name", "Relactions").addAttribute("type", "Relations")<br />
					.addAttribute("id", "19");<br />
			Element itemConfig = relations.addElement("node").addAttribute(<br />
					"name", "ItemConfig").addAttribute("type", "Relation")<br />
					.addAttribute("id", "20");<br />
			Element id1 = itemIdx.addElement("node").addAttribute("name", "1")<br />
					.addAttribute("type", "RelactionItem").addAttribute("id",<br />
							"21");<br />
			Element id2 = indexes.addElement("node").addAttribute("name",<br />
					"ItemIdx").addAttribute("type", "RelactionItem")<br />
					.addAttribute("id", "22");<br />
		}<br />
		try {</p>
<p>			/** 将document中的内容写入文件中 */<br />
			/** 美化xml标签 */<br />
			OutputFormat format = OutputFormat.createPrettyPrint();</p>
<p>			/** 实例化XMLWriter,利用FileWriter指定文件写入 */<br />
			XMLWriter writer = new XMLWriter(new FileWriter(xmlpath), format);<br />
			writer.write(document);<br />
			writer.close();<br />
			return nodeElement.asXML();<br />
		} catch (Exception ex) {<br />
			ex.printStackTrace();<br />
			return "-1";<br />
		}<br />
	}<br />
</code></p>
<p>接下来把DialogTextInput组件的事件实现一下,通过上面的addElement方法调用该组件.<br />
简单的定义了一个输入框 和二个按钮<br />
<code><br />
<s:label width="60" text="请输入:" height="22" x="34" y="10" /></p>
<p><s:button id="btnOK" click="btnOK_clickHandler(event)" x="80" y="33" label="OK" /></p>
<p><s:button id="btnCancel" click="btnCancel_clickHandler(event)" x="183" y="33" label="Cancel" /></p>
<p></code><br />
ReadXml是主模块,上面的flex代码都是在此文件里的.主要是需要调用newTableOK事件.通过输入框的值传入.<br />
removeElement(this)是关闭本窗口的意思,开始为找关闭功能一直在点close之类的信息都没用.郁闷&#8230;<br />
<code><br />
protected function btnOK_clickHandler(event:MouseEvent):void<br />
			{<br />
				try<br />
				{<br />
					(this.parentApplication as ReadXml).newTableOK(this.textTable.text);<br />
					this.parentApplication.removeElement(this);<br />
				}<br />
				catch (error:Error)<br />
				{<br />
					Alert.show(error.toString());<br />
				}<br />
			}</p>
<p>			protected function btnCancel_clickHandler(event:MouseEvent):void<br />
			{<br />
				try<br />
				{<br />
					this.parentApplication.removeElement(this);<br />
				}<br />
				catch (error:ErrorEvent)<br />
				{<br />
					Alert.show(error.toString());<br />
				}<br />
			}<br />
</code><br />
还是这样说.完整的代码可去我googleSVN上面看看..本人初学者&#8230;很多代码没有优化额,望高手们多多指正.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/flexwriter_tree_xml.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>使用Tree和DataGrid组件读取Xml文件</title>
		<link>http://www.licream.net/flex_java_tree.html/</link>
		<comments>http://www.licream.net/flex_java_tree.html/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 05:34:07 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.licream.net/?p=552</guid>
		<description><![CDATA[最近做了个小东西,使用了Tree和DataGrid组件,并通过xml文件定义好的结构在tree上显示节点和通过xml文件把数据显示在DataGrid上面. 我通过dom4j来读取xml文件.下面是我读取xml文件的代码 先插首歌曲听听 package gongqi.xml.service; import java.io.File; import java.util.Iterator; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.springframework.flex.remoting.RemotingDestination; import...]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.licream.net/wp-content/uploads/2010/08/tr.jpg" alt="" title="tr" width="457" height="235" class="alignnone size-full wp-image-555" /><br />
最近做了个小东西,使用了Tree和DataGrid组件,并通过xml文件定义好的结构在tree上显示节点和通过xml文件把数据显示在DataGrid上面.</p>
<p>我通过dom4j来读取xml文件.下面是我读取xml文件的代码<br />
先插首歌曲听听<br />
<embed src="http://www.licream.net/wp-content/themes/istudio-theme/swf/player.swf?soundFile=http://online1.tingclass.com/music/shi0529/notafriad.mp3&autostart=no&animation=yes&encode=no&initialvolume=80&remaining=yes&noinfo=no&buffer=5&checkpolicy=no&rtl=no&bg=E5E5E5&text=333333&leftbg=CCCCCC&lefticon=333333&volslider=666666&voltrack=FFFFFF&rightbg=B4B4B4&rightbghover=999999&righticon=333333&righticonhover=FFFFFF&track=FFFFFF&loader=009900&border=CCCCCC&tracker=DDDDDD&skip=666666" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" width="290" height="30"><br />
<span id="more-552"></span></p>
<pre class="brush: java;">
package gongqi.xml.service;

import java.io.File;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RemotingDestination(channels = { &quot;my-amf&quot; })
@Transactional
public class ReaderXml {

	@RemotingInclude
	public String gReadXml(String filexml) {
		SAXReader reader = new SAXReader();
		String xml = &quot;&quot;;
		try {
			Document doc = reader.read(new File(filexml));
			Element elements = doc.getRootElement();

			for (Iterator it = elements.elementIterator(); it.hasNext();) {
				Element element = (Element) it.next();
				xml += element.asXML();
			}
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		return xml;

	}

}
</pre>
<p>这是创建xml文件代码有点臃肿.呵呵:</p>
<pre class="brush: java;">
package gongqi.xml.service;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RemotingDestination(channels = { &quot;my-amf&quot; })
@Transactional
public class CreateXml {

	/**
	 * 创建xml文件
	 *
	 * @param filexml
	 * @return
	 * @throws IOException
	 */
	@RemotingInclude
	public String createXMLFile(String filename) {

		/** 建立document对象 */
		Document document = DocumentHelper.createDocument();
		/** 建立XML文档的根root */
		Element root = document.addElement(&quot;root&quot;);

		/** 加入一行注释 */
		root.addComment(&quot;这是一个表结构&quot;);

		/** 加入第一个node节点 */
		Element nodeElement = root.addElement(&quot;node&quot;);
		nodeElement.addAttribute(&quot;name&quot;, &quot;newtable&quot;).addAttribute(&quot;type&quot;,
				&quot;Table&quot;).addAttribute(&quot;id&quot;, &quot;1&quot;);

		/** 添加node子节点fields */
		Element fields = nodeElement.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;Fields&quot;).addAttribute(&quot;type&quot;, &quot;Fields&quot;)
				.addAttribute(&quot;id&quot;, &quot;2&quot;);
		fields.addAttribute(&quot;name&quot;, &quot;Fields&quot;).addAttribute(&quot;type&quot;, &quot;Fields&quot;)
				.addAttribute(&quot;id&quot;, &quot;2&quot;);
		Element itemid = fields.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;ItemId&quot;).addAttribute(&quot;type&quot;, &quot;Field&quot;).addAttribute(&quot;id&quot;, &quot;3&quot;);
		Element itemName = fields.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;ItemName&quot;).addAttribute(&quot;type&quot;, &quot;Field&quot;).addAttribute(&quot;id&quot;,
				&quot;4&quot;);
		Element itemGroup = fields.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;ItemGroup&quot;).addAttribute(&quot;type&quot;, &quot;Field&quot;).addAttribute(&quot;id&quot;,
				&quot;5&quot;);

		/** 添加node子节点FieldGroup */
		Element fieldsGroups = nodeElement.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;FieldGroups&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroups&quot;)
				.addAttribute(&quot;id&quot;, &quot;6&quot;);
		fieldsGroups.addAttribute(&quot;name&quot;, &quot;Fields&quot;).addAttribute(&quot;type&quot;,
				&quot;Fields&quot;).addAttribute(&quot;id&quot;, &quot;6&quot;);
		Element autoReport = fieldsGroups.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;AutoReport&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroup&quot;)
				.addAttribute(&quot;id&quot;, &quot;7&quot;);
		Element itemidReport = autoReport.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;ItemId&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroupItem&quot;)
				.addAttribute(&quot;id&quot;, &quot;8&quot;);
		Element itemNameReport = autoReport.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;ItemName&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroupItem&quot;)
				.addAttribute(&quot;id&quot;, &quot;9&quot;);
		Element itemGroupReport = autoReport.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;ItemGroup&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroupItem&quot;)
				.addAttribute(&quot;id&quot;, &quot;10&quot;);
		Element configurReport = autoReport.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;Configurable&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroupItem&quot;)
				.addAttribute(&quot;id&quot;, &quot;11&quot;);
		Element autoLookup = fieldsGroups.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;AutoReport&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroup&quot;)
				.addAttribute(&quot;id&quot;, &quot;12&quot;);
		Element itemidLookup = autoLookup.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;ItemId&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroupItem&quot;)
				.addAttribute(&quot;id&quot;, &quot;13&quot;);
		Element itemNameLookup = autoLookup.addElement(&quot;node&quot;).addAttribute(
				&quot;name&quot;, &quot;ItemName&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroupItem&quot;)
				.addAttribute(&quot;id&quot;, &quot;14&quot;);
		Element bom = fieldsGroups.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;AutoReport&quot;).addAttribute(&quot;type&quot;, &quot;FieldGroup&quot;).addAttribute(
				&quot;id&quot;, &quot;15&quot;);

		/*** 添加node子节点Indexes */
		Element indexes = nodeElement.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;Indexes&quot;).addAttribute(&quot;type&quot;, &quot;Indexes&quot;).addAttribute(&quot;id&quot;,
				&quot;16&quot;);
		;

		Element itemIdx = indexes.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;ItemIdx&quot;).addAttribute(&quot;type&quot;, &quot;Index&quot;).addAttribute(&quot;id&quot;,
				&quot;17&quot;);
		Element itemIdIndex = itemIdx.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;ItemId&quot;).addAttribute(&quot;type&quot;, &quot;IndexItem&quot;).addAttribute(&quot;id&quot;,
				&quot;18&quot;);
		/** 添加node子节点Relations */
		Element relations = nodeElement.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;Relactions&quot;).addAttribute(&quot;type&quot;, &quot;Relations&quot;).addAttribute(
				&quot;id&quot;, &quot;19&quot;);
		Element itemConfig = relations.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;,
				&quot;ItemConfig&quot;).addAttribute(&quot;type&quot;, &quot;Relation&quot;).addAttribute(
				&quot;id&quot;, &quot;20&quot;);
		Element id1 = itemIdx.addElement(&quot;node&quot;).addAttribute(&quot;name&quot;, &quot;1&quot;)
				.addAttribute(&quot;type&quot;, &quot;RelactionItem&quot;).addAttribute(&quot;id&quot;, &quot;21&quot;);
		Element id2 = indexes.addElement(&quot;node&quot;)
				.addAttribute(&quot;name&quot;, &quot;ItemIdx&quot;).addAttribute(&quot;type&quot;,
						&quot;RelactionItem&quot;).addAttribute(&quot;id&quot;, &quot;22&quot;);

		try {
			/** 将document中的内容写入文件中 */
			XMLWriter writer = new XMLWriter(new FileWriter(new File(filename)));
			writer.write(document);
			writer.close();

		} catch (Exception ex) {

			ex.printStackTrace();
		}

		return document.asXML();

	}
}&lt;/div&gt;
</pre>
<p>切换到前台,通过BlazeDS远程生成服务,并调用上面的方法.很简单的.<br />
先需要声明service服务</p>
<pre class="brush: jscript;">
&lt;s:ChannelSet id=&quot;channel&quot;&gt;
			&lt;s:AMFChannel url=&quot;http://localhost:8080/ReadXml/messagebroker/amf&quot;/&gt;
		&lt;/s:ChannelSet&gt;

		&lt;services:ReaderXml  id=&quot;serviceReadXml&quot; result=&quot;readerxml1_resultHandler(event)&quot; fault=&quot;Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)&quot; channelSet=&quot;{channel}&quot; showBusyCursor=&quot;true&quot; /&gt;
</pre>
<p><fx:xmllist id="gotxml"/></p>
<p>通过HTTPService访问远程xml文件,并解析为xml形式 在readerxml1_resultHandler 方法里实现以xmllist类型显示 gotxml=XMLList(event.result.toString()); </p>
<p><mx:httpservice url="dataxml/TableProperties.xml" useProxy="false"  id="srvtable" resultFormat="xml" result="srvtable_resultHandler(event)" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"/><br />
//调用远程方法读取xml文件.<br />
serviceReadXml.gReadXml(&#8220;E:/工作资源/erp/Gongqi_XML/got/GOT.xml&#8221;);</p>
<p>//把数据绑定到Tree组件上面<br />
dataProvider=&#8221;{gotxml}&#8221;</p>
<p>自定义右键菜单. </p>
<pre class="brush: jscript;">

private function showTables():void{

				var t_tables:ContextMenu=new ContextMenu();

				var M_openNewWindow:ContextMenuItem = new ContextMenuItem(&quot;Open New Windows&quot;);
				var M_Tables:ContextMenuItem = new ContextMenuItem(&quot;New Table&quot;);
				var M_Export:ContextMenuItem=new ContextMenuItem(&quot;Export&quot;);
				var M_Compile:ContextMenuItem=new ContextMenuItem(&quot;Compile&quot;);
				var M_Find:ContextMenuItem=new ContextMenuItem(&quot;Find&quot;);
				var M_Addins:ContextMenuItem=new ContextMenuItem('Add-ins');
				var M_Refresh:ContextMenuItem=new ContextMenuItem(&quot;Refresh&quot;);

				M_Tables.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,newTableEvent);

				t_tables.customItems.push(M_Tables);
				t_tables.customItems.push(M_openNewWindow);
				t_tables.customItems.push(M_Export);
				t_tables.customItems.push(M_Compile);
				t_tables.customItems.push(M_Find);
				t_tables.customItems.push(M_Addins);
				t_tables.customItems.push(M_Refresh);
				t_tables.hideBuiltInItems();
				tree.contextMenu=t_tables;

			}
private function newTableEvent(event:Event):void{

				try{
					newTable.createXMLFile(&quot;E:/Tables.xml&quot;);
					Alert.show(&quot;.......&quot;);

				}catch(io:IOError){
					Alert.show(io.message);
				}
			}
</pre>
<p>  根据节点要显示的功能不同及菜单项不同.我分别进行了一些判断.</p>
<pre class="brush: jscript;">
public function tree1_changeHandler(event):void{

				//注意:如果在父节点加入子节点xml,再不变更节点目录下,不能使用统一service ID,重新定义一个srevice ID来执行远程方法
				if(tree.selectedItem.@type=='Tables'){

					tableReadXml.gReadXml(&quot;E:/工作资源/erp/Gongqi_XML/got/datadictionary/Tables.xml&quot;);
					showTables();

				}else if(tree.selectedItem.@type=='Enums'){

					tableReadXml.gReadXml(&quot;E:/工作资源/erp/Gongqi_XML/got/datadictionary/Enums.xml&quot;);

				}else if(tree.selectedItem.@type=='ExtendedDataTypes'){

					tableReadXml.gReadXml(&quot;E:/工作资源/erp/Gongqi_XML/got/datadictionary/ExtendedDataTypes.xml&quot;);

				}else if(tree.selectedItem.@type=='Table'){					

					srvtable.send();

				}else if(tree.selectedItem.@type=='Field'){

					tablefield.send();
				}else if(tree.selectedItem.@type=='FieldGroup'){

					this.tablefieldgroup.send();

				}else if(tree.selectedItem.@type=='Index' ){

					this.tableindex.send();

				}else if(tree.selectedItem.@type=='Relation'){

					this.tablerelation.send();

				}else if(tree.selectedItem.@type=='Enum' ){

					this.enum.send();

				}else if(tree.selectedItem.@type=='EnumItem' ){

					this.enumitem.send();

				}else if(tree.selectedItem.@type=='RelationItem' ){

					this.extendeddatatypeitem.send();

				}else if(tree.selectedItem.@type=='ExtendedDataType' ){

					this.extendeddatatype.send();

				}else if(tree.selectedItem.@type=='RelationItem' ){

					this.tablerelationitem.send();

				}else if(tree.selectedItem.@type=='GOT'){	

					showGotMenu();			

				}else if(tree.selectedItem.@type=='DataDictionary'){
					showDataDictionary();

				}
			}
</pre>
<p> //在tree节点上添加子节点的xml文件.需将selecteditem转换为xml类型; </p>
<pre class="brush: jscript;">
protected function tableReadXml_resultHandler(event:ResultEvent):void
			{
				//将所有xml文件都显示出来,使用appendchild添加到子节点上
				tablesxml=XMLList(event.result.toString());
				enumsxml=XMLList(event.result.toString());
				extendsDataTypexml=XMLList(event.result.toString());
				var xml:XML=tree.selectedItem as XML;
				xml.appendChild(tablesxml);
			}
</pre>
<p> 要显示每个节点的属性即在DataGrid组件上显示数据.我们需要先定义一个全局的变量为XML类型;<br />
private var pro:XML;<br />
远程访问文件后进行绑定在DataGrid组件上面  </p>
<p>pro=XML(event.result);<br />
 dgpro.dataProvider =pro.child(&#8220;node&#8221;).children();//node节点下所有属性</p>
<p>   表达能力有限..这些完整代码我上传到google SVN上面了.有兴趣的可以去看看:http://code.google.com/p/licreamflexspringhibernate/source/list</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/flex_java_tree.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://online1.tingclass.com/music/shi0529/notafriad.mp3" length="5636053" type="audio/mpeg" />
		</item>
		<item>
		<title>整理分析项目流程</title>
		<link>http://www.licream.net/sortflexspring.html/</link>
		<comments>http://www.licream.net/sortflexspring.html/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 04:57:49 +0000</pubDate>
		<dc:creator>licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.licream.net/?p=543</guid>
		<description><![CDATA[上午用了些时间整理了一下最近使用的技术,比不上专业人员.粗略的说了下自已认识. 本来是用PPT通过google直接共享在这的.可惜被强 奸了啊..我们是看不到的.. 图简单的画了下.也不知道是不是正确的,我是按照自已的思路完成:) ﻿Hibernate注解 通过注解,我们可以完成以前的xml文件配置功能,这里说下 hibernate注解,目前我使用主要是在实体类中定义表结构.对应表结构或创建表结构.进行自动装配Bean. 使用注解包需采用javax.persistence.*; 下面的注解，而不是org.hibernate.annotation.*;虽然这二个包功能是一样.为了那传说中的jpa规范吧. Entity实体 @Entity:将一个类声明为一个实体bean @Table:声明该实体bean映射指定的表 上面二个用在类的上面  @Column:注解声明了属性到列的映射 @Id:声明该实体bean的标识属性,对应表主键 @GeneratedValue :注解声明了主键的生成策略 常用的表映射有这些,其它需要的时侯查查API文档 如果注解里面有value属性则可以省略写直接赋值就可以,例:@Talbe(value=“”)==@Table(“”) 这些注解将替代了以前hbm.xml形式来映射...]]></description>
			<content:encoded><![CDATA[<p>上午用了些时间整理了一下最近使用的技术,比不上专业人员.粗略的说了下自已认识. <img src='http://www.licream.net/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' />   <img src='http://www.licream.net/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /><br />
本来是用PPT通过google直接共享在这的.可惜被强  奸了啊..我们是看不到的..<br />
<a href="http://www.licream.net/wp-content/uploads/2010/07/1.jpg"><img class="alignnone size-medium wp-image-547" title="1" src="http://www.licream.net/wp-content/uploads/2010/07/1-300x220.jpg" alt="" width="300" height="220" /></a></p>
<p>图简单的画了下.也不知道是不是正确的,我是按照自已的思路完成:) <img src='http://www.licream.net/wp-includes/images/smilies/icon_cool.gif' alt=':cool:' class='wp-smiley' /> </p>
<p><span id="more-543"></span></p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/2.jpg"><img class="alignnone size-medium wp-image-548" title="2" src="http://www.licream.net/wp-content/uploads/2010/07/2-300x216.jpg" alt="" width="300" height="216" /></a></p>
<p><span style="color: #ff0000;">﻿Hibernate注解</span></p>
<p>通过注解,我们可以完成以前的xml文件配置功能,这里说下 hibernate注解,目前我使用主要是在实体类中定义表结构.对应表结构或创建表结构.进行自动装配Bean.  使用注解包需采用javax.persistence.*; 下面的注解，而不是org.hibernate.annotation.*;虽然这二个包功能是一样.为了那传说中的jpa规范吧.</p>
<p><span style="color: #ff0000;">Entity实体</span></p>
<p>@Entity:将一个类声明为一个实体bean</p>
<p>@Table:声明该实体bean映射指定的表  上面二个用在类的上面  </p>
<p>@Column:注解声明了属性到列的映射</p>
<p>@Id:声明该实体bean的标识属性,对应表主键</p>
<p>@GeneratedValue :注解声明了主键的生成策略  常用的表映射有这些,其它需要的时侯查查API文档  如果注解里面有value属性则可以省略写直接赋值就可以,例:@Talbe(value=“”)==@Table(“”)  这些注解将替代了以前hbm.xml形式来映射</p>
<p><span style="color: #ff0000;">Dao</span></p>
<p>子类继承hibernateDaoSupport,重写sessionFactory,并用注解@Resource注入,这样完成了dao与sessonfactory之间的依赖注入.  @Repository:用于标示数据访问层(持久层).定义在class类上面  各层之间注解:这些注解只能用法实现类,不可用在接口类</p>
<p>@Component:可装载组件(泛型模形)</p>
<p>@Repository:持久层组件</p>
<p>@Service:服务层组件<br />
@Controller:控制层组件   如果想在一个类中获得文件可以通过在xml配置这个类的某个属性。在注解的方式中，可以使用@Value来指定这个文件。例:@Value(&#8220;/WEB-INF/database.properties&#8221;)</p>
<p><span style="color: #ff0000;">注解说明</span></p>
<p>@Resource注解所提供名字相匹配的“bean name（bean名字）”的Spring管理对象会被注入.不指定名称则采用该类名为bean name.  等同于&lt;baen  id=“beanname” class=“bean.class” /&gt;  sessionFactory与dao层及service层的注入用该注解完全可不用在配置文件里写任何bean信息</p>
<p><span style="color: #ff0000;">Service</span></p>
<p>通过接口方法来调用持久层的方法,声明持久层接口用注解为他们之间进行依赖注入.  </p>
<p>@Service:表示该类为服务类.用在 class类上面  </p>
<p>@Transactional:需要事务管理的地方则加上,类的class和类的方法体上都可以加.方法体优先于类的class执行.注解要是写到接口方法上，要使用cglib代理，这时注解事物就失效了，为了保持兼容注解最好都写到实现类方法上,一般来说,将事务定位在业务层，这是非常务实的做法, 有二个常用属性(readOnly = false, rollbackFor = DataAccessException.class)只读关闭，遇到DataAccessException异常回滚</p>
<p><span style="color: #ff0000;">Web.xml</span></p>
<p>添加spring,BlazeDS,Log4j相应的过滤器注册  注意该文件的标签顺序,否则会出错.</p>
<p><span style="color: #ff0000;">Spring在flex的作用</span></p>
<p>MessageBroker 是 SBI 的一个组件，它的职责是处理 Flex 远程调用请求。MessageBroker 由 Spring 容器进行管理而不是由 BlazeDS。在 Web.xml 中添加 DispatcherServlet 允许 Spring 自行管理 MessageBroker。</p>
<p><span style="color: #ff0000;">注册spring容器</span></p>
<pre class="brush: xml;">
&lt;servlet&gt;
		&lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
			&lt;param-value&gt;/WEB-INF/config/application-config.xml&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/messagebroker/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
<p>利用spring把系统默认的BlazeDS的MessageBrokerServlet代理了<br />
spring容器注册,并指定applicaion-config.xml配置文件路径.<br />
第二条代码指定请求路径.</p>
<p><span style="color: #ff0000;">BlazeDS介绍</span></p>
<p>BlazeDS 是 Adobe Live-Cycle Service 的免费开源版本，它使用 AMF 二进制协议通过 AMF 管道构建了 Flex 和 Spring 进行数据通信的桥梁。BlazeDS 可以实现 Flex 对 Java 对象的远程调用。BlazeDS 可以部署运行在大多数 Web 应用服务器上，如 Tomcat、Websphere、JBoss 以及 Weblogic。</p>
<p><span style="color: #ff0000;">BlazeDS服务注册</span></p>
<pre class="brush: xml;">
&lt;servlet&gt;
&lt;servlet-name&gt;RDSDispatchServlet&lt;/servlet-name&gt;
&lt;display-name&gt;RDSDispatchServlet&lt;/display-name&gt;
&lt;servlet-class&gt;flex.rds.server.servlet.FrontEndServlet&lt;/servlet-class&gt;
&lt;init-param&gt;
&lt;param-name&gt;messageBrokerId&lt;/param-name&gt;
&lt;param-value&gt;_messageBroker&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;init-param&gt;
&lt;param-name&gt;useAppserverSecurity&lt;/param-name&gt;
&lt;param-value&gt;false&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;load-on-startup&gt;10&lt;/load-on-startup&gt;
&lt;/servlet&gt;

&lt;servlet-mapping id=&quot;RDS_DISPATCH_MAPPING&quot;&gt;
&lt;servlet-name&gt;RDSDispatchServlet&lt;/servlet-name&gt;
&lt;url-pattern&gt;/CFIDE/main/ide.cfm&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
<p><span style="color: #ff0000;">Log4j注册</span></p>
<pre class="brush: xml;">
&lt;context-param&gt;
&lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
&lt;param-value&gt;/WEB-INF/log4j.properties&lt;/param-value&gt;
&lt;/context-param&gt;
&lt;context-param&gt;
&lt;param-name&gt;log4jRefreshInterval&lt;/param-name&gt;
&lt;param-value&gt;1000&lt;/param-value&gt;
&lt;/context-param&gt;

&lt;listener&gt;
&lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p><span style="color: #ff0000;">Application配置</span><br />
首先配置flex,hibernate,等需要的命名空间.</p>
<pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/flex

http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;
</pre>
<p>利用注解方式类配置hibernate,sessionFactory,并指定数据源.配置实体类路径,利用annotatedClasses自动扫描访实体类,与指定hbm.xml意义相同.优点是省了xml文件.<br />
目前annotatedClasses还不能通过包名来自动扫描下面的注解类.需要手动一个一个的添加.或采用正则表达式方式添加.</p>
<pre class="brush: xml;">
&lt;bean id=&quot;sessionFactory&quot;
class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
&lt;property name=&quot;configLocation&quot; value=&quot;classpath:hibernate.cfg.xml&quot; /&gt;
&lt;property name=&quot;annotatedClasses&quot;&gt;
&lt;list&gt;
&lt;value&gt;entity.UserInfo&lt;/value&gt;
&lt;/list&gt;
&lt;/property&gt;
&lt;/bean&gt;
</pre>
<p>我们还需要扫描spring相关的注解功能.配置自动扫描代码:</p>
<p>自动扫描dao包里面的类.需要扫描其它包则修改为相应的包名即可.</p>
<p><span style="color: #ff0000;">Flex介绍</span></p>
<p>Flex 的通信协议主要有三种：HttpService、WebService 和 RemoteObject。RomoteObject 协议作为 Flex 提供的最快的通信方式，通过集成 BlazeDS，利用 AMF（Action Message Format）二进制协议使得 Flex 前端能轻松与 Java EE 后端进行数据交互，它是 Flex 集成 Spring 的首选通信协议。</p>
<p><span style="color: #ff0000;">配置flex信息</span><br />
配置请求通道,通道定义在service-config.xml,有几种通道.把我们需要的引入出来,使用多种用短号分开</p>
<pre class="brush: xml;">
&lt;flex:message-broker&gt;
&lt;flex:remoting-service default-channels=&quot;my-amf&quot; /&gt;
&lt;/flex:message-broker&gt;
&lt;!--开启flex相关注解支持功能--&gt;
&lt;bean
class=&quot;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter&quot; /&gt;
常用的注解有:
@RemotingDestination :定义在类上面
@RemotingInclude:定义在方法体上面
</pre>
<p>顺手测试下音乐功能:<br />
<embed src="http://www.licream.net/wp-content/themes/istudio-theme/swf/player.swf?soundFile=http://c2.api.ning.com/files/-ItFxbXs-A1vBE*VbSTkgCY1ahqVHJV-El-8TjVtXfDcWYkgOOotF6m-p4loFcUjSR0Kk8xy09ZV0q*QscFBzZiZ96i*OJom/Stan.mp3&autostart=no&animation=yes&encode=no&initialvolume=80&remaining=yes&noinfo=no&buffer=5&checkpolicy=no&rtl=no&bg=E5E5E5&text=333333&leftbg=CCCCCC&lefticon=333333&volslider=666666&voltrack=FFFFFF&rightbg=B4B4B4&rightbghover=999999&righticon=333333&righticonhover=FFFFFF&track=FFFFFF&loader=009900&border=CCCCCC&tracker=DDDDDD&skip=666666" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" width="290" height="30"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/sortflexspring.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>通过注解实现注册功能Flex</title>
		<link>http://www.licream.net/flex-reg.html/</link>
		<comments>http://www.licream.net/flex-reg.html/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 01:09:14 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[blazeds]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.licream.net/%e9%80%9a%e8%bf%87%e6%b3%a8%e8%a7%a3%e5%ae%9e%e7%8e%b0%e6%b3%a8%e5%86%8c%e5%8a%9f%e8%83%bdflex.html/</guid>
		<description><![CDATA[１. 利用Eclipse新建一个Flex项目名叫：FBS 按步一下并按照下图配置信息，再点完成． ２. 切换到java ee视图环境下编写java类,后台代码 在src目录下分别新建三个包:entity,dao,service. 在entity包里新建一个UserInfo的实体类 在方法体内写三个变量．Id,name,pass. 按shift+alt+s键并为他们生成set,get方法． 在类上面定义注解:@Entity及@table 在变量的get方法上面(除了主键)添加@colume package entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue;...]]></description>
			<content:encoded><![CDATA[<p>１. 利用Eclipse新建一个Flex项目名叫：FBS</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0021.jpg"><img style="display: inline; border-width: 0px;" title="clip_image002" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image002_thumb1.jpg" border="0" alt="clip_image002" width="184" height="244" /></a></p>
<p>按步一下并按照下图配置信息，再点完成．<span id="more-471"></span></p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0041.jpg"><img style="display: inline; border-width: 0px;" title="clip_image004" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image004_thumb1.jpg" border="0" alt="clip_image004" width="213" height="244" /></a></p>
<p>２. 切换到java ee视图环境下编写java类,后台代码</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0061.jpg"><img style="display: inline; border-width: 0px;" title="clip_image006" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image006_thumb1.jpg" border="0" alt="clip_image006" width="244" height="22" /></a></p>
<p>在src目录下分别新建三个包:entity,dao,service.</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0081.jpg"><img style="display: inline; border-width: 0px;" title="clip_image008" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image008_thumb1.jpg" border="0" alt="clip_image008" width="244" height="233" /></a></p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0101.jpg"><img style="display: inline; border-width: 0px;" title="clip_image010" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image010_thumb1.jpg" border="0" alt="clip_image010" width="205" height="244" /></a></p>
<p>在entity包里新建一个UserInfo的实体类</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0121.jpg"><img style="display: inline; border-width: 0px;" title="clip_image012" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image012_thumb1.jpg" border="0" alt="clip_image012" width="229" height="244" /></a></p>
<p>在方法体内写三个变量．Id,name,pass. 按shift+alt+s键并为他们生成set,get方法．</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0141.jpg"><img style="display: inline; border-width: 0px;" title="clip_image014" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image014_thumb1.jpg" border="0" alt="clip_image014" width="212" height="244" /></a></p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0161.jpg"><img style="display: inline; border-width: 0px;" title="clip_image016" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image016_thumb1.jpg" border="0" alt="clip_image016" width="244" height="152" /></a></p>
<p>在类上面定义注解:@Entity及@table</p>
<p>在变量的get方法上面(除了主键)添加@colume</p>
<pre class="brush: java;">
package entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table   //定义表名，不指定名则默认为该类名
public class UserInfo {
	public int Id;
	public String Name;
	public String Pass;
	@Id //主键ID
	@GeneratedValue //自动增长属性
	public int getId() {
		return Id;
	}
	public void setId(int id) {
		Id = id;
	}
	@Column //定义一个列属性
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	@Column
	public String getPass() {
		return Pass;
	}
	public void setPass(String pass) {
		Pass = pass;
	}

}
</pre>
<p>上面是完整的UserInfo代码.该类我们已经写好了,现在定义一个Dao,我们采用HibernateDaoSupport来实现.我们先写一个DAO的基类.在里面自动注入sessionFactory.通过子类来继承它,则子类自动注入到sessionFactory的实现.</p>
<p>这是DAO基类代码:</p>
<pre class="brush: java;">
package dao;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

public class SuperDao extends HibernateDaoSupport{

	@Resource(name = &quot;sessionFactory&quot;) //该注解意思是自动注入,指定名称为sessionFactory,要和xml里的名称一样
	public void setSessionFactoryOverride(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}

}
</pre>
<p>接下来我们声明一个UserInfoDao的接口.在里面写入要实现的方法</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0181.jpg"><img style="display: inline; border-width: 0px;" title="clip_image018" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image018_thumb1.jpg" border="0" alt="clip_image018" width="244" height="225" /></a></p>
<p>这是userInfoDao接口代码:</p>
<pre class="brush: java;"> package dao;

import java.util.List;

import entity.UserInfo;

public interface UserInfoDao {
	public void addUserInfo(UserInfo user);
	public List&lt;UserInfo&gt; findAll();
}
 </pre>
<p>建创一个UserInfoDaoImpl类来实现该接口的方法.并继续SuperDao基类.</p>
<p>这是UserInfoDaoImpl实现方法的代码(另个方法没去实现.添加功能通过了,其它功能以后再添加),实现了添加方法</p>
<pre class="brush: java;"> package dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import entity.UserInfo;
@Repository //表示持久层
public class UserInfoDaoImpl extends SuperDao implements UserInfoDao{

	@Override
	public void addUserInfo(UserInfo user) {
		this.getHibernateTemplate().save(user);

	}

	@Override
	public List&lt;UserInfo&gt; findAll() {
		// TODO Auto-generated method stub
		return null;
	}

}
</pre>
<p>现在我们需要创建服务类.与dao层类似.也是需要先定义一个接口.再实现接口的方法.再通过UserDao来调用持久层的方法.</p>
<p>这是UserInfoServiceImpl类代码:</p>
<pre class="brush: java;"> package service;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.TableGenerator;

import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dao.UserInfoDao;
import entity.UserInfo;

@Service(&quot;UserInfoService&quot;)
// 表示该类为service层
@RemotingDestination(channels = { &quot;my-amf&quot; })
@Transactional
// 调用事务
public class UserInfoServiceImpl implements UserInfoService {

	@Resource
	UserInfoDao userInfoDao; // 声明UserInfoDao

	@Override
	@RemotingInclude
	public void addUserInfo(UserInfo user) {
		userInfoDao.addUserInfo(user);

	}

	@Override
	@RemotingInclude
	public List&lt;UserInfo&gt; findAll() {
		// TODO Auto-generated method stub
		return null;
	}

}
</pre>
<p>接下来.在src目录下创建一个来与数据库连接的数据源,hibernate.cfg.xml.可通过工具来生成.</p>
<p>以下是该xml代码.其中数据库名称,用户名,密码需要修改.使用mysql数据库.</p>
<pre class="brush: xml;"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot; &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;
&lt;hibernate-configuration&gt;
	&lt;session-factory&gt;
		&lt;property name=&quot;hibernate.dialect&quot;&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
		&lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;/property&gt;
		&lt;property name=&quot;hibernate.connection.url&quot;&gt;jdbc:mysql://localhost:3306/hibernate&lt;/property&gt;
		&lt;property name=&quot;hibernate.connection.username&quot;&gt;root&lt;/property&gt;
		&lt;property name=&quot;hibernate.connection.password&quot;&gt;lds7617&lt;/property&gt;
		&lt;property name=&quot;hibernate.hbm2ddl.auto&quot;&gt;create&lt;/property&gt;
		&lt;property name=&quot;hibernate.show_sql&quot;&gt;true&lt;/property&gt;
		&lt;property name=&quot;hibernate.format_sql&quot;&gt;true&lt;/property&gt;
		&lt;property name=&quot;hibernate.current_session_context_class&quot;&gt;thread&lt;/property&gt;

		&lt;!-- 最大连接数 --&gt;
		&lt;property name=&quot;hibernate.c3p0.max_size&quot;&gt;20&lt;/property&gt;
		&lt;!-- 最小连接数 --&gt;
		&lt;property name=&quot;hibernate.c3p0.min_size&quot;&gt;5&lt;/property&gt;
		&lt;!-- 获得连接的超时时间,如果超过这个时间,会抛出异常，单位毫秒 --&gt;
		&lt;property name=&quot;hibernate.c3p0.timeout&quot;&gt;120&lt;/property&gt;
		&lt;!-- 最大的PreparedStatement的数量 --&gt;
		&lt;property name=&quot;hibernate.c3p0.max_statements&quot;&gt;100&lt;/property&gt;
		&lt;!-- 每隔120秒检查连接池里的空闲连接 ，单位是秒--&gt;
		&lt;property name=&quot;hibernate.c3p0.idle_test_period&quot;&gt;120&lt;/property&gt;
		&lt;!-- 当连接池里面的连接用完的时候，C3P0一下获取的新的连接数 --&gt;
		&lt;property name=&quot;hibernate.c3p0.acquire_increment&quot;&gt;2&lt;/property&gt;
		&lt;!-- 每次都验证连接是否可用 --&gt;
		&lt;property name=&quot;hibernate.c3p0.validate&quot;&gt;true&lt;/property&gt;

	&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</pre>
<p>接着在hibernateconfig.xml文件通过sessionFactory来注入数据源.并配置事务处理管理器</p>
<pre class="brush: xml;"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:security=&quot;http://www.springframework.org/schema/security&quot;
	xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd&quot;&gt;

	&lt;!--　定义注解形式SessionFactory --&gt;
	&lt;bean id=&quot;sessionFactory&quot;
		class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
		&lt;!--　定义数据源文件　--&gt;
		&lt;property name=&quot;configLocation&quot; value=&quot;classpath:hibernate.cfg.xml&quot; /&gt;
		&lt;!--　定义扫描有Entity注解实体类　--&gt;
		&lt;property name=&quot;annotatedClasses&quot;&gt;
			&lt;list&gt;
				&lt;value&gt;entity.UserInfo&lt;/value&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;!--　配置事务管理　--&gt;
	&lt;bean id=&quot;txManager&quot;
		class=&quot;org.springframework.orm.hibernate3.HibernateTransactionManager&quot;&gt;
		&lt;property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot; /&gt;
	&lt;/bean&gt;
	&lt;tx:annotation-driven transaction-manager=&quot;txManager&quot; /&gt;

&lt;/beans&gt;
</pre>
<p>再找到daoconfig.xml和serviceconfig.xml配置文件修改相应的包名.daoconfig.xml对应的是dao包的路径,serviceconfig.xml对应的是service包的路径.</p>
<pre class="brush: xml;">
&lt;!--　自动扫描dao层有注解的类--&gt;
&lt;context:component-scan base-package=&quot;dao&quot; /&gt;
&lt;!--　自动扫描service层有注解的类--&gt;
&lt;context:component-scan base-package=&quot;service&quot; /&gt;
</pre>
<p>向flexconfig.xml配置信息添加启动注解支持及路径访问配置.这是flexconfig.xml代码.</p>
<pre class="brush: xml;"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/flex

http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;

	&lt;flex:message-broker&gt;
		&lt;flex:remoting-service default-channels=&quot;my-amf&quot; /&gt;
	&lt;/flex:message-broker&gt;

	&lt;!--  启动注解的支持--&gt;
	&lt;bean
		class=&quot;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter&quot; /&gt;

&lt;/beans&gt;
</pre>
<p>对工程进行编译一次.确认没有错误.</p>
<p>接下来我们切换到flash视图环境下编写mxml文件.通过前台来调用后台的业务.</p>
<p>简单的设计下界面</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0201.jpg"><img style="display: inline; border-width: 0px;" title="clip_image020" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image020_thumb1.jpg" border="0" alt="clip_image020" width="244" height="122" /></a></p>
<p>对注册按钮右键点击生成服务调用功能:</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0221.jpg"><img style="display: inline; border-width: 0px;" title="clip_image022" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image022_thumb1.jpg" border="0" alt="clip_image022" width="155" height="244" /></a></p>
<p>选择BlazeDS服务.并钩选不需要密码.点下一步.会出现该错误.</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0241.jpg"><img style="display: inline; border-width: 0px;" title="clip_image024" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image024_thumb1.jpg" border="0" alt="clip_image024" width="244" height="62" /></a></p>
<p>解决方法:找到该工程目录下. .flexProperties文件.打开他.修改serverContextRoot=&#8221;/WebRoot&#8221;参数为项目名serverContextRoot=&#8221;/FBS&#8221; .修改完成生记得刷新一下工程.才能生效.</p>
<p>下一步可以看到我们通过注解公开的bean.</p>
<p>钩选我们要使用的.UserInfoService,并完成</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0261.jpg"><img style="display: inline; border-width: 0px;" title="clip_image026" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image026_thumb1.jpg" border="0" alt="clip_image026" width="244" height="241" /></a></p>
<p>再右键注册按钮来生成服务调用,刚才的步骤是新建服务,现在是用生成好的服务利用组件来调用它们.</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0281.jpg"><img style="display: inline; border-width: 0px;" title="clip_image028" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image028_thumb1.jpg" border="0" alt="clip_image028" width="244" height="139" /></a>我们选择addUserInfo方法.</p>
<p>对生成好的事件进行修改:</p>
<pre class="brush: jscript;">
var userInfoFlex:UserInfo=new UserInfo();
				userInfoFlex.Name=txtname.text;
				userInfoFlex.pass=txtpass.text;
				addUserInfoResult.token = userInfoService.addUserInfo(userInfoFlex); </pre>
<p>还需要为该事件定义路径:</p>
<p>修改如下代码:</p>
<pre class="brush: jscript;">
		&lt;services:UserInfoService id=&quot;userInfoService&quot; fault=&quot;Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)&quot; showBusyCursor=&quot;true&quot;&gt;
			&lt;services:channelSet&gt;
				&lt;s:ChannelSet&gt;
					&lt;s:AMFChannel url=&quot;http://localhost:8080/FBS/messagebroker/amf&quot;/&gt;
				&lt;/s:ChannelSet&gt;
			&lt;/services:channelSet&gt;

		&lt;/services:UserInfoService&gt;
</pre>
<p>这样算简单的配置完成了.如果发现flex_src目录下有文件错误.一般都是因为有重复的代码造成的.删除多余的就可以了.</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0301.jpg"><img style="display: inline; border-width: 0px;" title="clip_image030" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image030_thumb1.jpg" border="0" alt="clip_image030" width="244" height="138" /></a>删除有红色X的方法体.他们是因为有重复的方法了</p>
<p>再重新编译一次..</p>
<p>右键主模块FBS.mxml 运行</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0321.jpg"><img style="display: inline; border-width: 0px;" title="clip_image032" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image032_thumb1.jpg" border="0" alt="clip_image032" width="244" height="74" /></a></p>
<p>如果发现该文件出现404错误,需为工程设置路径.右键工程.&#8211;&gt;属性àflex构建路径.右下角修改为: <a href="http://localhost:8080/FBS/">http://localhost:8080/FBS/</a></p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image0341.jpg"><img style="display: inline; border-width: 0px;" title="clip_image034" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image034_thumb1.jpg" border="0" alt="clip_image034" width="244" height="222" /></a></p>
<p>结果发现有空值针异常.null.</p>
<p>经过检验,发现在UserInfoServiceImpl里的UserInfoDao没有注入给UserInfoServiceImpl.所以会引发这问题.解决的方法是在UserInfoDao上面添加</p>
<pre class="brush: java;">
 @Resource
 UserInfoDao userInfoDao; //声明UserInfoDao
</pre>
<p>成功添加数据:</p>
<p><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image036.jpg"><img style="display: inline; border-width: 0px;" title="clip_image036" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image036_thumb.jpg" border="0" alt="clip_image036" width="244" height="24" /></a></p>
<p>一个简单的注册功能完成了</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/flex-reg.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>更新flex+spring+hibernate通过注解改良实现</title>
		<link>http://www.licream.net/flex_spring_hibernate.html/</link>
		<comments>http://www.licream.net/flex_spring_hibernate.html/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 00:43:43 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[hibernate.web]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.licream.net/?p=432</guid>
		<description><![CDATA[看到官方网上的视频做的例子是通过注解来实现.减少了配置文件代码.我觉得这功能非常不错,经过自已一些测试实验.最终做出点像样的东西了.0 0.额. 下载了官方最新的BlazeDS.war.自已在里面添加了一些hibernate核心包及注解包.版本为.hbiernate3.spring3.flex4.添加了几个配置5个配置文件.和一些必需的相关代码.. 我现在一一的贴上来吧: application-config.xml,主要是引入其它配置文件信息. &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;beans xmlns=&#34;http://www.springframework.org/schema/beans&#34; xmlns:security=&#34;http://www.springframework.org/schema/security&#34; xmlns:tx=&#34;http://www.springframework.org/schema/tx&#34; xmlns:aop=&#34;http://www.springframework.org/schema/aop&#34; xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xmlns:context=&#34;http://www.springframework.org/schema/context&#34; xsi:schemaLocation=&#34; http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd...]]></description>
			<content:encoded><![CDATA[<p>看到官方网上的视频做的例子是通过注解来实现.减少了配置文件代码.我觉得这功能非常不错,经过自已一些测试实验.最终做出点像样的东西了.0 0.额.<br />
下载了官方最新的BlazeDS.war.自已在里面添加了一些hibernate核心包及注解包.版本为.hbiernate3.spring3.flex4.添加了几个配置5个配置文件.和一些必需的相关代码..<br />
我现在一一的贴上来吧:<br />
<span id="more-432"></span><br />
application-config.xml,主要是引入其它配置文件信息.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:security=&quot;http://www.springframework.org/schema/security&quot;
	xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd&quot;&gt;

	&lt;import resource=&quot;flexconfig.xml&quot; /&gt;
	&lt;import resource=&quot;hibernateconfig.xml&quot; /&gt;
	&lt;import resource=&quot;daoconfig.xml&quot; /&gt;
	&lt;import resource=&quot;serviceconfig.xml&quot; /&gt;

&lt;/beans&gt;
</pre>
<p>daoconfig.xml:扫描Dao层包里有注解的类.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:security=&quot;http://www.springframework.org/schema/security&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;&gt;
	&lt;!--　自动扫描dao层有注解的类--&gt;
	&lt;context:component-scan base-package=&quot;dao&quot; /&gt;

&lt;/beans&gt;
</pre>
<p>serviceconfig.xml与dao层的配置文件一样.是扫描service层的</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:security=&quot;http://www.springframework.org/schema/security&quot;
	xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd&quot;&gt;

	&lt;!--　自动扫描service层有注解的类--&gt;
	&lt;context:component-scan base-package=&quot;service&quot; /&gt;
&lt;/beans&gt;
</pre>
<p>flexconfig.xml 对flex一些信息处理.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/flex

http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;

	&lt;flex:message-broker&gt;
		&lt;flex:remoting-service default-channels=&quot;my-amf&quot; /&gt;
	&lt;/flex:message-broker&gt;

	&lt;!--  启动注解的支持--&gt;
	&lt;bean
		class=&quot;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter&quot; /&gt;

&lt;/beans&gt;
</pre>
<p>hibernateconfig.xml:配置数据源及sessionFactory和事务处理.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:security=&quot;http://www.springframework.org/schema/security&quot;
	xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd&quot;&gt;

	&lt;!--　定义注解形式SessionFactory --&gt;
	&lt;bean id=&quot;sessionFactory&quot;
		class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
		&lt;!--　定义数据源文件　--&gt;
		&lt;property name=&quot;configLocation&quot; value=&quot;classpath:hibernate.cfg.xml&quot; /&gt;
		&lt;!--　定义扫描有Entity注解实体类　--&gt;
		&lt;property name=&quot;annotatedClasses&quot;&gt;
			&lt;list&gt;
				&lt;value&gt;entity.UserInfo&lt;/value&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;!--　配置事务管理　--&gt;
	&lt;bean id=&quot;txManager&quot;
		class=&quot;org.springframework.orm.hibernate3.HibernateTransactionManager&quot;&gt;
		&lt;property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot; /&gt;
	&lt;/bean&gt;
	&lt;tx:annotation-driven transaction-manager=&quot;txManager&quot; /&gt;
&lt;/beans&gt;
</pre>
<p>配置web.xml代码为:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;
&lt;web-app&gt;

	&lt;display-name&gt;FBS&lt;/display-name&gt;
	&lt;description&gt;BlazeDS Application&lt;/description&gt;

	&lt;context-param&gt;
		&lt;param-name&gt;flex.class.path&lt;/param-name&gt;
		&lt;param-value&gt;/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars&lt;/param-value&gt;
	&lt;/context-param&gt;

	&lt;!-- Http Flex Session attribute and binding listener support --&gt;
	&lt;listener&gt;
		&lt;listener-class&gt;flex.messaging.HttpFlexSession&lt;/listener-class&gt;
	&lt;/listener&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;RDSDispatchServlet&lt;/servlet-name&gt;
		&lt;display-name&gt;RDSDispatchServlet&lt;/display-name&gt;
		&lt;servlet-class&gt;flex.rds.server.servlet.FrontEndServlet&lt;/servlet-class&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;messageBrokerId&lt;/param-name&gt;
			&lt;param-value&gt;_messageBroker&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;useAppserverSecurity&lt;/param-name&gt;
			&lt;param-value&gt;false&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;load-on-startup&gt;10&lt;/load-on-startup&gt;
	&lt;/servlet&gt;

	&lt;!-- MessageBroker Servlet --&gt;
	&lt;servlet&gt;
		&lt;servlet-name&gt;MessageBrokerServlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;flex.messaging.MessageBrokerServlet&lt;/servlet-class&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;services.configuration.file&lt;/param-name&gt;
			&lt;param-value&gt;/WEB-INF/flex/services-config.xml&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;flex.write.path&lt;/param-name&gt;
			&lt;param-value&gt;/WEB-INF/flex&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
			&lt;param-value&gt;/WEB-INF/config/*-config.xml&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping id=&quot;RDS_DISPATCH_MAPPING&quot;&gt;
		&lt;servlet-name&gt;RDSDispatchServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/CFIDE/main/ide.cfm&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;MessageBrokerServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/messagebroker/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;!-- Map /spring/* requests to the DispatcherServlet --&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/messagebroker/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
		&lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

	&lt;!-- for WebSphere deployment, please uncomment --&gt;
	&lt;!--
		&lt;resource-ref&gt;
		&lt;description&gt;Flex Messaging WorkManager&lt;/description&gt;
		&lt;res-ref-name&gt;wm/MessagingWorkManager&lt;/res-ref-name&gt;
		&lt;res-type&gt;com.ibm.websphere.asynchbeans.WorkManager&lt;/res-type&gt;
		&lt;res-auth&gt;Container&lt;/res-auth&gt;
		&lt;res-sharing-scope&gt;Shareable&lt;/res-sharing-scope&gt;
	&lt;/resource-ref&gt;
	--&gt;

&lt;/web-app&gt;
</pre>
<p>以上的代码基本是通用的.只需修改上面的路径就可以了.通过web.xml里面定义的过滤器来调用application-config.xml即可.<br />
自已也修改了一份blazeds.war..添加了上面的信息..集成好了的.如果有需要的可以发我邮箱索要.因为20多M..上传到空间不忍心哈..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/flex_spring_hibernate.html/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Flex+Spring整合详细流程 绝对正常运行</title>
		<link>http://www.licream.net/flexspring.html/</link>
		<comments>http://www.licream.net/flexspring.html/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 18:44:41 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.licream.net/flexspring%e6%95%b4%e5%90%88%e8%af%a6%e7%bb%86%e6%b5%81%e7%a8%8b-%e7%bb%9d%e5%af%b9%e6%ad%a3%e5%b8%b8%e8%bf%90%e8%a1%8c.html/</guid>
		<description><![CDATA[经过二周反复的新建删除新建删除重复的工作.现在终于有点成果了.对flex不了解.用了这么长时间才把他们整合好了.哎..其间碰到各种问题,真是郁闷死. 先把flex+spring发上来吧.hibernate还没完美整合上来- -. 我用文档写好了.我就直接贴上来自已也算在这备份一次.HOHO 1. Flex +Spring整合方法 i. 准备工具Eclipse,BlazeDS,Spring,Tomcat. 1. 使用Eclipse3.5 +flex builder 4 pulgin+Spring3.0+Tomcat6.0+JDK6.0+ BlazeDS 2. 下载地址: 3. Flex...]]></description>
			<content:encoded><![CDATA[<p>经过二周反复的新建删除新建删除重复的工作.现在终于有点成果了.对flex不了解.用了这么长时间才把他们整合好了.哎..其间碰到各种问题,真是郁闷死. 先把flex+spring发上来吧.hibernate还没完美整合上来- -.</p>
<p>我用文档写好了.我就直接贴上来自已也算在这备份一次.HOHO</p>
<p>1. Flex +Spring整合方法</p>
<p>i. 准备工具Eclipse,BlazeDS,Spring,Tomcat.</p>
<p>  <span id="more-430"></span>
<p>1. 使用Eclipse3.5 +flex builder 4 pulgin+Spring3.0+Tomcat6.0+JDK6.0+ BlazeDS</p>
<p>2. 下载地址:</p>
<p>3. Flex Builder 4: http://www.adobe.com/</p>
<p>4. Eclipse: <a href="http://www.eclipse.org/downloads/">http://www.eclipse.org/downloads/</a></p>
<p>5. Spring3.0: <a href="http://www.springsource.org/download">http://www.springsource.org/download</a></p>
<p>6. Tomcat6.0: <a href="http://tomcat.apache.org/download-60.cgi">http://tomcat.apache.org/download-60.cgi</a></p>
<p>7. JDK6.0: <a href="http://java.sun.com/javase/downloads/index.jsp">http://java.sun.com/javase/downloads/index.jsp</a></p>
<p>2. 创建HelloWorld工程</p>
<p>i. 打开Eclipse,打开文件菜单,选择Flex项目.</p>
<p>3. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image002.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image002_thumb.jpg" width="191" height="244" /></a></p>
<p>4. 定义项目名称为HelloWorld.应用类型为j2ee web形式,远程服务选用BlazeDS(简洁又免费),我们是把flex+java项目整合在一个项目工程里面.所以要钩选:使用WTP创建java/flex组合项目.</p>
<p>5. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image004.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image004_thumb.jpg" width="224" height="244" /></a></p>
<p>6. 在目标运行时后面那按钮点开他新建一个Tomcat服务.选中Tomcat V6.0.然后完成.回到新建工程第二部,选择刚才建的tomcat服务名称.</p>
<p>7. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image006.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image006_thumb.jpg" width="244" height="209" /></a> <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image008.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image008_thumb.jpg" width="214" height="244" /></a></p>
<p>8. 指定blazeDS文件路径.在输入文件夹名称修改为:WebRoot与内容文件夹同名.,这样就可以完成了工程的创建!</p>
<p>9. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image010.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image010_thumb.jpg" width="208" height="244" /></a></p>
<p>10. 补充下,我使用的blazeDS是最新版.自带很多JAR包及spring3.0包..还有web.xml.项目已经建完了,我们还需要配置一下.双击服务器.把我们刚新建的工程添加到tomcat模块里.点确定.</p>
<p>11. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image012.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image012_thumb.jpg" width="244" height="73" /></a></p>
<p>12. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image014.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image014" border="0" alt="clip_image014" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image014_thumb.jpg" width="244" height="180" /></a></p>
<p>13. 再右键工程名打开属性: 在flex构建路径下的输出文件夹URL设置为:http://localhost:8080/项目名/.记得一定要在项目名后面加正斜杠.基本配置完成!</p>
<p>14. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image016.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image016" border="0" alt="clip_image016" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image016_thumb.jpg" width="244" height="232" /></a></p>
<p>15. 在项目WEB-INF目录下新建一个存放xml文件夹.主要用来存放spring,hibernate及其它扩展xml信息文件.方便管理而已,项目结构如下:</p>
<p>16. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image018.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image018" border="0" alt="clip_image018" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image018_thumb.jpg" width="219" height="244" /></a></p>
<p>17. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image020.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020" border="0" alt="clip_image020" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image020_thumb.jpg" width="125" height="244" /></a></p>
<p>18. 复制下面代码到application-config.xml(该文件负责的功能是spring配置信息)</p>
<pre class="brush: xml;"> 	&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; 	&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:security=&quot;http://www.springframework.org/schema/security&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;&gt;  	&lt;/beans&gt; </pre>
<p>22. 复制下面代码到dispatchservlet-config.xml文件里面(该文件负责blazeDS远程公开服务.采用注解方式,优点是减少xml的配置信息.)</p>
<pre class="brush: xml;"> 	&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; 	&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/flex

	http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;	 	&lt;/beans&gt; </pre>
<p>26. 现在我们建个java 类,命名为Test.</p>
<pre class="brush: java;"> 	@Service(&quot;test&quot;)  	@RemotingDestination(channels={&quot;my-amf&quot;}) 	public class Test { 	@RemotingInclude 	public String say(String name){ 	return &quot;欢迎加入&quot;+name; 		} </pre>
<p>31. 回到application-config.xml文件向里面添加这二条代码:</p>
<p>a) &lt;context:annotation-config /&gt;&lt;!&#8211; 隐式地向 Spring 容器注册 &#8211;&gt;</p>
<p>b) &lt;context:component-scan base-package=<i>&quot;test&quot;</i> /&gt;&lt;!&#8211; 自动扫描指定包目录下所有在注解代码的java类 &#8211;&gt;</p>
<p>32. 回到dispatchservlet-config.xml文件向里面添加这段代码:</p>
<p>i. &lt;flex:message-broker&gt;</p>
<p>1. &lt;flex:remoting-service default-channels=<i>&quot;my-amf&quot;</i> /&gt;</p>
<p>ii. &lt;/flex:message-broker&gt;</p>
<p>33. 回到web.xml文件.把里面的</p>
<p>34. &lt;param-name&gt;useAppserverSecurity&lt;/param-name&gt;</p>
<p>1. &lt;param-value&gt; false &lt;/param-value&gt;&lt;!&#8211; 改成false &#8211;&gt;这样可以不用密码来有使用数据服务.</p>
<p>35. 记录修改配置文件路径.</p>
<p>a) &lt;context-param&gt;</p>
<p>i. &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;</p>
<p>ii. &lt;param-value&gt;/WEB-INF/config/*-config.xml&lt;/param-value&gt;</p>
<p>b) &lt;/context-param&gt;</p>
<p>36. 运行之后不知为什么会提示没有flex-servlet.xml这个文件.那我就在web.xml同目录下新建一个好了哈.</p>
<p>37. 添加代码到该文件下:</p>
<pre class="brush: xml;"> 	&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; 	&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:flex=&quot;http://www.springframework.org/schema/flex&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/flex

	http://www.springframework.org/schema/flex/spring-flex-1.0.xsd&quot;&gt;  	&lt;/beans&gt; </pre>
<p>41. 其实可以把另二个配置文件的信息都加到这里面来.我前面已经配置好了.所以这个就空在这.留个备用.呵呵,具体看不出web.xml哪条信息要读取这文件的.不知是不是系统定义的.</p>
<p>42. 用Tomcat启动项目后,切换到flash工程环境下.在数据服务标签下有个连接数据/服务功能.使用他我们可以用blazeds对后台进行通信,钩选不需要密码.点下一步会出现如下错误. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image022.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image022" border="0" alt="clip_image022" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image022_thumb.jpg" width="244" height="71" /></a><a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image024.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image024" border="0" alt="clip_image024" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image024_thumb.jpg" width="244" height="61" /></a></p>
<p>43. 解决的办法:找到工程目录下的.flexProperties文件.修改上下文配置(意思大概是这样吧) serverContextRoot=&quot;/WebRoot&quot;修改为serverContextRoot=&quot;/HelloWorld&quot;.一定要改成项目名称.随后刷新工程.再连接数据服务.</p>
<p>44. 我们先来测试下能不能正常读到后右的数据.钩选要读取的信息.如多个类文件则会显示多个services配置信息名称.我们选中test.下面二条输入框为默认.</p>
<p>45. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image026.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image026" border="0" alt="clip_image026" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image026_thumb.jpg" width="238" height="244" /></a></p>
<p>46. 建好之后在数据服务标签栏上找到如下图标.来测试数据是否正常通信. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image028.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image028" border="0" alt="clip_image028" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image028_thumb.jpg" width="97" height="58" /></a></p>
<p>47. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image030.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image030" border="0" alt="clip_image030" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image030_thumb.jpg" width="237" height="244" /></a></p>
<p>48. 嗯,测试成功了.说明我们之前的配置信息是没有问题了.能正常跟后台通信了.</p>
<p>49. 接下来我们切换到flash视图环境下编辑mxml主文件.添加二个组件.一个输入框及文本组件.</p>
<p>50. 添加如下代码在非可视标签下&lt;:fx:Declarations&gt;</p>
<pre class="brush: xml;"> 	&lt;s:CallResponder id=&quot;sayResult&quot;/&gt; 	&lt;services:Test destination=&quot;test&quot;&gt;  &lt;!--要与java类名称一致--&gt; 	&lt;services:channelSet&gt; 	&lt;s:ChannelSet&gt; 	&lt;s:AMFChannel url=&quot;http://localhost:8080/HelloWorld/messagebroker/amf&quot;/&gt; 	&lt;/s:ChannelSet&gt; 	&lt;/services:channelSet&gt; 	&lt;/services:Test&gt;&lt;!--上面的写法有点别扭,但一定是要这样写的.--&gt; </pre>
<p>52. 接下来我们把数据绑定在组件上,最终代码如下.button纯属自已多余添加的可不看-..</p>
<p>53. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image032.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image032" border="0" alt="clip_image032" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image032_thumb.jpg" width="244" height="161" /></a></p>
<p>54. <a href="http://www.licream.net/wp-content/uploads/2010/07/clip_image034.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image034" border="0" alt="clip_image034" src="http://www.licream.net/wp-content/uploads/2010/07/clip_image034_thumb.jpg" width="244" height="204" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/flexspring.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>浅谈组件映射</title>
		<link>http://www.licream.net/one-many.html/</link>
		<comments>http://www.licream.net/one-many.html/#comments</comments>
		<pubDate>Tue, 04 May 2010 13:28:15 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://www.licream.net/%e6%b5%85%e8%b0%88%e7%bb%84%e4%bb%b6%e6%98%a0%e5%b0%84.html/</guid>
		<description><![CDATA[hibernate中的关联映射主要有三种:一对一,一对多(多对一),多对多.它们都 可以分为单向和双向双种. 凡是双向关联必设mappedBy 一对一关联映射有两种: 一种是主键关联:限制两个数据表的主键使用相同的值 一种是外键关联:是一个外键和一个惟一关键字对应 一对一不产生新的字段而多对一会产生新的字段 多对一关联映射：在多的一端加入一个外键指向一的一端，它维护的关系是多指向一 一对多关联映射：在多的一端加入一个外键指向一的一端，它维护的关系是一指向多 也就是说一对多和多对一的映射策略是一样的，只是站的角度不同]]></description>
			<content:encoded><![CDATA[<p>hibernate中的关联映射主要有三种:一对一,一对多(多对一),多对多.它们都 可以分为单向和双向双种.<br />
凡是双向关联必设mappedBy<br />
一对一关联映射有两种:<br />
一种是主键关联:限制两个数据表的主键使用相同的值<br />
一种是外键关联:是一个外键和一个惟一关键字对应<br />
一对一不产生新的字段而多对一会产生新的字段<br />
多对一关联映射：在多的一端加入一个外键指向一的一端，它维护的关系是多指向一<br />
一对多关联映射：在多的一端加入一个外键指向一的一端，它维护的关系是一指向多<br />
也就是说一对多和多对一的映射策略是一样的，只是站的角度不同</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/one-many.html/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>ID生成策略及Session用法</title>
		<link>http://www.licream.net/id-auto-session.html/</link>
		<comments>http://www.licream.net/id-auto-session.html/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 04:48:40 +0000</pubDate>
		<dc:creator>Licream</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://www.licream.net/id%e7%94%9f%e6%88%90%e7%ad%96%e7%95%a5%e5%8f%8asession%e7%94%a8%e6%b3%95.html/</guid>
		<description><![CDATA[看了点ID生成的xml配置和annotation配置,重点放在annotation上面.为了经后需要吧.在实体类里利用@GeneratedValue来的strategy属性对主键设置生成策略的类型.常用的就IDENTITY(ms sql,mysql)和SEQUENCE(oracle).配置联合主键得需要用到,@EmbeddedId. @GeneratedValue(strategy=GenerationType.IDENTITY) Session需要SessionFactory来产生和管理.通常只需要一个sessionfactory. 打开session有二种方法: opensession:每次都是新的,需要手动关闭session. getcurrentsession:从上下文找,如果有,用旧的,没有建新的,带自动关闭sesison. 对于自定义的hibernate配置xml可用configure(&#8220;hibernate.cfg.xml&#8221;)指定. get:直接从数据库加载,不会延迟 load:返回的是代理对偈.等真正用到对像的内容时才发出sql语句. 无论是load还是get都会首先查找缓存(一级缓存),如果没有,才会去数据库查找.调用clear()方法可以强制清除session缓存. 调用flush()方法可以强制进行从内存到数年据库的同步,merge()用来合并数据. 实操中遇到Field &#8216;id&#8217; doesn&#8217;t have a default value错误:在对ID设置好策略后ID也不自动递增.网上基本都是说修改my.ini.我没去试.后来我把表删表..就正常了- -!]]></description>
			<content:encoded><![CDATA[<p>看了点ID生成的xml配置和annotation配置,重点放在annotation上面.为了经后需要吧.在实体类里利用@GeneratedValue来的strategy属性对主键设置生成策略的类型.常用的就IDENTITY(ms sql,mysql)和SEQUENCE(oracle).配置联合主键得需要用到,@EmbeddedId.</p>
<p>@GeneratedValue(strategy=GenerationType.IDENTITY)</p>
<p>Session需要SessionFactory来产生和管理.通常只需要一个sessionfactory.</p>
<p>打开session有二种方法:</p>
<p>opensession:每次都是新的,需要手动关闭session.</p>
<p><span id="more-386"></span></p>
<p>getcurrentsession:从上下文找,如果有,用旧的,没有建新的,带自动关闭sesison.</p>
<p>对于自定义的hibernate配置xml可用configure(&#8220;hibernate.cfg.xml&#8221;)指定.</p>
<p>get:直接从数据库加载,不会延迟</p>
<p>load:返回的是代理对偈.等真正用到对像的内容时才发出sql语句.</p>
<p>无论是load还是get都会首先查找缓存(一级缓存),如果没有,才会去数据库查找.调用clear()方法可以强制清除session缓存.</p>
<p>调用flush()方法可以强制进行从内存到数年据库的同步,merge()用来合并数据.</p>
<p>实操中遇到Field &#8216;id&#8217; doesn&#8217;t have a default value错误:在对ID设置好策略后ID也不自动递增.网上基本都是说修改my.ini.我没去试.后来我把表删表..就正常了- -!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.licream.net/id-auto-session.html/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
