SpringBoot入门笔记(一)、HelloWorld
本文是一篇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的更多相关文章
- SpringBoot入门笔记(二)、使用fastjson
1.添加fastjson配置 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastj ...
- SpringBoot入门笔记(四)、通常Mybatis项目目录结构
1.工程启动类(AppConfig.java) 2.实体类(domain) 3.数据访问层(dao) 4.数据服务层(service) 5.前端控制器(controller) 6.工具类(util) ...
- SpringBoot入门笔记(三)、热加载
1.配置热加载环境,在pom.xml添加如下代码 <build> <!--springloader plugin --> <plugins> <plugin& ...
- SpringBoot 入门笔记
1. Spring 4.3中引入了: @GetMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping 2. @RequestMapp ...
- SpringBoot学习笔记<一>入门与基本配置
毕业实习项目技术学习笔记 参考文献 学习视频 2小时学会Spring Boot:https://www.imooc.com/learn/767 学习资料 SpringBoot入门:https://bl ...
- SpringBoot学习笔记(一)入门简介
一.SpringBoot 入门简介 整体讲解内容概况: 1.1 简介 简化Spring应用开发的一个框架: 整个Spring技术栈的一个大整合: J2EE开发的一站式解决方案. Spring Boot ...
- SpringBoot入门基础
目录 SpringBoot入门 (一) HelloWorld. 2 一 什么是springboot 1 二 入门实例... 1 SpringBoot入门 (二) 属性文件读取... 16 一 自定义属 ...
- 一看就懂的Mybatis框架入门笔记
本篇为初学Mybatis框架时的入门笔记,整理发出 Spring集成Mybatis https://www.cnblogs.com/yueshutong/p/9381590.html SpringBo ...
- 「Android 开发」入门笔记
「Android 开发」入门笔记(界面编程篇) ------每日摘要------ DAY-1: 学习笔记: Android应用结构分析 界面编程与视图(View)组件 布局管理器 问题整理: Andr ...
随机推荐
- 【BZOJ5211】[ZJOI2018]线图(树哈希,动态规划)
[BZOJ5211][ZJOI2018]线图(树哈希,动态规划) 题面 BZOJ 洛谷 题解 吉老师的题目是真的神仙啊. 去年去现场这题似乎骗了\(20\)分就滚粗了? 首先\(k=2\)直接算\(k ...
- 【BZOJ5416】【NOI2018】冒泡排序(动态规划)
[BZOJ5416][NOI2018]冒泡排序(动态规划) 题面 BZOJ 洛谷 UOJ 题解 考场推出了就是两个上升子序列,并且最长下降子序列长度不超过\(2\)...然后大力暴力状压\(dp\)混 ...
- iis express添加虚拟目录
在调试WEB时,还是使用IIS EXPRESS比较方便, 在IIS中,选择网站,右击,添加虚拟目录或者应用程序,就能添加虚拟目录了.. 在IIS EXPRESS中,添加虚拟目录如下 1.右击IIS E ...
- 【mysql】mysql null值
在数据表我们有时候有些表字段会为null,表示空.其实在mysql中null值是占用空间的. mysql手册如下解释 NULL columns require additional space in ...
- SpaceVim中vimproc的vimproc_linux64.so未找到
vimproc是我使用的SpaceVim中自动安装的插件,在启动时出现了"找不到dll文件"的提示,通过查阅官网( https://github.com/Shougo/vimpro ...
- C# Winfrom 进程&多线程
进程: 首先需要引用命名空间: using systemDiagnostics; 最简单的打开进程的方法,进程名并不是汉字: Process.start("calc");//cla ...
- A1109. Group Photo
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 文献笔记:Genome-wide associations for birth weight and correlations with adult disease
该文献纳入了EGG(Early Growth Genetics Consortium)和UK biobank两大数据库,分为欧洲祖先和非欧洲祖先群体.这两个数据用到的样本量分别如下: Early Gr ...
- 第二十二节,TensorFlow中的图片分类模型库slim的使用、数据集处理
Google在TensorFlow1.0,之后推出了一个叫slim的库,TF-slim是TensorFlow的一个新的轻量级的高级API接口.这个模块是在16年新推出的,其主要目的是来做所谓的“代码瘦 ...
- ElasticSearch6.5.0 【script_lang not supported】
执行代码:[就是想根据条件更新]把品牌为LiNing的都改成Cat. UpdateByQueryRequestBuilder updateByQuery = UpdateByQueryAction.I ...