SpringBoot---基本配置

來源:互聯網
上載者:User

標籤:boot   mave   本地   star   scope   標籤   方法   depend   work   

1、首先在pom.xml添加對HTML的相關依賴

/** * pom.xml檔案 */<dependencies>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-web</artifactId>    </dependency>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-test</artifactId>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-thymeleaf</artifactId>    </dependency></dependencies><build>    <plugins>        <plugin>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-maven-plugin</artifactId>        </plugin>    </plugins></build>**

2、在application.yml檔案添加SpringBoot相關配置

spring:

 thymeleaf: prefix: classpath:/templates/

注意:application.yml 如果是空檔案,則預設視圖檔案存放在
templates檔案下,資源檔存放在static目錄下,由於SpringBoot對jsp支援不太友好,一般使用內建的標籤實現資料的賦值



在Controller裡面寫跳轉HTML頁面方法

@Controller  //注意這裡必須為Controllerpublic class HelloController {    /**     * 本地訪問內容地址 :http://localhost:8080/lmycc/hello     * @param map 傳遞參數     * @return     */    @RequestMapping("/hello")    public String helloHtml(HashMap<String, Object> map) {        map.put("hello", "歡迎進入HTML頁面");        return "/index";    }}

SpringBoot---基本配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.