本文整理汇总了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 );
}