TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
下面是关于输入点转换为Point类的实例:-
- package com.test.converter;
- import java.util.Map;
- import org.apache.struts2.util.StrutsTypeConverter;
- import com.test.bean.Point;
- public class PointConverter2 extends StrutsTypeConverter {
- @Override
- public Object convertFromString(Map context, String[] values, Class toType) {
- Point point = new Point();
- String str = values[0];
- String[] strParameters = str.split(",");
-
- int x = Integer.parseInt(strParameters[0]);
- int y = Integer.parseInt(strParameters[1]);
-
- point.setX(x);
- point.setY(y);
- return point;
- }
- @Override
- public String convertToString(Map context, Object o) {
-
- Point point = (Point)o;
-
- int x = point.getX();
- int y = point.getY();
-
- String result = "[ x = "+x+" , y = "+y+" ]";
-
- return result;
- }
-
-
- }
复制代码 |
|