37 lines
922 B
Java
37 lines
922 B
Java
package com.ecep.contract.converter;
|
|
|
|
import com.ecep.contract.service.DepartmentService;
|
|
import com.ecep.contract.vo.DepartmentVo;
|
|
import javafx.util.StringConverter;
|
|
|
|
/**
|
|
* 部门字符串转换器
|
|
*/
|
|
public class DepartmentStringConverter extends StringConverter<DepartmentVo> {
|
|
private DepartmentService service;
|
|
|
|
public DepartmentStringConverter() {
|
|
|
|
}
|
|
|
|
public DepartmentStringConverter(DepartmentService service) {
|
|
this.service = service;
|
|
}
|
|
|
|
@Override
|
|
public String toString(DepartmentVo department) {
|
|
if (department == null) {
|
|
return "-";
|
|
}
|
|
return department.getCode() + " " + department.getName();
|
|
}
|
|
|
|
@Override
|
|
public DepartmentVo fromString(String string) {
|
|
if (service == null || string == null || string.trim().isEmpty()) {
|
|
return null;
|
|
}
|
|
return service.findByCode(string.trim());
|
|
}
|
|
|
|
} |