如何显示在应用运行时获取的表的内容?

时间:2019-04-17 10:21:07

标签: java sql spring jsp dynamic

我有一个包含很多表的数据库。我创建了一个“ Referencer”类,dao,service,controller,rowmapper等,以便它将为给定的表名映射和显示适​​当的列(例如,如果我键入getReferencer(employee)和getReferencer(branch)等)即使列数不同,它也将显示各个表中的数据。它工作得很好,但是如何动态地在jsp中的表中显示此数据呢?

@Controller
@RequestMapping("/referencer")
public class ReferencerController {

@Resource
Service referencerService;


public List<Referencer> getReferencers(@RequestParam String tableName) 
{
    return referencerService.findAll(tableName);
}

@PostMapping(value = "/list")
@ResponseBody
public ModelAndView referencerssForm(@RequestParam String tableName) {
    ModelAndView model = new ModelAndView("DisplayRef");
    List<Referencer> refList = getReferencers(tableName);
    model.addObject("refss", refList);
    model.addObject("size", refList.size());

    return model;

    }
}

输出jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table border = "1">
<tr>
    <% for(int i = 1; i <= ${spravs}.size() /*or just ${size}*/; i++){ %>

    <td>
        ${spravs} //something else here i guess
    </td>   

    <% } %>
</tr>
</table>
</body>
</html>

0 个答案:

没有答案