spring-boot 从零开始-01

Spring-boot初认识

快速认识spring-boot,并且可以写spring-boot的项目,先要了解更多请自行百度,意在帮助iOS开发者了解spring-boot

创建一个Spring-boot工程

1.打开ecplise,new->maven project
默认选择next,直到需要输入groudid界面,输入你需要的项目名字和分组名字

2.配置pom.xml
Maven支持的jar:https://mvnrepository.com(在这个网址里面找)
在pom.xml文件中中输入如下配置,配置maven中配置的jar自动选择合适的当前环境的版本

  <!-- 配置parent maven 自动选择最合适的版本 -->
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
  </parent>

指定jdk的版本

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- 指定一下jdk的版本 ,这里我们使用jdk 1.8 ,默认是1.6 -->
    <java.version>1.8</java.version>
  </properties>

然后在这个节点下添加节点,dependency节点下是你需要maven帮你加入工程的配置jar, Spring-Boot需要的jar包

  <dependencies>
          <!-- 
              spring-boot-starter-web: MVC,AOP的依赖包....
           -->
    <dependency> 
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <!-- 
            <version></version>
            由于我们在上面指定了 parent(spring boot)
        -->
        </dependency>
        
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.15</version>
        </dependency>
    </dependencies>

图片如图所示:
在这里插入图片描述

简单的任务

1.设置工程入口
2.创建一个controller类,设置访问路径和返回值

1.上述环境配置好了,在App.js中设置注解@SpringBootApplication,设置spring-boot启动
@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

如图所示:
在这里插入图片描述

2.创建一个controller 单纯的java class

@RestControlller : is a stereotype annotation that combines
@RestControlller = @Controller + @ResponseBody
这是一个controller,并且将放回值写响应的body里面\

@Controller:@Controller用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller对象。分发处理器将会扫描使用了该注解的类的方法,并检测该方法是否使用了@RequestMapping注解。@Controller只是定义了一个控制器类,而使用@RequestMapping注解的方法才是真正处理请求的处理器。
@RequestMapping:映射Request请求与处理器,下面的一个方法是用来处理请求某个请求的,格式如下:

@RequestMapping("/hello")
@RequestMapping(value="/hello", method={RequestMethod.POST, RequestMethod.GET})


表示请求支持POST和GET请求,如果仅支持

@RequestMapping(value="/hello", method=RequestMethod.POST)
@RestController
public class HellowController {
    @RequestMapping("/hello")
    public String hello() {
        return "hello spring boot avalanching";
    }
}

在这里插入图片描述

打开app.js 右键鼠标,然后Run As,选在java Application
在这里插入图片描述

打开浏览器验证,输入网址http://localhost:8080/hello
在这里插入图片描述

到这里一个简单的spring-boot项目已经完成了,hello world

作为一个iOS的开发者,这里我们需要理解的概念是maven,照搬iOS的思想来理解就是java版的cocospods。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值