Java日志-Spring Boot(1)idea快速构建Spring Boot

来源:互联网 发布:HTML源码 编辑:程序博客网 时间:2024/06/11 19:12

对于Spring Boot博主也是个新手,希望可以跟大家一起学习一起进步


接下来我们使用idea构建一个简单的Spring Boot应用 “Hello World”


第一步:打开idea选择new project 选择Spring Initializr  点击next




第二步:选择必要的依赖,建议大家尽量跟我选择一样的吧


接下去就是next finish之类的  大家自己完成吧!


第四步:配置你的maven仓库,建议大家使用阿里云的maven仓库(极快无比),在你的maven中的setting.xml文件中的<mirrors>下写入

<mirror>        <id>nexus-aliyun</id>        <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name>        <url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror> 

第五部:写一个Controller吧

package com.example.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;/** * Created by Administrator on 2017/2/14 0014. */@Controllerpublic class TestController {    @RequestMapping("/")    public String test(){        return "index";    }}
注意:如果controller和你的application不在一个包的话可以通过以下配置来完成
package com.example;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication(scanBasePackages = {"com.example.controller"})public class DemoApplication {   public static void main(String[] args) {      SpringApplication.run(DemoApplication.class, args);   }}

第六步:编辑一个thymeleaf页面吧,由于博主使用的是1.5.1的spring boot可能在集成thymeleaf模板时可能有点问题所以我们在配置文件中加入

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"      xmlns:th="http://www.thymeleaf.org"><head>    <title>Title</title></head><body>    Hello world</body></html>

spring.session.store-type = none
就完全没有问题啦


接下来是完整的项目结构



最后启动项目,感受springboot快速构建项目带来的快感吧 localhost:8080  

第一次写博客,好心累!!一直ctrl+s   哈哈哈    

1 1
原创粉丝点击