1.mybatis用association进行关联
2.加载日期框$('.date-picker').datepicker();
3.多文件上传form加上enctype="multipart/form-data",文件标签栏加上multiple="multiple"(注意按住Ctrl加Shift一起选图片)
4.后台多文件上传用@RequestParam MultipartFile[] photos接收
获取图片的文件名String fileName = photo.getOriginalFilename();
5.表单提交前判断用οnsubmit="return CheckPost();"
6.获得本项目在Tomcat的路径 String path = req.getServletContext().getRealPath("/");
获取项目名 String webNameString = req.getServletContext().getContextPath();
将项目名替换为updateFiles path = path.replace(webNameString.substring(1), "updateFiles");
没有则创建updateFiles文件
File dir=new File(path);
if(!dir.exists()){
dir.mkdir();
}
7.页面跳转取消按钮采取刷新当前页面的方式
function cancel() {
$.ajax({
type: 'get',
url: 'major/list.do',
success: function (result) {
$('#page-content').html(result);
}
});
}
8.一级向二级页面跳转不能采取刷新当前页面的方式
function addDetail(base_id) {
top.jzts();
$.ajax({
type: 'get',
success: function (result) {
window.location.href="<%=basePath%>blzl/list.do?base_id=" + base_id;
top.hangge();
}
});
}
9.删除模态框
function deleteById(id) {
bootbox.confirm("确定要删除吗?", function(result) {
if(result) {
top.jzts();
var url = "<%=basePath%>tfywBase/delete.do?id=" + id;
$.get(url, function(data) {
setTimeout("self.location=self.location", 100);
top.diag.close();
});
}
});
}
10.Dialog增加模态框
function add(base_id){
top.jzts();
var diag = new top.Dialog();
diag.Drag=true;
diag.Title ="新增";
diag.URL = '<%=basePath%>blzl/goAddU.do?base_id='+base_id;
diag.Width = 600;
diag.Height = 600;
diag.CancelEvent = function(){ //关闭事件
if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
top.jzts();
setTimeout("self.location=self.location",100);
}
diag.close();
};
diag.show();
}
11.填充option
for (var i = 1; i < 11; i++){
$('#show_lev').append('<option value="'+i+'">'+i+'</option>');
}
显示及隐藏
$('#showorhide').show();
$('#showorhide').hide();
12.更新页面加载类型选择
$('#typeIdSelection').find("option[value='"+$('#typeId').val()+"']").attr("selected","selected");
<tr>
<td><select id="typeIdSelection" name="typeid">
<c:forEach items="${typeList}" var="type">
<option value="${type.ty_id}">${type.type_name}</option>
</c:forEach>
</td>
</tr>
13.根据系统获得换行符方法System.getProperty("line.separator")
14.列表页面根据数据库字段Y/N换显示是、否
<c:choose>
<c:when test="${tfywBase.sfcy eq 'Y' }"><td>是</td></c:when>
<c:when test="${tfywBase.sfcy eq 'N' }"><td>否</td></c:when>
</c:choose>
15.二级联动后台查询整个列表
<select id="typeIdSelection" name="type_two">
<option selected="selected" value="${tfywBase.typeSub.t_id}">${tfywBase.typeSub.type_name}</option>
</select>
$("#typeIdSelectionNew").change(function () {
var selectState = $(this).children('option:selected').val();
$('#typeIdSelection').empty();
if (selectState != "-1") {
$('#typeIdSelection').append('<option selected="selected" value="-1">请选择</option>');
<c:forEach items="${typeChildList}" var="typeChild">
if('${typeChild.O_ID}'==selectState){
$('#typeIdSelection').append('<option value="${typeChild.T_ID}">${typeChild.TYPE_NAME}</option>');
}
</c:forEach>
}
});
16.文件下载预览,PDF和图片是预览,其他文件下载
<a class="btn btn-mini btn-info" href="${base}/updateFiles/${tfywBase.jssmwd}">预览</a>
17.图片更新页面视图预览
<tr>
<td style="width:90px;text-align:left;padding-top: 13px;">
<div class="file-box">
<input id="photoCover1" type="file" name="photos" title="图片" class="file-btn" readonly="readonly" value="${type.image }" placeholder="点击选择图片"/>
</div>
<div id="view1">
<c:if test="${type.image!=null}">
<img src="<%=imagePath%>${type.image}_blue.png" alt="" id="icon" width="50px" height="50px"/>
</c:if>
</div><!-- 显示选择的图片 -->
</td>
</tr>
<%
String imagePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/updateFiles/";
%>
<script type="text/javascript">
//找到文件选择控制
var img = document.getElementById("photoCover1");
//绑定文件控件的选择事件
img.οnchange=function(){
//获取当前控件上选择的文件列表
var files = this.files;
//找到预览区域
var view = document.getElementById("view1");
//清空预览区域
view.innerHTML="";
var url=window.URL.createObjectURL(files[0]);
//创建 <img> 元素
var im = new Image();
//将图片的URL赋值 img 元素的src属性,显示图片
im.src = url;
//将图片添加到预览区域
view.appendChild(im);
};
</script>
18.主键ID从1往后加数字,后台实现
List<Type> typelist = typeService.typelist();
int max = 0;
for(int i=0;i<typelist.size();i++){
if(Integer.valueOf(typelist.get(i).getTypeId())>max){
max=Integer.valueOf(typelist.get(i).getTypeId());
}
}
Type type=new Type();
type.setTypeId(max+1+"");
19.关于换行问题
String newTitle = oldTitle.replace("||","<br>");(注意:html换行用<br>,不用\n)、
JS处理换行
<div><span id="test"></span></div>
<script type="text/javascript">
$().ready(function(){
var str = "变更||删除";
var newstr = str.replace(/\|/\|/g,"<br>");
$("#test").html(newstr);
});
</script>
20.关于判断填入值限制
截取id判断
if($("#bxj").val() == ''){
$("#bxj").tips({
side:3,
msg:'请输入报送资料',
bg:'#AE81FF',time:2
});
$("#bxj").focus();
return false;
}
截取name判断
if (blzlForm.typeId.value=="-1"){
alert("请选择资料类型");
blzlForm.typeId.focus();
return false;
}