Spring Cloud Spring Boot mybatis distributed microservices Cloud architecture-Developing Web Applications 2

Source: Internet
Author: User

After the configuration is complete, take a simple example, based on the QuickStart project, to give a simple example to render a page with Thymeleaf

@Controller  public class HelloController {      @RequestMapping("/")      public String index(ModelMap map) {          // 加入一个属性,用来在模板中读取          map.addAttribute("host", "http://blog.didispace.com");          // return模板文件的名称,对应src/main/resources/templates/index.html          return "index";        }  }  
<!DOCTYPE html>  

As on the page, open the HTML page directly to show Hello World, but after launching the program, access to http://localhost:8080/, is to display the controller in the value of the host:/HTTP Blog.didispace.com, the logical separation of data without destroying the contents of HTML itself.

For more Thymeleaf page syntax, please also visit the THYMELEAF Official document query for use.

Default parameter configuration for Thymeleaf

If you need to modify the default configuration, just copy the following to modify the properties to application.properties, and modify the required values, such as modifying the template file extension, modify the default template path and so on.

  # Enable template caching. Spring.thymeleaf.cache=true # Check The templates location exists. Spring.thymeleaf.check-template-location=true # Content-type value. spring.thymeleaf.content-type=text/html # Enable MVC thymeleaf View resolution. Spring.thymeleaf.enabled=true # Template encoding. Spring.thymeleaf.encoding=utf-8 # comma-separated List of view names that should is excluded from resolution. spring.thymeleaf.excluded-view-names= # Template mode to is applied to templates. See also Standardtemplatemodehandlers. SPRING.THYMELEAF.MODE=HTML5 # Prefix that gets prepended to view names when building a URL. spring.thymeleaf.prefix=classpath:/templates/# Suffix that gets appended to view names when building a URL. Spring.thymeleaf.suffix=.html spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain. spring.thymeleaf.view-names= # comma-separated List of view names that can is resolved. 

Spring Cloud Spring Boot mybatis distributed microservices Cloud architecture-Developing Web Applications 2

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.