- map的映射
package com.kob.backend.controller.pk;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/pk/")
public class BotInfoController {
@RequestMapping("getbotinfo/")
public Map<String,String> getBotInfo(){
Map<String, String> map = new HashMap<>();
map.put("name", "trigger");
map.put("rateing", "1500");
return map;
}
}
Map, List里面用的都是尖括号
- 二者的嵌套
@RestController
@RequestMapping("/pk/")
public class BotInfoController {
@RequestMapping("getbotinfo/")
public List<Map<String,String>> getBotInfo(){
List<Map<String,String>> list = new LinkedList<>();
Map<String, String> bot1 = new HashMap<>();
bot1.put("name", "trigger");
bot1.put("rateing", "1500");
Map<String, String> bot2 = new HashMap<>();
bot2.put("name", "trigger");
bot2.put("rateing", "1600");
Map<String, String> bot3 = new HashMap<>();
bot3.put("name", "trigger");
bot3.put("rateing", "1700");
list.add(bot1);
list.add(bot2);
list.add(bot3);
return list;
}
}
- 链接是通过controller来实现的 :http://localhost:8080/pk/getbotinfo/
- 修改端口
server.port=3000
变红是没有加到git里面