struts2 内置的类型转换(10)
2017-05-26 21:57
288 查看
类型转换
例子介绍:test,jsp:
<%-- Created by IntelliJ IDEA. User: Alex Date: 2017/5/24 Time: 23:07 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>类型转换测试</title> </head> <body> name:<s:property value="name" /> <br/> age: <s:property value="age" /> </body> </html>struts.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="test" namespace="/" extends="struts-default"> <action name="test" class="com.alex.action.testAction"> <result>/test.jsp</result> </action> </package> </struts>testAction.java:
package com.alex.action; import com.opensymphony.xwork2.ActionSupport; /** * Created by Alex on 2017/5/24. */ public class testAction extends ActionSupport { private String name; private int age; @Override public String execute() throws Exception{ return super.execute(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }非常简单的一个环境,运行后是这样子的:
在此时已经发生类型转换了.所谓类型转换就是把字符串与特定类型相互转换,
接下来我们在action里添加一个日期的变量:
package com.alex.action; import com.opensymphony.xwork2.ActionSupport; import java.util.Date; /** * Created by Alex on 2017/5/24. */ public class testAction extends ActionSupport { private String name; private int age; private Date d; public Date getD() { return d; } public void setD(Date d) { this.d = d; } @Override public String execute() throws Exception{ return super.execute(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }在前端使用<s:date>标签对日期类型进行转换,
<%-- Created by IntelliJ IDEA. User: Alex Date: 2017/5/24 Time: 23:07 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>类型转换测试</title> </head> <body> name:<s:property value="name" /> <br/> age: <s:property value="age" /><br/> date: <s:property value="d"/><br/> <s:date format="yyyy/MM/dd HH:mm:ss" name="d" /> </body> </html>可以看到如下效果:
相关文章推荐
- Struts2-10 类型转换
- java学习笔记(六)----对象的类型转换, 匿名内置类
- Struts2学习:类型转换篇
- struts2 类型转换流程
- Struts2.1笔记(六):Struts2的 类型转换(续)
- Struts2.1笔记(五):Struts2的类型转换
- 用标准C++进行string与各种内置类型数据之间的转换
- Struts2之类型转换
- 用标准c++进行string与各种内置数据类型的转换
- struts2的一些用法(二):类型转换
- Struts2的类型转换器
- struts2的类型转换
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- Struts2入门-类型转换补充
- 用标准C++进行string与各种内置类型数据之间的转换
- struts2日期类型转换
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- Struts2学习笔记5:Struts2类型转换续二
- 如何将 10 字节 Long 类型的值的 Double 转换为 8 字节 Double
- C++内置类型对象转换