idea+springboot+Mybatis搭建web項目

來源:互聯網
上載者:User

標籤:str   maven   否則   initial   方法   local   bin   為我   點擊   

使用idea+springboot+Mybatis搭建一個簡單的web項目。

首先建立一個項目;

在這裡選擇Maven項目也可以,但是IDEA為我們提供了一種更方便快捷的建立方法,即Spring Initializr。選擇後點擊Next;

把項目資訊寫好,Next;

按下面三張圖勾選設定;

最後Finish。

等待Maven自動載入完成後,最初的項目結構如。在Springboot屬性檔案application.properties中,把資料庫連接屬性加上,同時可以設定服務連接埠。

spring.datasource.url = jdbc:mysql://localhost:3306/testspring.datasource.username = rootspring.datasource.password =  rootspring.datasource.driverClassName = com.mysql.jdbc.Driver#頁面熱載入spring.thymeleaf.cache = false#連接埠server.port=8888

resources目錄下,static檔案夾是放置各種靜態資源,如css,js,img等檔案的。templates檔案夾則是預設放置網頁的。當然也可以更改。

在static檔案夾下建立一個測試css,test.css。

body{    color: red;}

  

在templates檔案夾下建立一個html,要注意的是meta這個標籤的結束符軟體並沒有自動加上,需要手動加上,否則訪問網頁時會報錯。並引入test.css

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
<link rel="stylesheet" href="test.css" type="text/css" />
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

  

接下來可以寫一個controller了

package com.example.demo;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class IndexController {    @RequestMapping("/index")    public String index(){        return "hello";    }}

  

 

完成之後,通過方式1和方式2都可以啟動項目

接下來可以在瀏覽器中測試了

到此,一個簡單的項目搭建完成。

idea+springboot+Mybatis搭建web項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.