我正在开发一个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();
}
}
所以问题是我访问网址时
http://localhost:8080/state?start=2012-03-03 00:00:00&end=2012-03-03 10:00:00
当我使用嵌入式tomcat时,它完美地给出了JSONdata。但是如果我在独立的tomcat中部署应用程序那么
http://localhost:8080/Application_Name/state?start=2012-03-03 00:00:00&end=2012-03-03 10:00:00
每次都返回一个空数组。 任何帮助表示赞赏。
答案 0 :(得分:1)
我弄清楚问题是什么。发现问题是postgresql jdbc连接器的依赖性无效。