当前位置: 首页>>代码示例>>Java>>正文


Java Context.setVariables方法代码示例

本文整理汇总了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;
}
 
开发者ID:mattpwest,项目名称:entelect-spring-webapp-template,代码行数:18,代码来源:MailSenderImpl.java

示例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;
}
 
开发者ID:baratine,项目名称:baratine,代码行数:26,代码来源:ViewThymeleaf.java

示例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");
	}
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:21,代码来源:ThymeleafTemplateEngine.java

示例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();
    }
}
 
开发者ID:Exrick,项目名称:xpay,代码行数:34,代码来源:EmailUtils.java

示例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);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:15,代码来源:WordprocessingMLThymeleafTemplate.java

示例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);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:27,代码来源:TemplateRepresentation.java

示例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);
}
 
开发者ID:LeonHartley,项目名称:Coerce,代码行数:8,代码来源:ThymeleafViewParser.java

示例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");
  }
}
 
开发者ID:airbnb,项目名称:reair,代码行数:15,代码来源:ThymeleafTemplateEngine.java

示例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);
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:8,代码来源:ThymeleafTemplateProcessorImpl.java

示例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);
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:7,代码来源:ThymeleafTemplateService.java

示例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();
	}
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:49,代码来源:EmailServiceImpl.java

示例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 );
}
 
开发者ID:purplejs,项目名称:purplejs,代码行数:7,代码来源:ThymeleafServiceImpl.java


注:本文中的org.thymeleaf.context.Context.setVariables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。