Struts2 关于StrutsTypeConvert怎么转换DomainModel
最近看了很多大侠的文章,关于Action字段或者是对于类的整体转换的转换的很多
比如
public class User { private int id; private String name; //... } public class UserAction extends ActionSupport { User user public String execute() { return SUCCESS; } //..getter and setter } 当你想对user中的字段id进行转换时
要是你使用如下的配置文件
UserAction-conversion.properties
user.id = com.xxx.youIdConvert
我试验了很多次 要是使用这样的配置 那么 convertFromString()的方法会被调用
也就是说id会被正确的转换成int
但是 convertToString 方法却不会被调用 即使使用OGNL表达式也不行
必须要进行如下的配置
不需要UserAction-conversion.properties文件
配置一个 User-conversion.properties
id=com.xxx.myIdConvert