Spring Boot? Render a Web view using the Freemarker template engine

Source: Internet
Author: User
Tags locale

Code

?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 666768697071 package com.wls.integrateplugs.hello.controller;/** * Created by wls on 2017/8/24. */import java.util.Locale;import java.util.UUID;import javax.servlet.http.HttpSession;import com.sun.org.apache.regexp.internal.RE;import org.springframework.ui.Model;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.servlet.ModelAndView;import springfox.documentation.annotations.ApiIgnore;@RestControllerpublic class HelloController {    @RequestMapping(value = "/hello",method = RequestMethod.GET)    public String hello(Locale locale, Model model) {        return "hello world";    }     @RequestMapping("/helloWorld")    public String index() {        return "Hello World";    }    /**     * 使用@RestController时,则使用ModelAndView显示页面     * @param map     * @return     */    @ApiIgnore    @RequestMapping(value = "/helloThymeleaf",method = RequestMethod.GET)    public ModelAndView indexThymeleaf(ModelMap map) {        ModelAndView mv = new ModelAndView("indexThymeleaf");        map.addAttribute("name","王老师");        map.addAttribute("host", "http://blog.didispace.com");        return mv;    }    @RequestMapping(value = "/helloFreeMarker",method = RequestMethod.GET)    public ModelAndView indexFreeMarker(ModelMap map) {        ModelAndView mv = new ModelAndView("indexFreeMarker");        map.addAttribute("name","王老师");        map.addAttribute("host", "http://blog.didispace.com");        return mv;    }    /**     * 共享session     * @param session     * @return     */    @RequestMapping(value = "/uid",method = RequestMethod.GET)    String uid(HttpSession session) {        UUID uid = (UUID) session.getAttribute("uid");        if (uid == null) {            uid = UUID.randomUUID();        }        session.setAttribute("uid", uid);        return session.getId();    }}

Indexfreemarker.ftl

?
1234567891011 <!DOCTYPE html>"en">    <meta charset="UTF-8"/>    <title></title><body>FreeMarker模板引擎</body>

  

?
12345 <!--    freemarker      -->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-freemarker</artifactId>        </dependency>

  

Spring Boot? Rendering a Web View using the Freemarker template engine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.