参考 : https://blog.csdn.net/sinat_29774479/article/details/102745582
TestStruce 添加 uses=DateMapper.class
@Mapper(componentModel = "spring",uses=DateMapper.class)
public interface TestStruce {
DateMapper
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Component
public class DateMapper {
public String asString(Date date) {
return date != null ? new SimpleDateFormat("yyyy-MM-dd")
.format(date) : null;
}
public Date asDate(String date) {
try {
return date != null ? new SimpleDateFormat("yyyy-MM-dd")
.parse(date) : null;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
public Date asDate(Long date) {
try {
return new Date(date);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
END。