package controller; import javax.swing.JOptionPane; public abstract class BaseController { protected void validateNotNull(Object obj, String fieldName) { if (obj == null) { throw new IllegalArgumentException(fieldName + "不能为空"); } } protected void validateStringNotEmpty(String str, String fieldName) { if (str == null || str.trim().isEmpty()) { throw new IllegalArgumentException(fieldName + "不能为空"); } } protected void validateStringLength(String str, String fieldName, int min, int max) { validateStringNotEmpty(str, fieldName); if (str.length() < min || str.length() > max) { throw new IllegalArgumentException(fieldName + "长度应在" + min + "-" + max + "之间"); } } protected void showError(String message) { JOptionPane.showMessageDialog(null, message, "错误", JOptionPane.ERROR_MESSAGE); } protected void showSuccess(String message) { JOptionPane.showMessageDialog(null, message, "成功", JOptionPane.INFORMATION_MESSAGE); } protected void logInfo(String message) { //System.out.println("ℹ️ " + message); } protected void logError(String message) { System.err.println("❌ " + message); } }