-2
我有一個連接,控制器類和jsp文件,我想將我從PostgreSQL的sql查詢得到的數據轉換成jsp。我怎樣才能顯示我的結果從數據庫上的JSP由春mvc
我是新的春天:有沒有人可以幫助我。感謝
這是我的連接類:
public class PostGisConnection {
public Connection getConn(){
Connection connection = null;
try{
String url = "jdbc:postgresql://127.0.0.1:5432/imposm3";
String user = "postgres";
String passwd = "mypass";
connection = DriverManager.getConnection(url, user, passwd);
String query1="Select * from imposm3";
Statement mystmt = connection.createStatement();
ResultSet myRrs = mystmt.executeQuery(query1);
while (myRrs.next()) {
System.out.println(myRrs.getString("id") + ", " + myRrs.getString("tags") + "," + myRrs.getString("geom"));
}catch (SQLException e){
e.printStackTrace();
return null;
}
}
}
}
這是我的控制器:
@RequestMapping(method = RequestMethod.GET, path = "/createObject")
public String viewSchema() {
return "/index";
}
}
,這是我的jsp:在後PostGisConnection
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>saeed</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<form action="/createObject" method="GET" >
<table>
<tr>
<th>OSM_ID</th>
<th>TAGS</th>
<th>GEOMETRY</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</form>
商店DB導致一些豆,豆返回的列表中一個ModelAndView,並在JSP中使用A JSTL的forEach?看到這個例子:https://www.mkyong.com/spring-mvc/spring-mvc-and-list-example/ – 2016-11-07 10:36:12