Dozer:更改字段名称策略
如您所知,dozer 使用相同的字段名称在两个 bean 之间进行映射,但是我如何简单地更改此映射策略。
public class Product {
private String productName;
public String getProductName(){
return productName;
}
public void setProductName(String productName){
this.productName = productName;
}
}
public class ProductTO {
private String PRODUCT_NAME;
public String getPRODUCT_NAME(){
return PRODUCT_NAME;
}
public void setPRODUCT_NAME(String PRODUCT_NAME){
this.PRODUCT_NAME = PRODUCT_NAME;
}
}
对于上面的情况,我不想定义映射文件,因为太多的字段和太多的TO,我只想更改默认的映射策略,并更新为如上所示:thisField = THIS_FIELD。 如果您有任何建议,谢谢。
As you know, dozer use same field name to mapping between two beans, but how can I just simple change this mapping strategy.
public class Product {
private String productName;
public String getProductName(){
return productName;
}
public void setProductName(String productName){
this.productName = productName;
}
}
public class ProductTO {
private String PRODUCT_NAME;
public String getPRODUCT_NAME(){
return PRODUCT_NAME;
}
public void setPRODUCT_NAME(String PRODUCT_NAME){
this.PRODUCT_NAME = PRODUCT_NAME;
}
}
For above case, I don't want to define a mapping file, because too much field and too much TO, I just want to change the default mapping strategy, and update to like above: thisField = THIS_FIELD.
Thanks if you have any suggestion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Dozer 不支持这一点。也许您可以在将来的版本中请求此功能。
Dozer doesn't support this. May be you can request this feature for future release.
你可以看看 Orika 它提供了类似的功能和更高级的方式来管理映射,高级映射
第二种方法是使用 MappingHints
MappingHint使用示例
You can look at Orika it provide similar feature and a more advanced way to manage mapping, Advanced Mapping
Second way to do that is to use MappingHints
Example of MappingHint usage