1.打开一个新页面
$("#uploadfile").click(function(){
var contractId = $("#contractId").val();
var src = "${pageContext.request.contextPath}/contract/upLoadFile.do?menuId="+${menuId};
$('#openLoadframe')[0].src=src;
$('#openRoleDiv').window('open');
});
2.上传文件
<script language="javascript">
function setBack(index){
var filelist = $("tr td");
var allstr = "";
for (var i = 0; i< filelist.length; i++) {
var filetd = filelist.eq(i).text();
allstr =allstr + filetd + ",";
}
$(window.parent.$("#returnValue").textbox('setValue',allstr));
parent.$('#openRoleDiv').window('close');
}
</script>
<form method="post" action="${pageContext.request.contextPath}/contract/filesUpload.do" enctype="multipart/form-data" >
<input type="file" name="files" multiple="multiple"><span>可一次选择多文件</span><br><br>
<input type="submit" value="上传">
<input type="button" value="关闭" οnclick="setBack(${status.index});">
</form>
<table id = "test">
<c:forEach items="${flist}" var="flist" varStatus="status">
<tr>
<td id="picName${status.index}">${flist}</td>
</tr>
</c:forEach>
</table>
3.点击保存
@RequestMapping("/filesUpload.do")
public String filesUpload(@RequestParam(value = "files") MultipartFile[] files,String contractId,HttpServletRequest request) throws IOException {
List<String> flist = new ArrayList<>();
//判断file数组不能为空并且长度大于0
if(files!=null&&files.length>0){
//循环获取file数组中得文件
for(int i = 0;i<files.length;i++){
MultipartFile file = files[i];
//保存文件
saveFile(file,request);
flist.add(file.getOriginalFilename());
}
}
request.setAttribute("flist", flist);
return "contract/upLoadFile";
}
private boolean saveFile(MultipartFile file,HttpServletRequest request) {
// 判断文件是否为空
if (!file.isEmpty()) {
try {
// 文件保存路径
String filePath = ("D:/File/upload/") +
System.currentTimeMillis() +file.getOriginalFilename();
// 转存文件
File f1 = new File(filePath);
if(!f1.exists()){
f1.mkdirs();
}
file.transferTo(f1);
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
点击超链接而不跳转页面,默认调到iframe
<form name="frmPost1" action="http://www.baidu.com" method="post" target="hiddenIFrame">
<INPUT type="text" name="id" value="111">
<INPUT type="submit" value="Submit" name="Submit">
</form>
<iframe style="display:none" name="hiddenIFrame" id="hiddenIFrame"/>
@ResponseBody不带数据跳转页面的方式
@RequestMapping("/toNewsAllList.do")
@ResponseBody //joson格式注解
public ModelAndView toNewsAllList(HttpServletRequest request,Integer type) {
ModelAndView mv = new ModelAndView("oasystem/newsList");
return mv;
}
//后台将json转成字符串
String emp_name = new String(employee_name.getBytes("ISO8859-1"), "utf-8");
集成CKeditor(编辑器)和CKfinder(上传文件)
分类查询,每一种类查询最新5条记录(a.id,a.title,a.things_type,a.create_time,a.create_by,a.content,a.remark)
select a1.* from oa_things a1
inner join
(select a.id,a.title,a.things_type,a.create_time,a.create_by,a.content,a.remark from oa_things a left join oa_things b
on a.things_type=b.things_type and a.create_time<=b.create_time
group by a.things_type,a.create_time
having count(b.create_time)<=5
)b1
on a1.things_type=b1.things_type and a1.create_time=b1.create_time
order by a1.things_type,a1.create_time desc
xml文件里面的转译符
< < 小于号
> > 大于号
& & 和
' ’ 单引号
" " 双引号
sql语句的执行顺序:
(1)from 选取数据源;
(2)where 筛选数据源;
(3)group by 将筛选的数据源分组;
(4)使用聚集函数计算;
(5)having 筛选分组的数据;
(6)计算表达式;
(7)order by 排序;
js判断哪一天是星期几
function getMyDay(date){
var week;
if(date.getDay()==0) week="周日"
if(date.getDay()==1) week="周一"
if(date.getDay()==2) week="周二"
if(date.getDay()==3) week="周三"
if(date.getDay()==4) week="周四"
if(date.getDay()==5) week="周五"
if(date.getDay()==6) week="周六"
return week;
}
var w1 = getMyDay(new Date("2018/01/18"));
alert(w1)
date.getDay(){
天 1
一 2
二 3
三 4
四 5
五 6
六 0
}
var count = (endtime.getTime() - starttime.getTime()) / 1000 / 60 / 60 / 24;
if(am == '13:00:00' && pm == '12:00:00'){
if(endtime.getTime() == starttime.getTime()){
msg = '时间格式错误!请检查您输入的时间';
$.messager.alert('提示',msg);
flag = false;
return false;
}
}
if(am == '09:00:00' && pm == '18:00:00'){
count = count + 1;
}
if(am == '09:00:00' && pm == '12:00:00'){
count = count + 0.5;
}
if(am == '13:00:00' && pm == '18:00:00'){
count = count + 0.5;
}
//获得周六周日的天数
var newDate;
var wDays = 0;
for (var i = 0; i < count; i++) {
newDate = starttime.setDate(starttime.getDate()+1); //向前加一天
var time = new Date(newDate);
var dSum = time.getDay();
if(dSum == 0 || dSum == 1){
wDays = wDays + 1;
}
}
var dataObj
//获得系统设置的节假日天数
var url = '${pageContext.request.contextPath}/event/toSumDays.do?starttimeStr='+starttimeStr+'&endtimeStr='+endtimeStr+'&random='+Math.random();
$.ajax({
url: url,
async: false,
datatype: "jsonp",
type: "get",
success: function(result){
dataObj = JSON.parse(result); //返回的result为json格式的数据
}
});
var lastNum = count - wDays - dataObj;
count_num = lastNum;
$('#counttime').textbox("setValue", lastNum);
要是form提交路径后面非要带参数,导致路径过长,将路径中的参数截出来,用input的hidden隐藏的方式,name改成类中的属性,再提交到后台。
Jquery动态增加行和删除行并封装成list表单提交
动态增加表单jquery方法:
var i=0;
function addtr(){
$("#myTable").append("<tr><td><input id=\"sd\" type=\"checkbox\" name=\"ckb\" /> "+
" </td><td><input type=\"text\" name=\"list["+i+"].companyName\" /></td><td><input type=\"text\" name=\"list["+i+"].orgNo\" /></td><td><input type=\"text\" name=\"list["+i+"].draftingCity\" /> "+
" </td><td><input type=\"text\" name=\"list["+i+"].linkman\" /></td><td><input type=\"text\" name=\"list["+i+"].linkTel\"/></td>'</tr>");
i=i+1;
}
删除行的方法:
function delTr(ckb){
//获取选中的复选框,然后循环遍历删除
var ckbs=$("input[name="+ckb+"]:checked");
if(ckbs.size()==0){
alert("要删除指定行,需选中要删除的行!");
return;
}
ckbs.each(function(){
$(this).parent().parent().remove();
});
}
function allCheck(allCkb, items){
$("#"+allCkb).click(function(){
$('[name='+items+']:checkbox').attr("checked", this.checked );
});
}
$(function(){
//全选
allCheck("allCkb", "ckb");
})
function del() {
delTr('ckb');
}
打开子页面的方法
在局部父页面打开
function newDiolog(){
var customerId = $('#id').val();
$('#dlg').dialog({
title: '对话框',
iconCls:"icon-edit",
collapsible: true,
minimizable: true,
maximizable: true,
resizable: true,
width: 500,
height: 600,
modal: true,
href: "${pageContext.request.contextPath}/customer/addPerson.do?customerId="+customerId,
onClose: function () {
}
});
在整体父页面打开
var id = $('#id').val();
var url = "${pageContext.request.contextPath}/customer/addPerson.do?id=" + id;
parent.openDialog(url,window.screen.width*0.8,window.screen.height*0.75,'添加联系人');