Simple string as JSON return value in spring rest controller

前端 未结 4 1830
离开以前
离开以前 2020-12-17 16:58

Let\'s take a look at the following simple test controller (Used with Spring 4.0.3):

@RestController
public class Te         


        
4条回答
  •  太阳男子
    2020-12-17 17:39

    Here are the steps that I did to achieve this :

    1. Add dependency in pom file:

      
          com.fasterxml.jackson.core
          jackson-databind
          2.9.3
      
      
    2. Put @ResponseBody annotation on your method like this:

      @RequestMapping(value = "/getCountries", method = RequestMethod.GET)    
      @ResponseBody    
      public List getCountries() {    
          return countryDAO.list();    
      }
      

提交回复
热议问题