• 项目导入eclipse

先检测是否安装有gradle插件

然后点击  finish 按钮

  • hello world实例

    • Application.java

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

SpringBootApplication的说明

    • HelloController.java

先创建包controller,再在包下创建Java类HelloController

package com.example.demo.controler;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//注解的解释参考下面
@RestController
public class HelloControler {  //映射路径定义为hello
    @RequestMapping("/hello")
    public String hello() {

        return "hello world!";
    }
}
@Open Declaration   org.springframework.web.bind.annotation.RestController
@Controller
@ResponseBody
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Documented

A convenience annotation that is itself annotated with @Controller and @ResponseBody. 

Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default. 

NOTE: @RestController is processed if an appropriate HandlerMapping-HandlerAdapter pair is configured such as the RequestMappingHandlerMapping-RequestMappingHandlerAdapterpair which are the default in the MVC Java config and the MVC namespace.
Since:4.0Author:Rossen StoyanchevSam Brannen
    • HelloControlerTest.java  (测试用例)

代码可以拷贝DemoApplicationTests.java里的

package com.example.demo.controler;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest//配置注入MockMvc
@AutoConfigureMockMvc
public class HelloControlerTest {
  

  //因为使用的时MVC框架
    @Autowired
    private MockMvc mockmvc;
    @Test
    public void testHello() throws Exception {     //构建MVC的请求,get方法,接受的媒体类型(JSON),断言预期返回(),期望返回内容(字符串和“hello world!”匹配)
        mockmvc.perform(MockMvcRequestBuilders.get("/hello").accept(org.springframework.http.MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andExpect(content().string(equalTo("hello world!")));
    }

}
    • 测试

在HelloControlerTest.java 中,右键 => Run as  => JUnit Test

    ------------6月22日-------------

    经过研究个人感觉还是maven更好用一些,一直都在用IDEA下maven组织的项目。

springboot学习2的更多相关文章

  1. springboot 学习资源推荐

    springboot 是什么?对于构建生产就绪的Spring应用程序有一个看法. Spring Boot优先于配置的惯例,旨在让您尽快启动和运行.(这是springboot的官方介绍) 我们为什么要学 ...

  2. Springboot学习记录1--概念介绍以及环境搭建

    摘要:springboot学习记录,环境搭建: 官方文档地址:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/ht ...

  3. SpringBoot学习笔记

    SpringBoot个人感觉比SpringMVC还要好用的一个框架,很多注解配置可以非常灵活的在代码中运用起来: springBoot学习笔记: .一.aop: 新建一个类HttpAspect,类上添 ...

  4. springboot学习(一)——helloworld

    以下内容,如有问题,烦请指出,谢谢 springboot出来也很久了,以前零散地学习了不少,不过很长时间了都没有在实际中使用过了,忘了不少,因此要最近准备抽时间系统的学习积累下springboot,给 ...

  5. SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问

    SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问 https://blog.csdn.net/yft_android/article/details/80307672

  6. Springboot学习07-数据源Druid

    Springboot学习07-数据源Druid 关键字 Druid 前言 学习笔记 正文 1-Druid是什么 Druid是阿里巴巴开源平台上的一个项目,整个项目由数据库连接池.插件框架和SQL解析器 ...

  7. Springboot学习06-Spring AOP封装接口自定义校验

    Springboot学习06-Spring AOP封装接口自定义校验 关键字 BindingResult.Spring AOP.自定义注解.自定义异常处理.ConstraintValidator 前言 ...

  8. Springboot学习05-自定义错误页面完整分析

    Springboot学习06-自定义错误页面完整分析 前言 接着上一篇博客,继续分析Springboot错误页面问题 正文 1-自定义浏览器错误页面(只要将自己的错误页面放在指定的路径下即可) 1-1 ...

  9. Springboot学习04-默认错误页面加载机制源码分析

    Springboot学习04-默认错误页面加载机制源码分析 前沿 希望通过本文的学习,对错误页面的加载机制有这更神的理解 正文 1-Springboot错误页面展示 2-Springboot默认错误处 ...

  10. Springboot学习笔记(六)-配置化注入

    前言 前面写过一个Springboot学习笔记(一)-线程池的简化及使用,发现有个缺陷,打个比方,我这个线程池写在一个公用服务中,各项参数都定死了,现在有两个服务要调用它,一个服务的线程数通常很多,而 ...

随机推荐

  1. LeetCode 12. 整数转罗马数字(Integer to Roman)

    题目描述 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II , ...

  2. DB2基础维护手册

    诊断DB2系统性能:db2top -d DEMODB db2top详解:http://blog.sina.com.cn/s/blog_636d62310102v7lm.html

  3. 下载excle文件之工具

    创建万能的工具类,已备用 ExcelData.java 存放文件数据 package com.ulic.gis.dataCenter.util; import java.io.Serializable ...

  4. DP练习题——洛谷P1970花匠

    目录 题目描述: 输入输出格式: 输入格式: 输出格式: 输入输出样例: 输入样例: 输出样例: 题目分析: 解法一: 解法二: 结语: 题目描述: 洛谷\(P1970\) 花匠栋栋种了一排花,每株花 ...

  5. LVS 四层 TCP/UDP 负载均衡器

    目录 文章目录 目录 LVS LVS 应用结构 LVS 提供的三种模式 LVS-NAT LVS-TUN LVS_DR LVS 负载均衡算法 静态负载均衡 动态负载均衡 LVS-ipvsadm 指令集 ...

  6. vim技巧2

    vim技巧总结-查找 1.查找命令1.1 执行一次查找普通模式下,/会调用查找提示符,如果vim扫描到文档尾部仍没有找到目标,会提示"search hit BOTTOM, continuin ...

  7. RTX数据表分析

    /******************************************* * UserName 做主键 **************************************** ...

  8. Centos7 yum 源安装nginx

    一.建立nginx源 vim /etc/yum.repos.d/nginx.repo [nginx]name=nginx repobaseurl=http://nginx.org/packages/c ...

  9. tableau desktop

    参考: 入门指南: https://help.tableau.com/current/guides/get-started-tutorial/zh-cn/get-started-tutorial-co ...

  10. spring boot-1.简单介绍及环境搭建

    1.简介 spring boot 是在spring 基础上进行了全面整合的架构,个人认为优点在于以下几点: 1.简化配置,甚至零配置即可开发出一个web应用.spring boot 默认配置了大量的s ...