一、创建SpringBoot项目

  

  

  

  

二、导入Jar包(pom.xml)

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="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.example</groupId>
<artifactId>testdemo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>TestDemo1</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties> <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-configuration-processor</artifactId>
<optional>true</optional>
</dependency> <!--添加mysql的组件-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> <!--servlet依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency> <!--jstl依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency> <!--使jsp页面生效-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency> <!--整合mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency> </dependencies> <build>
<plugins>
<!--将SpringBoot的Maven插件全部引入 包含tomcat-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

三、配置yml文件、启动类

  

  application.yml内容:

 server:
#服务端口
port: 8080
#项目contextPath,一般在正式发布版本中,不配置,目前配置缺省路径
context-path: /
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
#address: 192.168.0.101
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
# error:
# path: /error
# session最大超时时间(分钟),默认为30
#session:
# timeout: 60
# tomcat:
# tomcat的URI编码
#uri-encoding: utf-8
# tomcat最大线程数,默认为200
#max-threads: 1000
# 存放Tomcat的日志、Dump等文件的临时文件夹,默认为系统的tmp文件夹(如:C:\Users\Shanhy\AppData\Local\Temp)
#basedir: D:/springboot-tomcat-tmp
# 打开Tomcat的Access日志,并可以设置日志格式的方法:
#server.tomcat.access-log-enabled=true
#server.tomcat.access-log-pattern=

  application.java启动类:

    ---- spring会扫描该类所在目录下的java类,SpringBoot唯一入口程序

 package com.example.demo;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class TestDemo1Application {
/*
Servlet容器默认的Context路径是/DispatherServlet匹配的路径(servlet-mapping中的url-patterns)
@ComponentScan路径被默认设置为SampleController的同名package,
也就是该package下的所有@Controller,@Service, @Component, @Repository都会被实例化后并加入Spring Context中。
*/
public static void main(String[] args) {
SpringApplication.run(TestDemo1Application.class, args);
}
}

  Controller类:

 package com.example.demo.controller;

 import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; /**
* Created by Administrator on 2017/7/19.
*/
@Controller
public class ControllerDemo {
@RequestMapping("/index")
// @ResponseBody
public String getDemo(){
System.out.println(".....");
return "index";
}
}

访问localhost:8080/index 即可在页面中打印出 “index” 字样。

注意:在创建Controller类时,所有的类都得是默认包的子孙包。

SpringBoot学习:在Interillj Idea上快速搭建SpringBoot项目的更多相关文章

  1. 【SpringBoot学习一】开发入门--快速创建springboot程序

    前言 本片博客记录快速创建springboot工程的两种方式.一种是使用maven创建,一种是使用spring initializr创建.开发环境JDK1.8.IDEA.maven. SpringBo ...

  2. SpringBoot学习(一)—— idea 快速搭建 Spring boot 框架

    简介 优点 Spring Boot 可以以jar包的形式独立运行,运行一个Spring Boot 项目只需要通过 java -jar xx.jar 来运行. Spring Boot 可以选择内嵌Tom ...

  3. WAMP Server助你在Windows上快速搭建PHP集成环境

    WAMP Server助你在Windows上快速搭建PHP集成环境 原文地址 我想只要爬过几天网的同学都会知道PHP吧,异次元的新版本就是基于PHP的WordPress程序制造出来的,还有国内绝大部分 ...

  4. 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置

    1.快速搭建springboot框架(在idea中): file–>new project–>Spring Initializr–>next–>然后一直下一步. 然后复制一下代 ...

  5. 在线官网Spring Initializr 或 IntelliJ IDEA 快速搭建springboot项目

    Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 那么,如何快速新建一个一个spring ...

  6. VMware 克隆linux后找不到eth0(学习hadoop,所以想快速搭建一个集群)

    发生情况:      由于在学习hadoop,所以想快速搭建一个集群出来.所以直接在windows操作系统上用VMware安装了CentOS操作系统,配置好hadoop开发环境后,采用克隆功能,直接克 ...

  7. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse

    笔记 1.快速搭建SpringBoot项目,采用Eclipse     简介:使用SpringBoot start在线生成项目基本框架并导入到eclipse中 1.站点地址:http://start. ...

  8. 使用IDEA快速搭建Springboot项目

    Spring Boot是由Pivotal团队提供的全新框架,设计目的是用来简化新Spring应用的初始搭建以及开发过程.它主要推崇的是'消灭配置’,实现零配置. 下面就介绍一下如何使用idea快速搭建 ...

  9. 聊聊SpringBoot | 第一章:快速搭建SpringBoot第一个应用

    快速搭建SpringBoot第一个应用 1.简介 本章仅介绍如何快速搭建第一个SpringBoot应用,细节内容下一章再做讲解,如果有需要,各位可以直接到Spring官网去了解. 从 Spring B ...

随机推荐

  1. Qt ------- QByteArray操作注意

    使用QByteArray方法把数据存入QByteArray需要是char型数据,如果需要存入无符号8位数据,如下: QByteArray data; data[0] = 0xFF; 即使通过data[ ...

  2. Centos7 安装rabbitmq(转载)

    原文地址:http://blog.csdn.net/wenyu826/article/details/71108279 安装Erlang 从链接https://packages.erlang-solu ...

  3. 小米路由器设置DMZ主机 并在外网访问

    一.前提条件: 1.小米路由器 2.拥有公网IP的网络 二.步骤: 1.登陆小米路由器管理界面  miwifi.com 2.高级设置=>端口转发  页面底部的DMZ选项开启,然后选择需要映射到外 ...

  4. linux部署j2eeweb工程涉及到的指令

    1.查看java进程: ps -e | grep java; 可以获取到java进程的进程号. 或: ps -ef | grep java; 可以查看到详细的进程信息 2.杀死java进程 kill ...

  5. http-反向代理学习

    主要是学习了反向代理. 结合公司的方向代理使用,然后与同事进行交流,知识还是需要通过交流才能印象深刻,以后多多交流.

  6. Eclipse导入Java工程导入错误

    1.在一台电脑A上用Eclipse新建的Java工程,换了一台电脑B,再用Eclipse导入时却出现了错误,工程显示红色叹号,并有如下两个错误提示: The project cannot be bui ...

  7. 【BZOJ4880】排名的战争 [暴力]

    排名的战争 Time Limit: 8 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 小Q是一名出色的质检员,他负责质检 ...

  8. 【洛谷 P2763】 试题库问题(最大流)

    题目链接 6/23 这是网络流23题里我第一个没看题解自己写出来一遍过的.. 这题应该是最简单的模型了吧. 从源点向每个类型连一条流量为这个类型要的题数,再从每个类型向可以属于这个类型的所有试题连一条 ...

  9. js中的for in 循环

    1.数组 使用for in 遍历数组时,其索引被视为对象的属性,从而直接输出数组的索引 var arr = ["a","b","c"]; f ...

  10. cuda中的二分查找

    使用背景 通常,在做高性能计算时,我们需要随机的连接某些点.这些点都具有自己的度量值,显然,度量值越大的值随机到的概率就会越大.因此,采用加权值得方法: void getdegreeSum(DG *g ...