Java解析属性配置文件并给占位符传参
来源:互联网 发布:最火淘宝店铺 编辑:程序博客网 时间:2024/06/05 23:40
//注册功能
public void register(User user){
//补齐数据
user.setUid(CommonUtils.uuid());
user.setStatus(false);
user.setActivationCode(CommonUtils.uuid() + CommonUtils.uuid());
try {
userDao.save(user);
} catch (Exception e) {
throw new RuntimeException();
}
//发送邮件
//加载配置文件
Properties properties = new Properties();
try {
properties.load(this.getClass().getClassLoader().getResourceAsStream("email_template.properties"));
} catch (IOException e1) {
throw new RuntimeException();
}
String host = properties.getProperty("host");
String username = properties.getProperty("username");
String password = properties.getProperty("password");
String from = properties.getProperty("from");
String to = user.getEmail();
String subject = properties.getProperty("subject");
//把占位符用后面的参数替换,后面参数可变
try {
MailUtils.send(session, mail);
} catch (Exception e) {
throw new RuntimeException();
}
}
public void register(User user){
//补齐数据
user.setUid(CommonUtils.uuid());
user.setStatus(false);
user.setActivationCode(CommonUtils.uuid() + CommonUtils.uuid());
try {
userDao.save(user);
} catch (Exception e) {
throw new RuntimeException();
}
//发送邮件
//加载配置文件
Properties properties = new Properties();
try {
properties.load(this.getClass().getClassLoader().getResourceAsStream("email_template.properties"));
} catch (IOException e1) {
throw new RuntimeException();
}
String host = properties.getProperty("host");
String username = properties.getProperty("username");
String password = properties.getProperty("password");
String from = properties.getProperty("from");
String to = user.getEmail();
String subject = properties.getProperty("subject");
//把占位符用后面的参数替换,后面参数可变
String content = MessageFormat.format(properties.getProperty("content"), user.getActivationCode());
//发送邮件3步曲
Session session = MailUtils.createSession(host, username, password);
try {
MailUtils.send(session, mail);
} catch (Exception e) {
throw new RuntimeException();
}
}
阅读全文
0 0
- Java解析属性配置文件并给占位符传参
- MyBatis配置文件属性解析
- spring+mybatis 配置文件占位符不能解析的问题
- java工程如何读取配置文件并获取配置文件中的属性值
- mybatis配置文件(mapper)属性解析
- java读写属性配置文件
- java读取配置文件属性
- JAVA 读取属性配置文件
- Java读取属性配置文件
- java解析json中的所有属性并返回
- Java使用PropertyDescriptor获取实体类中私有属性的值,并给私有属性赋值
- java反射动态给对象属性赋值,并获取属性值
- spring配置文件<import>标签中使用${}占位符获得配置文件的属性值
- spring配置文件<import>标签中使用${}占位符获得配置文件的属性值
- JAVA配置文件解析
- java解析properties配置文件
- 通过java反射机制来获取属性的类型,获取属性的值并给属性赋值
- 系统配置帮助类,用于解析属性配置文件。
- Coursera machine learning week 6(一)
- 3章 文件I/O
- 简单排序
- 航院 6213 Chinese Zodiac
- 增加测试函数计算排序函数运行时间
- Java解析属性配置文件并给占位符传参
- Apache XBean 简单介绍
- Linux使用-小程序hello world
- 【总结】--机房合作--界面
- Request对象的主要方法
- anaconda详解
- webservice实现步骤
- SE homework 1
- JavaWeb