實體.hbm.xml文件中設置以下屬性,作用爲能夠動態修改
dynamic-insert=true
dynamic-update=true
格式化數據顯示:(配置文件)
package.proporties :
#number
format.money={0,number,#0.00#}
#date
date.format={0,date,yyyy-MM-dd HH:mm:ss}
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!--國際化配置 -->
<constant name="struts.custom.i18n.resources" value="package"/>
<package name="hang" namespace="/" extends="struts-default">
<!-- 查詢所有的商品信息 -->
<action name="good" class="com.hlx.action.GoodsAction">
<result>/list.jsp</result>
</action>
<!-- 下訂單 -->
<action name="add" class="com.hlx.action.GoodsAction" method="add">
<result>/add.jsp</result>
<result name="input" type="redirectAction">good.action</result>
</action>
<!-- 添加訂單 -->
<action name="save" class="com.hlx.action.GoodsAction" method="save">
<result>/show.jsp</result>
<result name="input" type="redirectAction">good.action</result>
</action>
</package>
</struts>
需要格式化的頁面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'show.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
* {
font-size: 14px;
}
div {
width: 1200px;
margin-left: 20px;
}
li {
width: 200px;
list-style: none;
float: left;
}
table {
clear: both;;
}
.bd {
font-weight: bolder;
}
span {
font-weight: bolder;
border-bottom: 2px solid black;
}
</style>
</head>
<body>
<center>
<div>
<ul>
<li>訂單號:<span><s:property value="orders.id" /> </span>
</li>
<li>收貨人:<span><s:property value="orders.name" /> </span>
</li>
<li>收貨地址:<span><s:property value="orders.address" /> </span>
</li>
<li>訂單日期:<span><s:text name="date.format">
<s:param value="orders.createtime"></s:param>
</s:text> </span>
</li>
</ul>
</div>
<table border="1" width="85%" height="150">
<tbody>
<tr align="center">
<td> 商品名稱</td>
<td> 價格</td>
<td> 數量</td>
<td> 金額</td>
</tr>
<s:iterator value="orders.orderitems">
<tr align="center">
<td><s:property value="goods.name" /></td>
<td>¥<s:text name="format.money">
<s:param value="goods.price"></s:param>
</s:text>
</td>
<td><s:property value="amount" /></td>
<td>¥<s:text name="format.money">
<s:param value="goods.price*amount"></s:param>
</s:text>
</td>
</tr>
</s:iterator>
<tr align="right">
<td colspan="4" class="bd">總金額: ¥<s:text name="format.money">
<s:param value="total"></s:param>
</s:text></td>
</tr>
</tbody>
</table>
</center>
</body>
</html>
語言轉化:
index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><s:text name="my.title"/></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<a href="china.action?request_locale=zh_CN">中文</a>
<a href="china.action?request_locale=en_US">英文</a>
<a href="china.action?request_locale=zh_TW">臺灣</a>
<s:form action="login" method="post">
<s:textfield name="uname" key="my.name" />
<s:password name="upass" key="my.pass" />
<s:submit name="sub" key="my.submit" />
<s:submit name="sub" key="my.register" />
</s:form>
</body>
</html>
package com.hlx.action;
import com.opensymphony.xwork2.ActionSupport;
public class ChinaAction extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 國際化配置 -->
<constant name="struts.custom.i18n.resources" value="message" />
<package name="hlx" namespace="/" extends="struts-default">
<action name="china" class="com.hlx.action.ChinaAction">
<result>/index.jsp</result>
</action>
</package>
</struts>
語言配置文件:
message_en_US.properties:
my.title=English Page
my.name=username
my.pass=userpass
my.submit=submit
my.register=register
my.title=\u4E2D\u6587\u9875\u9762
my.name=\u7528\u6237\u540D
my.pass=\u5BC6\u7801
my.submit=\u63D0\u4EA4
my.register=\u6CE8\u518C
message_zh_TW.properties:
my.title=\u7E41\u9AD4\u9801\u9762
my.name=\u7528\u6236\u540D
my.pass=\u5BC6\u78BC
my.submit=\u63D0\u4EA4
my.register=\u8A3B\u518A