|
The default time format of struts2 is yyyy-MM-dd, and to use the yyyyMMdd format, you need to write a format converter Partial:
Step 1: Write a time type converter that inherits from DefaultTypeConverter
[mw_shl_code=java,true]package utils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;
/** * @author Delver_Si
* */ public class DateConvert extends DefaultTypeConverter {
@Override public Object convertValue(Map<String, Object> context, Object value, Class toType) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
try { if(toType==Date.class){ String[] params = (String[]) value; return dateFormat.parseObject(params[0]); The first element in the array is the one to be transformed }else if (toType==String.class) { Date date = (Date) value; return dateFormat.format(date); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
} [/mw_shl_code]
![]()
Create the following format configuration file under the action package, with the Action name before -conversion.properties and the full path of the converter after the property
Big picture: The configuration file is modified as follows, placed in the src directory
|