javascript - 总是在独立的 tomcat 中返回空的 JSON 数组

标签 javascript json web-services tomcat spring-boot

我正在开发一个 spring boot 应用程序,这是我的 Rest Controller

@RestController
public class State_Controller {
    List<State>  state_list = new ArrayList<State>();   
    state_data object;

    @RequestMapping(value="/state",produces={MediaType.APPLICATION_JSON_VALUE},method=RequestMethod.GET)
    public ResponseEntity<List<State>> getthreshold(@RequestParam("start") String start_time,@RequestParam("end") String end_time){

            Timestamp start_time1 = Timestamp.valueOf(start_time);
            Timestamp end_time1 = Timestamp.valueOf(end_time);

        List<State> state_list=get_state( start_time1, end_time1);
        return new ResponseEntity<List<State>>(state_list,HttpStatus.OK);
    }
    @ResponseBody   
    public List<State>  get_state(Timestamp start_time,Timestamp end_time){

        System.out.println(start_time);
        object = new state_data(start_time,end_time);
        state_list=object.printTopics();
        return state_list;
    }
}

还有我的数据库连接和返回结果集方法:

private Connection connectToDatabaseOrDie()
  {
    Connection conn = null;
    try
    {
      Class.forName("org.postgresql.Driver");
      String url = "jdbc:postgresql://localhost:5432/data_base";
      conn = DriverManager.getConnection(url,"user", "password");
    }
    catch (ClassNotFoundException e)
    {
      e.printStackTrace();
      System.exit(1);
    }
    catch (SQLException e)
    {
      e.printStackTrace();
      System.exit(2);
    }
    return conn;
  }
private void populateListOfTopics(Connection conn, List<State> listOfBlogs,Timestamp start_time,Timestamp end_time,int zone_id)
  {
    try 
    {

        String sql= "SELECT * FROM public.table where time >= ? and time <= ?";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setTimestamp(1,start_time);


        pstmt.setTimestamp(2,end_time);


        ResultSet rs = pstmt.executeQuery();


      while ( rs.next() )
      {
          State blog = new State();

        blog.year = rs.getInt ("year");
        blog.month=rs.getInt ("month");
        blog.day  = rs.getInt ("day");
        blog.hour = rs.getInt ("hour");



        listOfBlogs.add(blog);
      }

      rs.close();
      pstmt.close();
      conn.close();
    }
    catch (SQLException se) {
      System.err.println("Threw a SQLException creating the list of state.");
      System.err.println(se.getMessage());
    } catch (Exception e) {
        System.out.println("Err");
        e.printStackTrace();
    }
  }

所以问题是当我访问 url 时

 http://localhost:8080/state?start=2012-03-03 00:00:00&end=2012-03-03 10:00:00

当我使用嵌入式 tomcat 时,它会完美地提供 JSON 数据。但是如果我在独立的 tomcat 中部署应用程序,那么

 http://localhost:8080/Application_Name/state?start=2012-03-03 00:00:00&end=2012-03-03 10:00:00

每次都返回一个空数组。 感谢您的帮助。

最佳答案

我弄清楚了问题所在。发现问题在于 postgresql jdbc 连接器的依赖项不起作用。

关于javascript - 总是在独立的 tomcat 中返回空的 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41354508/

相关文章:

ios - 为什么我的 Safari 推送通知的日志记录 Web 服务端点收到空白请求且没有错误消息

java - 部署到 WAS Liberty Profile,无需 jax-ws

javascript - Facebook登录验证码调用循环函数两次

javascript - 在 JsTestDriver 中设置 CoffeeScript 单元测试

java - 当我尝试返回 http 响应时应用程序崩溃

json - 如何在 swift 4 的 httpBody 中同时发送字符串值和 json 值

javascript - 在三元运算符中执行函数

javascript - AngularJS : concatenate depending on variable value

python - Python中用户类的序列化

android - org.xmlpull.v1.XmlPullParserException : expected: START_TAG {http://schemas. xmlsoap.org/soap/envelope/