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 { 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()); } }