本文整理匯總了Java中org.thymeleaf.context.Context.setVariable方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.setVariable方法的具體用法?Java Context.setVariable怎麽用?Java Context.setVariable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.thymeleaf.context.Context
的用法示例。
在下文中一共展示了Context.setVariable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMembershipEmailHtml
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
public String getMembershipEmailHtml(User user) {
DateTimeFormatter formatter =
DateTimeFormatter.ISO_LOCAL_DATE
.withZone(ZoneId.of("Europe/Tallinn"));
Member member = user.getMemberOrThrow();
String memberDate = formatter.format(member.getCreatedDate());
Context ctx = new Context();
ctx.setVariable("memberNumber", member.getMemberNumber());
ctx.setVariable("firstName", user.getFirstName());
ctx.setVariable("lastName", user.getLastName());
ctx.setVariable("memberDate", memberDate);
ctx.setLocale(localeResolver.resolveLocale(request));
String htmlContent = templateEngine.process("membership", ctx);
return htmlContent;
}
示例2: sendEmailWithVerificationLinkAndLang
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public void sendEmailWithVerificationLinkAndLang(String xForwardedProto, String xForwardedHost, int xForwardedPort, String email, String emailToken, String recipientFullName, String language) {
Assert.hasText(emailToken, "emailToken must have text");
Assert.hasText(email, "email must have text");
Assert.hasText(recipientFullName, "recipientFullName must have text");
final String fragment = emailSenderProperties.getPpUiVerificationEmailTokenArgName() + "=" + emailToken;
final String verificationUrl = toPPUIVerificationUri(xForwardedProto, xForwardedHost, xForwardedPort, fragment);
final Context ctx = new Context();
ctx.setVariable(PARAM_RECIPIENT_NAME, recipientFullName);
ctx.setVariable(PARAM_LINK_URL, verificationUrl);
ctx.setVariable(PARAM_BRAND, emailSenderProperties.getBrand());
if (language == null || language.trim().isEmpty()) {
language = "en";
}
Locale locale = new Locale(language);
ctx.setLocale(locale);// set locale to support multi-language
sendEmail(ctx, email,
PROP_EMAIL_VERIFICATION_LINK_SUBJECT,
TEMPLATE_VERIFICATION_LINK_EMAIL,
PROP_EMAIL_FROM_ADDRESS,
PROP_EMAIL_FROM_PERSONAL,
locale);
}
示例3: sendForgotPasswordEmail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
/**
* <p>sendForgotPasswordEmail.</p>
*
* @param email a {@link java.lang.String} object.
* @param resetPwdURL a {@link java.lang.String} object.
*/
protected void sendForgotPasswordEmail(String email, String resetPwdURL) {
try {
// Prepare the evaluation context
final Context ctx = new Context(Locale.ENGLISH);
ctx.setVariable("resetPwdURL", resetPwdURL);
// Create the HTML body using Thymeleaf
final String htmlContent = this.templateEngine.process("forgot-password-email", ctx);
emailService.sendEmail(email, getMessage(LABEL_PASSWORD_RESET_EMAIL_SUBJECT), htmlContent);
} catch (SecuredAppException e) {
log.error(e.getMessage());
}
}
示例4: sendCreationEmail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendCreationEmail(User user, String baseUrl) {
log.debug("Sending creation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, baseUrl);
String content = templateEngine.process("creationEmail", context);
String subject = messageSource.getMessage("email.activation.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
示例5: sendCreationEmail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendCreationEmail(User user) {
log.debug("Sending creation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process("creationEmail", context);
String subject = messageSource.getMessage("email.activation.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
示例6: sendEmailFromTemplate
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process(templateName, context);
String subject = messageSource.getMessage(titleKey, null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
示例7: sendActivationEmail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendActivationEmail(User user, String baseUrl) {
log.debug("Sending activation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable("user", user);
context.setVariable("baseUrl", baseUrl);
String content = templateEngine.process("activationEmail", context);
String subject = messageSource.getMessage("email.activation.title", null, locale);
// sendEmail(user.getEmail(), subject, content, false, true);
sendMailToQueue(user.getEmail(), subject, content, false, true);
}
示例8: sendTemplateMail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
/**
* 測試 使用模板發送郵件
*/
@Test
public void sendTemplateMail() {
//創建郵件正文
Context context = new Context();
context.setVariable("id", "77451733");
String emailContent = templateEngine.process("emailTemplate", context);
mailService.sendHtmlMail("[email protected]", "test mail", emailContent);
}
示例9: sendEmailFromTemplate
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, baseUrlValue);
String content = templateEngine.process(templateName, context);
sendEmail(user.getEmail(), "sample title", content, false, true);
}
示例10: sendPasswordResetMail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendPasswordResetMail(User user, String baseUrl) {
log.debug("Sending password reset e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable("user", user);
context.setVariable("baseUrl", baseUrl);
String content = templateEngine.process("passwordResetEmail", context);
String subject = messageSource.getMessage("email.reset.title", null, locale);
// sendEmail(user.getEmail(), subject, content, false, true);
sendMailToQueue(user.getEmail(), subject, content, false, true);
}
示例11: sendPasswordResetMail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendPasswordResetMail(User user) {
log.debug("Sending password reset e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process("passwordResetEmail", context);
String subject = messageSource.getMessage("email.reset.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
示例12: sendTemplateMail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
/**
* 發送模版郵件
* @param sender
* @param sendto
* @param templateName
* @param o
*/
@Async
public void sendTemplateMail(String sender, String sendto,String title, String templateName,Object o) {
log.info("開始給"+sendto+"發送郵件");
MimeMessage message = mailSender.createMimeMessage();
try {
//true表示需要創建一個multipart message html內容
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(sender);
helper.setTo(sendto);
helper.setSubject(title);
Context context = new Context();
context.setVariable("title",title);
context.setVariables(StringUtils.beanToMap(o));
//獲取模板html代碼
String content = templateEngine.process(templateName, context);
helper.setText(content, true);
mailSender.send(message);
log.info("給"+sendto+"發送郵件成功");
}catch (Exception e){
e.printStackTrace();
}
}
示例13: sendSocialRegistrationValidationEmail
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Async
public void sendSocialRegistrationValidationEmail(User user, String provider) {
log.debug("Sending social registration validation e-mail to '{}'", user.getEmail());
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable("provider", StringUtils.capitalize(provider));
String content = templateEngine.process("socialRegistrationValidationEmail", context);
String subject = messageSource.getMessage("email.social.registration.title", null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
示例14: sendAlert
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
public boolean sendAlert(AlertEntry alertEntry, List<String> emails, String mailTemplate){
logger.debug("Sending alert e-mail to '{}'", emails.toString());
Locale locale = Locale.getDefault();
Context context = new Context(locale);
context.setVariable("alert", alertEntry);
String content = templateEngine.process(mailTemplate, context);
return sendEmail(mailFromBpo, emails, "New Application ticket has been created", content);
}
示例15: getContext
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public IContext getContext() {
final Context ctx = new Context();
ctx.setVariable("now", new Date());
ctx.setVariable("name", "Name Surname");
ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));
return ctx;
}