尚方宝剑之说
假设你的html如下:
<div class="content">
<div class="title">
<span>标题:</span><input type="text" class="title"/>
</div>
<div class="list">
<div class="item">
<span>题目:</span><input type="text" class="question"/>
<span>选项:</span><input type="text" class="option"/>
<span>选项:</span><input type="text" class="option"/>
<span>选项:</span><input type="text" class="option"/>
<span>选项:</span><input type="text" class="option"/>
</div>
<div class="item">
<span>题目:</span><input type="text" class="question"/>
<span>选项:</span><input type="text" class="option"/>
<span>选项:</span><input type="text" class="option"/>
<span>选项:</span><input type="text" class="option"/>
<span>选项:</span><input type="text" class="option"/>
</div>
</div>
</div>
你可以用js或者jquery,将问卷当做一个js对象,然后格式化为json字符串进行传输。
<script type="text/javascript">
var title = $('.content .title input').val();
// 获取<div class='item'>标签数组
var itemList = $('.content div.list').children();
var itemArray = [];
for (int i = 0; i < itemList.length; i++) {
var question = itemList[i].class('.question').val();
var options = [];
itemList.class('option').each(function(index, value){
options.push($(this).val());
});
itemArray.push({question: question, option: options});
}
// 得到的对象格式形如:
/*{
title: "title",
question: [
{
question: "Which kind of animal do you like most?",
option: ["horse", "koala", "rabbit", "panda"]
},
{
question: "Which kind of animal do you like most?",
option: ["horse", "koala", "rabbit", "panda"]
}
]
}*/
var combinedParam = {title: title, question: itemArray};
// 将combinedParam转为JSON字符串传给后台
// ...
</script>
我不懂js所以以上的代码你权当伪代码看。java端获取JSON字符串以后,反序列化得到JSON对象,然后根据需要,该怎么存表就怎么存。