网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

我的第一个springboot接口项目-创新互联

  1. idea创建项目

在这里插入图片描述
勾选web-spring web依赖
在这里插入图片描述
创建新的类,拼接url
在这里插入图片描述
启动
@SpringBootApplication

东光ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

postman调用接口http://localhost:8080/h1/h2
在这里插入图片描述

  1. 带有参数的接口
package com.example.demo;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/h1")
public class http {@RequestMapping("/h2")
    public String toweb(@RequestBody Test param){System.out.println(param.getAge()+"&&&");
        System.out.println(param.getName()+"****");
        System.out.println("sucess"+param);
        return "hello";
    }
}

Test是自定义的类,

package com.example.demo;

public class Test {int age;
    String name;

    @Override
    public String toString() {return "Test{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    public void setAge(int age) {this.age = age;
    }

    public void setName(String name) {this.name = name;
    }

    public int getAge() {return age;
    }

    public String getName() {return name;
    }

    public Test(int age, String name) {this.age = age;
        this.name = name;
    }
}

postmen里面的json字段要和类的属性一致,否则获取到null,如果不加@RequestBody,则
可以获取到form-data和x-www-form-urlencoded

@GetMapping("/goods/{id}")
    public Goods goods(@PathVariable(name = "id") Integer id) {Goods g = new Goods(id, "草莓", 6.5, new Date(), "好吃");
        return g;
    }
@RestController
@RequestMapping("/h1")
public class http {@RequestMapping("/h2/{id}")
    @ResponseBody
    public String toweb(@PathVariable(name = "id") Integer id){System.out.println(id+"&&&");
        System.out.println("sucess");
        return "543";
    }
}

在这里插入图片描述

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网页名称:我的第一个springboot接口项目-创新互联
网站路径:http://bjjierui.cn/article/cchpjg.html

其他资讯