클래스 주석을 바탕으로 대상 데이터를 excel로 내보내기
15889 단어 주석 excel
@Retention(value=RetentionPolicy.RUNTIME)
@Target(value=ElementType.FIELD)
public @interface AllowExcel {
boolean value() default true;
String name();//
int width();//
int pos();//
String map() default "";//
String format() default "";// ,
}
web excel :
@RequestMapping(value="/exportEvents")
public void exportExcelByDate(HttpServletRequest request,HttpServletResponse response,String startDate,String endDate) throws IOException, Exception{
response.reset();
String fileName = " ("+ startDate + "-" + endDate + ")";
response.addHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "iso8859-1") + ".xls");
eventService.exportEvents(startDate, endDate, response.getOutputStream());
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
<c:set var="contextPath" value="${pageContext.request.contextPath}/assets" />
<c:set var="cssBasePath" value="${contextPath}/css" />
<c:set var="scriptBasePath" value="${contextPath}/js" />
<link rel="${cssBasePath}" href="assets/css/dropzone.css" />
<link href="${cssBasePath}/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="${cssBasePath}/font-awesome.min.css" />
<!-- page specific plugin styles -->
<link rel="stylesheet" href="${cssBasePath}/jquery-ui-1.10.3.full.min.css" />
<link rel="stylesheet" href="${cssBasePath}/ui.jqgrid.css" />
<link rel="stylesheet" href="${cssBasePath}/datepicker.css" />
<link rel="stylesheet" href="${cssBasePath}/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" href="${cssBasePath}/chosen.css" />
<!-- ace styles -->
<link rel="stylesheet" href="${cssBasePath}/ace.min.css" />
<link rel="stylesheet" href="${cssBasePath}/ace-rtl.min.css" />
<link rel="stylesheet" href="${cssBasePath}/ace-skins.min.css" />
<link href="${pageContext.request.contextPath}/common/public.font.css"
rel="stylesheet" type="text/css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="${scriptBasePath}/jquery-2.0.3.min.js"></script>
<script src="${scriptBasePath}/jquery-ui-1.10.3.full.min.js"></script>
<script src="${scriptBasePath}/bootstrap.min.js"></script>
<!-- ace scripts -->
<script src="${scriptBasePath}/ace-elements.min.js"></script>
<script src="${scriptBasePath}/ace.min.js"></script>
<script src="${scriptBasePath}/date-time/bootstrap-datetimepicker.js"></script>
<script src="${scriptBasePath}/date-time/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${scriptBasePath}/fuelux/fuelux.wizard.min.js"></script>
<script src="${scriptBasePath}/jquery.validate.min.js"></script>
<script src="${scriptBasePath}/additional-methods.min.js"></script>
<script src="${scriptBasePath}/bootbox.min.js"></script>
<script src="${scriptBasePath}/jquery.maskedinput.min.js"></script>
<script src="${scriptBasePath}/select2.min.js"></script>
<script src="${scriptBasePath}/chosen.jquery.min.js"></script>
<script type="text/javascript">
try {
ace.settings.check('main-container', 'fixed');
} catch (e) {
}
</script>
<style type="text/css">
label
{
font-size: 14px;color: #478fca;font-weight: bolder;
}
a{
cursor: pointer;
}
</style>
</head>
<body>
<div class="main-container" id="main-container">
<div class="main-container-inner">
<div class="main-content">
<div class="page-content">
<div class="row">
<div class="col-xs-12">
<div class="widget-box transparent">
<div class="widget-body">
<form class="form-horizontal" id="exportForm">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"> </label>
<div class="col-sm-9">
<div class="col-xs-4">
<div class="input-group input-group-sm">
<input type="text" id="startDate"
name="startDate" placeholder=" "
class="form-control date-picker"
data-date-format="yyyy-mm-dd" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
<div class="col-xs-4">
<div class="input-group input-group-sm">
<input type="text" id="endDate"
name="endDate" placeholder=" "
class="form-control date-picker"
data-date-format="yyyy-mm-dd" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
</div>
<div class="col-md-offset-4 col-md-6">
<button class="btn" type="reset" id="clean">
<i class="icon-refresh bigger-100"></i>
</button>
<button class="btn btn-info" type="button" id="searchList">
<i class="icon-search bigger-100"></i>
</button>
</div>
</form>
</div>
<!-- /widget-box -->
</div>
</div>
</div>
<!-- /.page-content -->
</div>
<!-- /.main-content -->
</div>
<!-- /.main-container-inner -->
</div>
<!--/ .main-container-->
<script type="text/javascript">
var $path_base = "/";//this will be used in gritter alerts containing images
jQuery(function($) {
$('#startDate').val('');
$('#endDate').val('');
$(".date-picker").datetimepicker({
autoclose : true,
language : 'zh-CN',
format : 'yyyy-mm-dd',
minView : 2
}).on(ace.click_event, function() {
});
$('.date-picker').datetimepicker({
autoclose: true
}).next().on(ace.click_event,
function() {
//console.log('debug');
$(this).prev().focus();
});
jQuery.validator.methods.compareDate = function(value, element, param) {
//var startDate = jQuery(param).val() + ":00"; yyyy-MM-dd HH:mm:ss
//value = value + ":00";
var startDate = jQuery(param).val();
if (startDate !='') {
var date1 = new Date(Date.parse(startDate.replace("-", "/")));
var date2 = new Date(Date.parse(value.replace("-", "/")));
return date1 < date2;
} else {
return true;
}
};
$('#exportForm').validate(
{
errorElement : 'div',
errorClass : 'help-block',
focusInvalid : false,
rules : {
startDate:{
required : true,
date : true
},
endDate : {
required : true,
date : true,
compareDate: "#startDate"
}
},
messages : {
startDate : {
required:" ",
date : " "
},
endDate : {
required : " ",
date : " ",
compareDate: " !"
}
},
invalidHandler : function(event, validator) { //display error alert on form submit
//$('.alert-danger', $('.login-form')).show();
},
highlight : function(e) {
$(e).closest('.form-group').removeClass(
'has-info').addClass('has-error');
},
success : function(e) {
$(e).closest('.form-group').removeClass(
'has-error').addClass('has-info');
$(e).remove();
},
errorPlacement : function(error, element) {
if (element.is(':checkbox')
|| element.is(':radio')) {
var controls = element
.closest('div[class*="col-"]');
if (controls.find(':checkbox,:radio').length > 1)
controls.append(error);
else
error.insertAfter(element.nextAll(
'.lbl:eq(0)').eq(0));
} else if (element.is('.select2')) {
error
.insertAfter(element
.siblings('[class*="select2-container"]:eq(0)'));
} else if (element.is('.chosen-select')) {
error
.insertAfter(element
.siblings('[class*="chosen-container"]:eq(0)'));
} else
error.insertAfter(element.parent());
},
submitHandler : function(form) {
},
invalidHandler : function(form) {
}
});
$('#startDate').datetimepicker().on('changeDate', function(ev){
$('#endDate').datetimepicker('setStartDate', ev.date);
});
$('#endDate').datetimepicker().on('changeDate', function(ev){
$('#startDate').datetimepicker('setEndDate', ev.date);
});
$("#clean").click(function() {
$('#startDate').val('');
$('#endDate').val('');
$('.help-block').remove();
$('.form-group').removeClass("has-error");
});
//
$("#searchList").click(function() {
if (!$('#exportForm').valid()) {
$('.btn-success').removeAttr("disabled");
return false;
} else {
$('.btn-success').attr('disabled',"true");
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
exportEvents(startDate,endDate);
}
});
});
function exportEvents(startDate,endDate) {
var form = $("<form id='downloadForm'>");
form.attr('style', 'display:none');
form.attr('target', '');
form.attr('method', 'post');
form.attr('action', '<c:url value="/regularmeeting/exportEvents.html"/>');
var input1 = $('<input>');
input1.attr('type', 'hidden');
input1.attr('name', 'startDate');
input1.attr('value', startDate);
var input2 = $('<input>');
input2.attr('type', 'hidden');
input2.attr('name', 'endDate');
input2.attr('value', endDate);
$('body').append(form);
form.append(input1);
form.append(input2);
form.submit();
form.remove();
}
</script>
</body>
</html>