[Spring MVC]JSON型の値を返すサンプル

2021年4月7日

1.Jacksonを導入
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

2.Controller側

@RequestMapping("/getData")
public List(Employee)getDate(){

  return Arrays.asList(new Employee("user01","21","addr123"),new Employee("user02","31","addr456"))
}

3.JSON結果

「
  {
     "name": "user01",
      "age" : "21",
     "address":"addr123"
  },
  {
     "name": "user02",
     "age" : "31",
     "address":"addr456"
  }

」

 

SpringMVC

Posted by arkgame