近期做了一个前端信息上传数据库的功能,其项目框架依旧基于spring mvc + mybatis。
前端在jsp中将页面样式写好,其中文字信息是用js的一个工具类将用户输入的信息提交至后端,采用了在前端将用户选好的省、市、区、地址等点位信息先连成一个字符串,以逗号分开,这样可一并传入后端,再进行解析,此处以form表单的形式提交亦不失为一个好办法,但每种方法各有优劣,当以业务的使用和扩展方便为宜。前端连接信息代码如下,因为一个页面可提交多个点位,故这里采用了循环结构。
function savePointLocationInfos(){
var boxLength = $('.box').length;
var pointLocationInfos="start;";
for(var i=0; i<boxLength; i++){
//省市区
console.log(phone.length)
var temp=$('.box').eq(i).find('.pro').attr('data-province-code');
if(temp!=""){
pointLocationInfos+=temp;
}else{
pointLocationInfos+=",null";
}
temp=$('.box').eq(i).find('.pro').attr('data-city-code');
if(temp!=""){
pointLocationInfos+=","+temp;
}else{
pointLocationInfos+=",null";
}
temp=$('.box').eq(i).find('.pro').attr('data-district-code');
if(temp!=""){
pointLocationInfos+=","+temp;
}else{
pointLocationInfos+=",null";
}
temp=$('.box').eq(i).find('#back_explain').val();
if(temp!=""){
pointLocationInfos+=","+temp;
}else{
pointLocationInfos+=",null";
}
temp=$('.box').eq(i).find('#two').val();
if(temp!=""){
pointLocationInfos+=","+temp;
}else{
pointLocationInfos+=",null";
}
temp=$('.phone_wrap').fin