lundi 22 octobre 2018

Spring boot, how to read particular object from json file, what annotation should I need?

I'm studying string boot and I know how to read json file from resources directory but I want to get particular data not whole data. like localhost:8080/user returns user name.

below is my current code

package com.example;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.*;



@RestController
@EnableAutoConfiguration
public class HelloWorld {

    @Value("classpath:json/test.json")
    private Resource resourceFile;
    @RequestMapping("/")
    Resource home() {
        return resourceFile;
    }


    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloWorld.class, args);
    }
}

I want to read particular data in test.json file. plz give me some advice or steps. Thanks




Aucun commentaire:

Enregistrer un commentaire