先创建包com.sdcet
RestaurantMain
@SpringBootApplication public class RestaurantMain { public static void main(String[] args) { SpringApplication.run(RestaurantMain.class,args); } }
在com.sedcet建包controller
HelloController
@Controller @ResponseBody public class HelloController { @RequestMapping("/hello") public String hello() { return "HELLO ??"; } @RequestMapping("/getPhone") public Phone getPhone(){ return new Phone(); } @RequestMapping("/getSites") public Wrapper getSites(){ Wrapper wrapper=new Wrapper(); List<Website>websiteList=new ArrayList<>(); Website websitel=new Website(); websitel.setName("菜鸟驿站"); websitel.setUrl("www.runoob.com"); websiteList.add(websitel); Wrapper wrapper2=new Wrapper(); Website websitel2=new Website(); websitel2.setName("谷歌"); websitel2.setUrl("www.google.com"); websiteList.add(websitel2); Wrapper wrapper3=new Wrapper(); Website websitel3=new Website(); websitel3.setName("微博"); websitel3.setUrl("www.weibo.com"); websiteList.add(websitel3); wrapper.setSites(websiteList); return wrapper; } }
com.sdcet下建包entity
Phone
Website
Wrapper
public class Phone { private String brand; private String made;
public class Wrapper<Webstie> { private List<Webstie> sites; public void setSites(List<Webstie> sites) { this.sites = sites; } public List<Webstie> getSites() { return sites; } }
private double price=1000.88; private boolean newst=true; private String[] strArray={"Sunday","Monday","Tuesday"}; public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getMade() { return made; } public void setMade(String made) { this.made = made; } }
public class Website { 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; } }