JSON export data from database?

2019-09-20 09:01发布

问题:

Hi, I am working on web applications.I have a query.How can I export data from database to JSON using spring,I am unable to understand.Please help me to resolve this.

Thank you very much in advance!!

回答1:

Try this code:

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody MyObj getJSON() {
    MyObj obj = new MyObj();

    return obj;

}

Put jackson in your classpath and @ResponseBody annotation in controller method handler.

Also enable mvc:annotation-driven in your servlet config.

In this case MyObj will be serialized in JSON format.



回答2:

Go through the following links for database and JSON examples.

  1. Spring MVC JDBC Example.
  2. Spring MVC and JSON