@Component
public class ErrorMessage{
private ErrorMessage{
}
private final static Properties PROPERTIES = getProperties();
private static Properties getProperties(){
InputStream resourceAsStream = ErrorMessage.class.getClassLoader().getResourceAsStream("errorMessage.properties");
Properties properties = new Properties();
try{
Assert.notNull(resourceAsStream,"errorMessage.properties文件不存在");
properties.load(new InputStreamReader(resourceAsStream,StandardCharsets.UTF_8));
}catch(IOEException e){
e.printStackTrace();
}
return properties;
}
public static String getMessage(String code){
return PROPERTIES.getProperty(code);
}
}
errorMessage.properties文件
9999=代码有误
9998=参数有误
9997=数组越界