本文是一篇SprintBoot学习入门笔记

1、打开Eclipse,版本为Oxygen 4.7.0

2、新建项目
NewProject->MavenProject->Next->Next

GroupId填写com.learn,Artifactid 填写spring-boot-hello,完成

3、配置pom.xml

双击pom.xml,打开pom.xml选项卡,因为暂时不需要Test,删除Test有关的,另外删除项目Test目录。
修改后的pom.xml内容如下

<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.kfit</groupId>
<artifactId>spring-boot-hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>spring-boot-hello</name>
<url>http://maven.apache.org</url> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 指定jdk1.8 -->
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

4、新建Controller类

内容如下

package com.learn.spring_boot_hello;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController { @RequestMapping("/hello")
public String hello() {
return "hello";
}
}

5、App.Java中启动

package com.learn.spring_boot_hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* 在这里使用@SpringBootApplication指定这是一个sprint boot的应用程序
*
*/
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class, args);
}
}

6、项目右键Run,选择App,Ok

7、查看Console,如果输出以下内容表示运行正常

8、浏览器测试
http://127.0.0.1:8080/hello
输出
hello

9、新建一个Student实体类

package com.learn.spring_boot_hello;

public class Student {

    int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

10、Controller里编写对应的方法

    @RequestMapping("/getstudent")
public Student getStudent() {
Student student=new Student();
student.id=1;
student.name="小明";
return student;
}

11、启动
http://127.0.0.1:8080/getstudent

{"id":1,"name":"小明"}

从上面可以看出会自动把对象转为json,默认使用的jackson解析框架。

(完毕)

SpringBoot入门笔记(一)、HelloWorld的更多相关文章

  1. SpringBoot入门笔记(二)、使用fastjson

    1.添加fastjson配置 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastj ...

  2. SpringBoot入门笔记(四)、通常Mybatis项目目录结构

    1.工程启动类(AppConfig.java) 2.实体类(domain) 3.数据访问层(dao) 4.数据服务层(service) 5.前端控制器(controller) 6.工具类(util) ...

  3. SpringBoot入门笔记(三)、热加载

    1.配置热加载环境,在pom.xml添加如下代码 <build> <!--springloader plugin --> <plugins> <plugin& ...

  4. SpringBoot 入门笔记

    1. Spring 4.3中引入了: @GetMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping 2. @RequestMapp ...

  5. SpringBoot学习笔记<一>入门与基本配置

    毕业实习项目技术学习笔记 参考文献 学习视频 2小时学会Spring Boot:https://www.imooc.com/learn/767 学习资料 SpringBoot入门:https://bl ...

  6. SpringBoot学习笔记(一)入门简介

    一.SpringBoot 入门简介 整体讲解内容概况: 1.1 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案. Spring Boot ...

  7. SpringBoot入门基础

    目录 SpringBoot入门 (一) HelloWorld. 2 一 什么是springboot 1 二 入门实例... 1 SpringBoot入门 (二) 属性文件读取... 16 一 自定义属 ...

  8. 一看就懂的Mybatis框架入门笔记

    本篇为初学Mybatis框架时的入门笔记,整理发出 Spring集成Mybatis https://www.cnblogs.com/yueshutong/p/9381590.html SpringBo ...

  9. 「Android 开发」入门笔记

    「Android 开发」入门笔记(界面编程篇) ------每日摘要------ DAY-1: 学习笔记: Android应用结构分析 界面编程与视图(View)组件 布局管理器 问题整理: Andr ...

随机推荐

  1. 【Hihocoder1413】Rikka with String(后缀自动机)

    [Hihocoder1413]Rikka with String(后缀自动机) 题面 Hihocoder 给定一个小写字母串,回答分别把每个位置上的字符替换为'#'后的本质不同的子串数. 题解 首先横 ...

  2. 让自己的网站实现在线编辑office文档

    我们可以通过Office Web Apps(OWA)来实现在线编辑word,excel,power point, one note,并集成到自己的网站里去.   1 准备工作 1.1 操作系统 安装了 ...

  3. 天梯赛 L2-001 紧急救援

    L2-001 紧急救援 (25 分) 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道 ...

  4. Docker安装及常用命令

    修改机器名: [root@docker /]# hostnamectl set-hostname Docker 安装EPEL源: [root@docker /]# yum -y install epe ...

  5. js 刷新

    方法一: location.reload 重新加载 location.reload(); 如果该方法没有规定参数,或者参数是 false,它就会用 HTTP 头 If-Modified-Since 来 ...

  6. 【模板】ac自动机

    本来是真的特别不想写这个的 但是有段时间洛谷天天智推这个可能是我太菜了 然后觉得这个也不难 乘着今早没事写下 来这保存下 方便下次食用 #include <bits/stdc++.h> u ...

  7. A1002. A+B for Polynomials

    This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file con ...

  8. linux提取第一列且删除第一行(awk函数)

    如下文件所示,只想提取红框中的内容,即进行提取第一列,且去除第一行的操作 则用到下列命令行: awk 'NR == 1 {next} {print $1}' file.txt > file_co ...

  9. fcntl F_SETFL

    F_SETFL file set flag F_SETFL命令允许更改的标志有O_APPEND,O_NONBLOCK,O_NOATIME,O_DIRECT,O_ASYNC 这个操作修改文件状态标记适用 ...

  10. TestNg 9. 参数化测试-DataProvider参数化

    首先利用@DataProvider(name = "XXX")的属性,将name的值XXX 传递给 @Test(dataProvider = "XXX") 看以 ...