You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
double_project/src/controller/BaseController.java

42 lines
1.3 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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