来人啊啊啊啊啊
public void execute(){
List query=mailDao.MailQuery();
if(query==null){
System.out.println("no one book");
}else{
try{
System.out.println("正在发送邮件");
Properties props=new Properties();
props.put("mail.smtp.host","smtp.163.com");
props.put("mail.smtp.auth","true");
Session s=Session.getInstance(props);
s.setDebug(true);
MimeMessage message=new MimeMessage(s);
InternetAddress from=new InternetAddress("**");
message.setFrom(from);
InternetAddress to=new InternetAddress("**");
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject("test");
message.setSentDate(new Date());
BodyPart mdp=new MimeBodyPart();
mdp.setContent("success","text/html;charset=utf-8");
Multipart mm=new MimeMultipart();
mm.addBodyPart(mdp);
message.setContent(mm);
message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect("smtp.163.com","**","**");
transport.sendMessage(message,message.getAllRecipients());
transport.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public MailDao getMailDao() {
return mailDao;
}
public void setMailDao(MailDao mailDao) {
this.mailDao = mailDao;
}
}
加入dao层查询返回的数据作判断就无法发送了,为什么呢,dao层已经spring注入了
------解决方案--------------------你的action是如何管理的,交给spring管理了?