2021-05-18

在这里插入图片描述

引入@SpringBootApplication

写一个main方法SpringApplication.run(Xxx.class,args) 启动项目

package com.sdcet;

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

@SpringBootApplication
public class RestaurantMain {
public static void main(String[] args) {
SpringApplication.run(RestaurantMain.class, args);

}

}
定义一个Phone类 设置静态方法 设置多个变量

package com.sdcet.entity;

public class Phone {
private String brand=“名牌手机”;
private String model=“最新款”;
private double price=1000.2;
private boolean newest=true;

}
定义Webstie 使用静态方法 并生成getter setter方法

package com.sdcet.entity;

public class Webstie {
private String name;
private String url;

public String getName() {
    return name;
}

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

public String getUrl() {
    return url;
}

public void setUrl(String url) {
    this.url = url;
}

}
设置Srapper类 获取网站连接数

private List sites;
并生成getter setter方法

package com.sdcet.entity;

import java.util.List;

public class Wrapper {
private List sites;

public void setSites(List<Webstie> sites){
    this.sites=sites;
}

public List<Webstie> getSites(){
    return sites;
}

}

设置类HelloControlller,引入

@Controller
@ResponseBody
使用@RequestMapping 注解映射请求路径

并定义微博 设置setName setUrl

package com.sdcet.constroller;

import com.sdcet.entity.Webstie;
import com.sdcet.entity.Wrapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@ResponseBody
public class HelloControlller {
@RequestMapping("/hello")
public String hello() {
return “HELLO SPRINGBO!!!”;
}

@RequestMapping("/getSites")
public Wrapper getSites (){
    Wrapper wrapper = new Wrapper();
    List<Webstie> webstieList=new ArrayList<>();

    Webstie webstie = new Webstie();
    webstie.setName("菜鸟教程");
    webstie.setUrl("www.runoob.com");
    webstieList.add(webstie);

    Webstie webstie1 = new Webstie();
    webstie1.setName("google");
    webstie1.setUrl("www.gooogle.com");
    webstieList.add(webstie1);

    Webstie webstie2 = new Webstie();
    webstie2.setName("微博");
    webstie2.setUrl("www.weibo.com");
    webstieList.add(webstie2);

    wrapper.setSites(webstieList);
    return wrapper;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值