本文整理匯總了Java中org.thymeleaf.context.Context.setVariables方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.setVariables方法的具體用法?Java Context.setVariables怎麽用?Java Context.setVariables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.thymeleaf.context.Context
的用法示例。
在下文中一共展示了Context.setVariables方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createMailContext
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
private Context createMailContext(Email mail, boolean isEmail) throws MailSendingException {
Map<String, Object> model;
try {
model = convertValueObjectJsonToMap(mail.getDataJson());
if(isEmail){
model.put("emailTemplate",true);
}
} catch (Exception ex) {
String message = String.format("Failed to send mail. Could not deserialize data JSON: %s", mail.getDataJson());
log.debug(message, ex);
throw new MailSendingException(message, ex);
}
Context context = new Context();
context.setVariables(model);
return context;
}
示例2: render
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public boolean render(RequestWeb req, View view)
{
String viewName = view.name();
if (! viewName.endsWith(".html")) {
return false;
}
try {
Context ctx = new Context();
ctx.setVariables(view.map());
req.type("text/html; charset=utf-8");
_engine.process(viewName, ctx, req.writer());
req.ok();
}
catch (Exception e) {
req.fail(e);
}
return true;
}
示例3: render
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
/**
* Process the specified template (usually the template name).
* Output will be written into a String that will be returned from calling this method,
* once template processing has finished.
*
* @param modelAndView model and view
* @param locale A Locale object represents a specific geographical, political, or cultural region
* @return processed template
*/
public String render(ModelAndView modelAndView, Locale locale) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Context context = new Context(locale);
context.setVariables((Map<String, Object>) model);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
示例4: 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();
}
}
示例5: process
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public WordprocessingMLPackage process(Map<String, Object> variables) throws Exception {
// 創建模板輸出內容接收對象
StringWriter output = new StringWriter();
//設置上下文參數
Context ctx = new Context();
ctx.setVariables(variables);
// 使用Thymeleaf模板引擎渲染模板
getEngine().process(templateKey , ctx , output);
//獲取模板渲染後的結果
String html = output.toString();
//使用HtmlTemplate進行渲染
return new WordprocessingMLHtmlTemplate(html , altChunk).process(variables);
}
示例6: setDataModel
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
/**
* Sets the template's data model from a request/response pair. This default
* implementation uses a Resolver.
*
* @see Resolver
* @see Resolver#createResolver(Request, Response)
*
* @param request
* The request where data are located.
* @param response
* The response where data are located.
*/
public void setDataModel(Request request, Response response) {
Map<String, Object> valuesMap = new LinkedHashMap<>();
Form form = new Form(request.getEntity());
for (NamedValue<String> param : form) {
if (!valuesMap.containsKey(param.getName())) {
valuesMap.put(param.getName(), param.getValue());
}
}
Context ctx = new Context(locale);
ctx.setVariables(valuesMap);
setContext(ctx);
}
示例7: render
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public String render(String view, Map<String, Object> model) {
Context context = new Context();
context.setVariables(model);
return templateEngine.process(view, context);
}
示例8: render
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<String, ?> modelMap = (Map<String, ?>) model;
Context context = new Context();
context.setVariables(modelMap);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
示例9: process
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public String process(String templateName, Map<String, Object> variables)
throws TemplateException {
final Context context = new Context();
context.setVariables(variables);
return templateEngine.process(templateName, context);
}
示例10: generateFromContext
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public String generateFromContext(Map<String, Object> mailContext, String template) {
Context ctx = new Context();
ctx.setVariables(mailContext);
return engine.process(template, ctx);
}
示例11: send
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
@Override
public ServiceResponse<Status> send(String sender,
List<User> recipients,
List<User> recipientsCopied,
String subject,
String templateName,
Map<String, Object> templateParam,
Locale locale) {
try {
if (!Optional.ofNullable(sender).isPresent() || sender.isEmpty()) {
return ServiceResponseBuilder.<Status>error().withMessage(Validations.SENDER_NULL.getCode()).build();
}
if (!Optional.ofNullable(recipients).isPresent() || recipients.isEmpty()) {
return ServiceResponseBuilder.<Status>error().withMessage(Validations.RECEIVERS_NULL.getCode()).build();
}
if (!Optional.ofNullable(subject).isPresent() || subject.isEmpty()) {
return ServiceResponseBuilder.<Status>error().withMessage(Validations.SUBJECT_EMPTY.getCode()).build();
}
if (!Optional.ofNullable(templateName).isPresent() || templateName.isEmpty()) {
return ServiceResponseBuilder.<Status>error().withMessage(Validations.BODY_EMPTY.getCode()).build();
}
final Context ctx = new Context(locale);
ctx.setVariables(templateParam);
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.setSubject(subject);
message.setFrom(sender);
message.setTo(recipients.stream().map(r -> r.getEmail()).collect(Collectors.toList()).toArray(new String[0]));
if (Optional.ofNullable(recipientsCopied).isPresent()) {
message.setCc(recipientsCopied.stream().map(r -> r.getEmail()).collect(Collectors.toList()).toArray(new String[0]));
}
final String htmlContent = this.templateEngine.process(templateName, ctx);
message.setText(htmlContent, true);
this.mailSender.send(mimeMessage);
return ServiceResponseBuilder.<Status>ok().build();
} catch (MessagingException e) {
return ServiceResponseBuilder.<Status>error()
.withMessage(e.getMessage())
.build();
}
}
示例12: doRender
import org.thymeleaf.context.Context; //導入方法依賴的package包/類
private String doRender( final ResourcePath view, final Map<String, Object> model )
{
final Context context = new Context();
context.setVariables( model );
return this.engine.process( view.toString(), context );
}