• 项目导入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组织的项目。

最新文章

  1. 部署网站出现System.ServiceModel.Activation.HttpModule错误
  2. ListView简单使用
  3. 响应式布局 Bootstrap(01)
  4. FFmpeg - 音频解码过程
  5. 【freemaker】之循环,判断,对象取值
  6. WCF - 绑定
  7. hyperLink的定制
  8. 一个只有99行代码的JS流程框架(二)
  9. js中多维数组转一维
  10. PHP 页面跳转到另一个页面的多种方法方法总结
  11. A Basic Course in Partial Differential Equations
  12. Camp 前三日简单总结
  13. spring boot + easypoi两行代码excel导入导出
  14. awesomium_v1.6.6_sdk 百度云下载地址
  15. iOS 10的两个坑
  16. mysql建表规范及注意事项
  17. IIS部署wordpress4.7.4
  18. Python中的基本数据类型的区别
  19. 《无所不能的JavaScript编程系列:setTimeout 简笔》
  20. Java设计模式(15)备忘录模式(Memento模式)

热门文章

  1. Swagger常用参数用法
  2. 第七周学习总结&JAVA实验五报告。
  3. Redis数据类型,面试相关
  4. leetcode-easy-trees-102. Binary Tree Level Order Traversal-YES
  5. 源码编译apache出错
  6. leetcode 289生命游戏
  7. spring BeanUtils.copyProperties只拷贝不为null的属性
  8. 清空mysql数据
  9. linux查看内存使用情况top
  10. 用roles部署nginx