카테고리 없음
dto String -> 포멧설정
별지킴Lee
2023. 11. 21. 15:56
@Data
public class testDto {
private String mobile_phone; // 휴대폰번호
private String biz_no; // 사업자번호
private String qty; // 물량
private String fee; // 요금
private String from_date; // 시작일
private String to_date; // 종료일
public void setFrom_date(String from_date){
this.from_date = from_date;
if(!StringUtils.isEmpty(this.from_date)){
try {
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy.MM.dd");
Date date = inputFormat.parse(this.from_date);
this.from_date = outputFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void setTo_date(String to_date){
this.to_date = to_date;
if(!StringUtils.isEmpty(this.to_date)){
try {
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy.MM.dd");
Date date = inputFormat.parse(this.to_date);
this.to_date = outputFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void setQty(String qty) {
this.qty = qty;
if(!StringUtils.isEmpty(this.qty)){
try {
int qty_int = Integer.parseInt(qty);
this.qty = String.format("%,d", qty_int);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void setFee(String fee) {
this.fee = fee;
if(!StringUtils.isEmpty(this.fee)){
try {
int fee_int = Integer.parseInt(fee);
this.fee = String.format("%,d", fee_int);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void setBiz_no(String biz_no) {
this.biz_no = biz_no;
if(!StringUtils.isEmpty(this.biz_no)){
try {
String regEx = "([0-9]{3})-?([0-9]{2})-?([0-9]{5})";
this.biz_no = biz_no.replaceAll(regEx, "$1-$2-$3");
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void setMobile_phone(String mobile_phone) {
this.mobile_phone = mobile_phone;
if(!StringUtils.isEmpty(this.mobile_phone)){
try {
String regEx = "(\\d{3})(\\d{3,4})(\\d{4})";
this.mobile_phone = mobile_phone.replaceAll(regEx, "$1-$2-$3");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}