Answers for "how to create object of new responseEntity"

0

responseentity object

package com.zetcode.controller;

import com.zetcode.bean.Country;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MyController {
    
    @RequestMapping(value = "/getCountry")
    public ResponseEntity<Country> getCountry() {
        
        var c = new Country();
        c.setName("France");
        c.setPopulation(66984000);
        
        var headers = new HttpHeaders();
        headers.add("Responded", "MyController");
        
        return ResponseEntity.accepted().headers(headers).body(c);
    }
    
    @RequestMapping(value = "/getCountry2")
    @ResponseBody
    public Country getCountry2() {
        
        var c = new Country();
        c.setName("France");
        c.setPopulation(66984000);
        
        return c;
    }    
}
Posted by: Guest on September-17-2020
0

responseentity object

@RequestMapping(value = "/getCountry2")
@ResponseBody
public Country getCountry2() {
    
    var c = new Country();
    c.setName("France");
    c.setPopulation(66984000);
    
    return c;
}
Posted by: Guest on September-17-2020

Code answers related to "how to create object of new responseEntity"

Browse Popular Code Answers by Language