SpringBoot2.x整合模板引擎freemarker
作者:互联网
代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> 这是小滴课堂 freemaker整合index.html页面 <h1>payAppid ${setting}</h1> </body> </html> package com.example.Maven.Project.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import java.io.Serializable; @Configuration @PropertySource(value="classpath:pay.properties") public class WXConfig implements Serializable { @Value("${wxpay.appid}") private String payAppid; @Value("${wxpay.secret}") private String paySecret; @Value("${wxpay.mechid}") private String payMechId; public String getPayAppid() { return payAppid; } public void setPayAppid(String payAppid) { this.payAppid = payAppid; } public String getPaySecret() { return paySecret; } public void setPaySecret(String paySecret) { this.paySecret = paySecret; } public String getPayMechId() { return payMechId; } public void setPayMechId(String payMechId) { this.payMechId = payMechId; } } package com.example.Maven.Project.controller; import com.example.Maven.Project.config.WXConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Controller @RequestMapping("tpl") public class FreeMarkerController { @Autowired private WXConfig wxConfig; @GetMapping("freemaker") public String index1(ModelMap modelMap){ modelMap.addAttribute("setting",wxConfig); //不用加后缀,因为配置文件里面已经指定了后缀 return "fm/index"; } } #微信支付的appid wxpay.appid=w23432432432 #支付秘钥 wxpay.secret=sfwerefwefqwed #微信支付商户号 wxpay.mechid=324324
标签:String,freemarker,springframework,annotation,SpringBoot2,org,import,public,模板 来源: https://www.cnblogs.com/aluoluo/p/15915632.html