欢迎大家来到IT世界,在知识的湖畔探索吧!
(1),模板list_jsp.ftl文件
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String childPath = request.getContextPath();
String basePath = request.getScheme()+"://"
+request.getServerName()+":"+request.getServerPort()+ childPath +"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<%@ include file="/pub/scripts.jsp"%>
<script type="text/javascript">
function gotoPageSub(){
var varCurPageIdx = $("#curPageIdx").val();
varCurPageIdx = parseInt(varCurPageIdx) + 1;
var varPages = $("#pages").val();
if(parseInt(varCurPageIdx) > parseInt(varPages) ) {
// 没有下一页按钮置灰
$("#pageSub").attr("disabled", true);
$("#pageSub").remove("href");
} else {
$("#curPageIdx").val(varCurPageIdx);
submit_seach();
}
}
function gotoPageAdd(){
var varCurPageIdx = $("#curPageIdx").val();
varCurPageIdx = parseInt(varCurPageIdx) - 1;
var varPages = $("#pages").val();
if(parseInt(varCurPageIdx) < 1) {
// 没有上一页按钮置灰
$("#pageSub").attr("disabled", true);
$("#pageSub").remove("href");
} else {
$("#curPageIdx").val(varCurPageIdx);
submit_seach();
}
}
function submit_seach_real() {
$("#curPageIdx").val( 1 );
$("#serachForm").submit();
}
function submit_seach() {
$("#serachForm").submit();
}
function testT00_userModifyJs() {
var checkNum = 0;
var tid = 0;
$("input[name='tidChx']").each(function(){
if($(this).attr("checked")) {
checkNum = parseInt(checkNum) + 1;
tid = $(this).val();
}
});
if(checkNum > 1) {
alert("只能选中一条数据进行修改!");
return false;
}
else if(checkNum == 0) {
alert("请选择其中的一条数据进行修改!");
return false;
} else {
$("#btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Modify").attr("href", "<%=childPath %>/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Conter/get<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>?tid="+ tid);
return true;
}
}
function testT00_userDispJs() {
var checkNum = 0;
var tid = 0;
$("input[name='tidChx']").each(function(){
if($(this).attr("checked")) {
checkNum = parseInt(checkNum) + 1;
tid = $(this).val();
}
});
if(checkNum > 1) {
alert("只能选中一条数据进行查看!");
return false;
}
else if(checkNum == 0) {
alert("请选择其中的一条数据进行查看!");
return false;
} else {
$("#btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Disp").attr("href", "<%=childPath %>/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Conter/get<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Disp?tid="+ tid);
return true;
}
}
function testT00_userDelJs() {
var checkNum = 0;
var tid = 0;
$("input[name='tidChx']").each(function(){
if($(this).attr("checked")) {
checkNum = parseInt(checkNum) + 1;
tid = $(this).val();
}
});
if(checkNum > 1) {
alert("只能选中一条数据进行删除!");
return false;
}
else if(checkNum == 0) {
alert("请选择其中的一条数据进行删除!");
return false;
} else {
$("#btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Del").attr("href", "<%=childPath %>/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Conter/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Del?tid="+ tid);
return true;
}
}
</script>
</head>
<body>
<!-- 标题区域 -->
<div class="tleBg">
<div class="title">
<span class="txt"> <em></em><#list mapDataTableComment as listItmCom > ${listItmCom.columnComment} </#list>- 列表
</span> <a href="javascript:;" class="search-hide"></a>
</div>
<div class="clr"></div>
</div>
<!-- 查询维度区域 -->
<div class="t_list" id="searchtable">
<form name="serachForm" id="serachForm" action="<%=childPath %>/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Conter/query_<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>List" method="post">
<input type="hidden" id="curPageIdx" name="curPageIdx" value="美元符左大括<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Dto.curPageIdx右大括" />
<input type="hidden" id="pages" name="pages" value="美元符左大括<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Dto.pages右大括" />
<table border="0" cellspacing="0" cellpadding="0" class="t_list_1">
<tbody>
<tr>
<td class="text">
名称:
</td>
<td>
<input type="text" id="name_" name="name_" class="inputStyle" value="美元符左大括testT00_userDto.name_右大括" />
</td>
<td>
年龄:
</td>
<td>
<input type="text" id="age" name="age" class="inputStyle" value="美元符左大括testT00_userDto.age右大括" />
</td>
</tr>
自己选择加入查询条件
<#list mapDataList as listItm >
${listItm.columnComment}: 元素ID ${listItm.columnName}
</#list>
<tr>
<td class="text">
</td>
<td>
</td>
<td>
</td>
<td>
<input type="button" id="btn_search" value="查 询" class="t_button_gray" onclick="submit_seach_real()" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="t_title">
<a href="<%=childPath %>/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Conter/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Add" class="btn-def" id="btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Add">新 增</a>
<a href="#" class="btn-def" id="btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Modify" onclick="return <#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>ModifyJs()">修 改</a>
<a href="#" class="btn-def" id="btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Del" onclick="return <#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>DelJs()">删 除</a>
<a href="#" class="btn-def" id="btn<#list mapDataTableComment as listItmCom > ${listItmCom.upperColumnName} </#list>Disp" onclick="return <#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>DispJs()">查 看</a>
</div>
<div class="t-table-Frame">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="t-table">
<thead>
<tr class="titleBg">
<#list mapDataList as listItm >
<td>${listItm.columnComment}</td>
</#list>
</tr>
</thead>
<tbody>
<c:forEach items="美元符左大括listTestT00_userDto}" var="testT00_user" varStatus="k">
<tr>
<td>
<input type="checkbox" name="tidChx" value="美元符左大括testT00_user.tid}" title="美元符左大括testT00_user.tid}">
<a href="#">
美元符左大括testT00_user.tid}
</a>
</td>
<#list mapDataList as listItm >
<td>美元符左大括<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>.${listItm.columnName}</td>
</#list>
</tr>
</c:forEach>
<tr>
<td colspan="3" style="text-align: left">
共美元符左大括testT00_userDto.pages}页, 当前第美元符左大括testT00_userDto.curPageIdx}页 <a onclick="gotoPageAdd()" href="#" id="pageAdd">上一页</a> <a onclick="gotoPageSub()" id="pageSub" href="#">下一页</a>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
欢迎大家来到IT世界,在知识的湖畔探索吧!
(2),生成jsp列表页
欢迎大家来到IT世界,在知识的湖畔探索吧!public class TestCls {
public static void main(String[] args) throws Exception {
TestCls testCls = new TestCls();
String testT00_po = "testT00_user";
String generFileName = testT00_po + "List.jsp";
testCls.outTemplate(testT00_po, "用户数据"
, generFileName, "list_jsp.ftl" );
System.out.println("执行成功!");
}
// 输出到模板
private void outTemplate(String entryInfoPoName, String tableComment
, String templateFileName , String templFileName ) throws Exception {
Configuration configuration = new Configuration();
String templateDir = "F:\\xbl\\myResource\\temp_test_";
configuration.setDirectoryForTemplateLoading(new File(templateDir));
Template template = configuration.getTemplate(templFileName);
Map<String, List<EntryInfoPo>> dataMap = new HashMap<String, List<EntryInfoPo>>();
List<EntryInfoPo> listEntryInfo = new ArrayList<EntryInfoPo>();
listEntryInfo = testMetaAddComment();
dataMap.put("mapDataList", listEntryInfo );
// 表注释
dataMap.put("mapDataTableComment", testTableComment(entryInfoPoName, tableComment ));
String generFileDir = "F:\\xbl\\myResource\\temp_test_\\gener_file_\\";
File generFile = new File(generFileDir + templateFileName);
if(generFile.exists()) {
generFile.delete();
}
generFile.createNewFile();
Writer outputWriter = new OutputStreamWriter(new FileOutputStream(generFile ) );
// Writer outputWriter = new OutputStreamWriter(System.out );
template.process(dataMap, outputWriter);
System.out.println("输出完成!");
outputWriter.close();
}
// 表注释
private List<EntryInfoPo> testTableComment(String entryInfoPoName, String tableComment) throws Exception {
List<EntryInfoPo> listTableComment = new ArrayList<EntryInfoPo>();
EntryInfoPo entryInfoPo = new EntryInfoPo();
entryInfoPo.setColumnName(entryInfoPoName);
entryInfoPo.setColumnComment(tableComment);
entryInfoPo.setUpperColumnName(firTextUpper( entryInfoPoName ) );
listTableComment.add(entryInfoPo);
return listTableComment;
}
// 首字母大写
private String firTextUpper(String scontext ) {
int textLength = scontext.length();
String sufText = scontext.substring(1, textLength);
String firText = scontext.substring(0, 1);
firText = firText.toUpperCase();
String finText = firText + sufText;
return finText;
}
private List<EntryInfoPo> testMetaAddComment() throws Exception {
List<EntryInfoPo> listEntryInfoPo = new ArrayList<EntryInfoPo>();
Connection connection = getDataBaseConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("show full columns from t00_user ");
while (resultSet.next()) {
String columnComment = resultSet.getString("Comment");
String columnName = resultSet.getString("Field");
columnName = columnName.toLowerCase();
EntryInfoPo entryInfoPo = new EntryInfoPo();
entryInfoPo.setColumnName(columnName);
entryInfoPo.setColumnComment(columnComment);
listEntryInfoPo.add(entryInfoPo);
}
return listEntryInfoPo;
}
private Connection getDataBaseConnection() throws Exception {
// 连接数据库
Class.forName("com.mysql.jdbc.Driver");
String databaseUrl = "jdbc:mysql://127.0.0.1:3306/grcdb05?useUnicode=true&characterEncoding=utf8";
Connection connection = DriverManager.getConnection(databaseUrl, "root", "root");
return connection;
}
}
(3),注意替换空格
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/35352.html