当我使用 File.exists 检查时它是“真的”,但是当我使用 Template t = ve.getTemplate(pathContent); 我收到 ResourceNotFoundException 错误。为什么会这样,
我的 EmailSender 类:
public class EmailSender {
public static boolean send(String to, String newUsername, String newPassword, String contentPath) {
try{
.......................
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
context.put("username", newUsername);
context.put("password", newPassword);
Template t = ve.getTemplate(contentPath);
StringWriter writer = new StringWriter();
t.merge( context, writer );
System.out.println(writer.toString());
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
我尝试在我的服务类中传递真实路径
public class UserServiceImpl {
public ResultDto sendNotifEmail(Users user) {
try{
String emailFormatPath = context.getRealPath("emailFormat");
if(!EmailSender.send(user.getEmail(), user.getUsername(), password, emailFormatPath+"\\emailFormat.vm")){
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
谢谢