First, Spring boot primer (web+freemarker)

Source: Internet
Author: User

1. Configuring MAVEN Files Pom.xml

<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupId>Com.hdwang</groupId>    <Artifactid>Spring-boot-test</Artifactid>    <version>1.0-snapshot</version>    <name>Spring-boot-test</name>    <Description>Project for Test Spring Boot</Description>    <Properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <java.version>1.8</java.version>    </Properties>    <!--Inherit defaults from Spring Boot -    <Parent>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-parent</Artifactid>        <version>1.5.4.RELEASE</version>        <RelativePath/>    </Parent>    <Dependencies>        <!--Add Typical dependencies for a Web application -        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-web</Artifactid>        </Dependency>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-freemarker</Artifactid>        </Dependency>        <!--Auto Redeploy -        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-devtools</Artifactid>            <Optional>True</Optional>        </Dependency>    <!--Package as an executable jar -    <Build>        <Plugins>            <plugin>                <groupId>Org.springframework.boot</groupId>                <Artifactid>Spring-boot-maven-plugin</Artifactid>            </plugin>        </Plugins>    </Build></Project>

2. The file structure (the name of the Static/templates/application.properties/logback.xml is all agreed, you can use only a few names, refer to the Spring Boot official documentation, The following name is one of the configuration methods)

3. Create a startup class (the class that is placed on the top level, sub-layer (subordinate folder) can be scanned for injection)

@SpringBootApplication  Public class Application {    /**     * Main function     @param  args params      *    /publicstaticvoid  main (string[] args) {       Springapplication.run (Application. class , args);}    }

4. Create a controller (in the subordinate directory of the Application class)

@Controller @requestmapping ("/common") Public classCommon {@Value ("${msg:welcome!}")    PrivateString msg; /*** Get a page *@returna page with name called return value*/@RequestMapping ("Login")     PublicString getloginpage (Modelmap map) {Map.put ("Welcomemsg", This. msg); return"Login"; }}

5. Create a Web Template LOGIN.FTL (Freemarker must use the FTL suffix, which has been this pit for a long time!) Js/css what are placed in the corresponding folder, note the access path without/static, also by this pit for a long time! )

<! DOCTYPE html>

6. Application Configuration file Authoring

Create a new Application.properties file and add the following:

Msg=ladies and gentleman,welcome!

7. Start running

Browser access: Http://localhost:8080/common/login

8. Deployment

MVN package to make a bag

Java-jar Xxx.jar Run this package to

First, Spring boot primer (web+freemarker)

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.