• 项目导入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. 一、Smarty安装与调试

    一.安装注:这里所使用的Smarty是3.x版本,要求PHP版本为5.2或者更高.解压下载下来的Smarty压缩文件,将文件夹libs拷到项目中,在项目中引入libs文件夹中的"Smarty ...

  2. 《统计学习方法(李航)》讲义 第03章 k近邻法

    k 近邻法(k-nearest neighbor,k-NN) 是一种基本分类与回归方法.本书只讨论分类问题中的k近邻法.k近邻法的输入为实例的特征向量,对应于特征空间的点;输出为实例的类别,可以取多类 ...

  3. react-native 环境安装常见问题

    npm install react-native-cli -g react-native init yourproject npm install react-native run-ios 问题1:卡 ...

  4. Kotlin之注释

    kotliin中注释和java注释是一样的,支持单行注释和多行注释,但kotlin支持嵌套,java不支持

  5. ListView 如何提高其效率?

    ① 复用 ConvertView② 自定义静态类 ViewHolder③ 使用分页加载 ④ 使用 WeakRefrence 引用 ImageView 对象 ViewHolder 为什么要声明为静态类? ...

  6. 阶段3 2.Spring_03.Spring的 IOC 和 DI_9 spring的依赖注入

    新建工程 改成jar包 加入spring的依赖 复制之前的工程代码 再复制配置文件 fac factory整个删除 构造函数也删除.删除后的代码.如下 配置文件中的注释都删除掉 spring中的依赖注 ...

  7. python学习笔记:(九)循环(for和while)

    在python中循环包括for和while 1.while循环 while 判断条件: statements ----表示:判断条件为真时执行statements,为假不执行 2.for语句 for ...

  8. C#学习笔记二 (资源托管,泛型,数组和元组,运算符和类型强制转换)

     托管和非托管资源 1.托管资源是指GC管理的内存空间,非托管资源是指文件句柄,网络连接,数据库连接等. 2.方法中临时申请的变量,被存放在栈中.栈存储非对象成员的值数据.例如在方法中有B b=new ...

  9. 【VS开发】【图像处理】Pleora推出iPORT CL-U3外置抓帧器

    全球领先的高性能视频接口产品供应商Pleora科技公司近日宣布推出可将Camera Link®摄像头转化为USB3Vision™摄像头的首个产品iPORT CL-U3外置抓帧器,树立了另一个行业里程碑 ...

  10. Python密码登录程序的思考--学与习

    # 初学者的起步,对于开始的流程图结构还不太熟悉 #   思考: 1,write()与writelines()的区别,前者确定为字符串,后者为序列(列表,字典.元组等),自动为你迭代输入#      ...