Java文件方法1:
@Resource(name="questionnaireService")
private QuestionnaireService questionnaireService;
@Resource(name="quserInfoRecordService")
private QuserInfoRecordService quserInfoRecordService;
@RequestMapping(value="#")
public ModelAndView insertQuestionnaire(HttpServletRequest request,HttpServletResponse response){
String userid = getCurrentUserid(request, response);
ModelAndView mav=new ModelAndView();
List<Questionnaire> list=questionnaireService.findQuestionnaire(userid);
if(list.size()>0){
System.out.println("已经存在有问卷");
Questionnaire quest=list.get(0);
mav.addObject("title", quest.getTitle());
mav.addObject("time", quest.getTime());
mav.addObject("link", quest.getLink());
mav.addObject("imagelink", quest.getImagelink());//图片链接
//System.out.println("======"+quest.getExt());
mav.addObject("ext", quest.getExt());
mav.addObject("status", quest.getStatus());
mav.addObject("qid", quest.getQid());
}else{
Questionnaire quest=new Questionnaire();
quest.setUserid(userid);
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
String qid=sdf.format(date);
quest.setQid(qid);
quest.setTitle("默认问卷方案一");
quest.setTime("2:00");
quest.setStatus(1);
quest.setLink("http://v.polyv.net/uc/main");
quest.setImagelink("http://v.polyv.net/uc/main");
List<String> listName=new ArrayList<String>();
listName.add("姓名");
listName.add("手机");
listName.add("邮箱");
List<String> listNote=new ArrayList<String>();
listNote.add("请填写真实姓名");
listNote.add("请填写真实的手机号码");
listNote.add("建议填写QQ邮箱");
JSONArray array = new JSONArray();
JSONObject member = null;
for (int i = 0; i < 3; i++)
{
member = new JSONObject();
member.put("name", listName.get(i));
member.put("note", listNote.get(i));
array.add(member);
}
quest.setExt(array.toString());
questionnaireService.addQuestionnaire(quest);
System.out.println("初始化成功");
}
mav.setViewName("/video/userInfoRecord");
return mav;
}
Java文件方法2:
///修改问卷设置
@RequestMapping(value="/#",method={RequestMethod.GET,RequestMethod.POST})
public ModelAndView updataQuestionnaire(HttpServletRequest request, HttpServletResponse response){
ModelAndView mav=new ModelAndView();
String userid = getCurrentUserid(request, response);
ParamUtil pu = new ParamUtil(request);
Questionnaire quest=new Questionnaire();
quest.setUserid(userid);
quest.setQid(pu.getString("qid"));
quest.setTitle(pu.getString("title"));
quest.setTime(pu.getString("time"));
quest.setStatus(1);
quest.setLink(pu.getString("link"));
if(StringUtil.isFine(pu.getString("tg_content_txt"))){
quest.setImagelink(pu.getString("tg_content_txt"));
}else{
quest.setImagelink(pu.getString("imagelink"));
}
System.out.println("==qid===="+pu.getString("qid"));
int count=Integer.parseInt(pu.getString("fieldcount"));
List<String> nameList=new ArrayList<String>();
List<String> noteList=new ArrayList<String>();
for(int i=0;i<count;i++){
nameList.add(pu.getString("rname"+i));
noteList.add(pu.getString("rurl"+i));
}
JSONArray array = new JSONArray();
JSONObject member = null;
for (int i = 0; i < count; i++)
{
member = new JSONObject();
member.put("name", nameList.get(i));
member.put("note", noteList.get(i));
array.add(member);
}
quest.setExt(array.toString());
questionnaireService.updateQuestionnaire(quest);
System.out.println("修改成功");
mav.setViewName("/video/userInfoRecord");
return null;
}
解析json串的方法:
///播放器post过来的访客的资料
@RequestMapping(value="/#",method={RequestMethod.GET,RequestMethod.POST})
public void addQuserInfoRecord(HttpServletRequest request,HttpServletResponse response){
ParamUtil pu = new ParamUtil(request);
QuserInfoRecord quir=new QuserInfoRecord();
System.out.println("播放器提交数据进来了?");
String jsondata=request.getParameter("data");
System.out.println("========="+jsondata);
if(StringUtil.isFine(jsondata)){
JSONObject json=JSONObject.fromObject(jsondata);
//System.out.println("---success----");
String vid=json.getString("vid");
String jsonArray=json.getString("field");
System.out.println("-------"+jsonArray);
String userid=vid.substring(0,10);//从0开始截取前10位字符
quir.setUserid(userid);
quir.setQid(json.getString("id"));
quir.setIp(pu.getIP());
//System.out.println("==============="+pu.getIP());
//System.out.println("==============="+json.getString("vid"));
String video_pool_id=vid.substring(0, vid.length()-2);//去掉后面两个字母
String hostid = getCurrentUseridFirstChar(vid);
DOC videopool =new Video_pool_db(hostid).getOne(video_pool_id);///
//System.out.println("========doc==========="+videopool);
//System.out.println("=====vtitle========="+videopool.get("title"));
quir.setSourcetitle(videopool.get("title"));
quir.setPagelink(json.getString("link"));
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss");
String dataString=sdf.format(date);
quir.setDate(dataString);
quir.setExt(jsonArray);
quserInfoRecordService.addQuserInfoRecord(quir);//保存数据
System.out.println("controller save data success");
}
}
Java模版文件:
<script >
$(document).ready(function(){
var data=$("#json").val();
var arr=eval(data);
var count=0;
for(var i=0; i<arr.length;i++){
var name=arr[i].name;
$("#fieldContent").append("<p id='rmenu"+count+"'>字段名:<input style='width:70px' name='rname"+count+"' type='text' value='"+name+"' />注释:<input style='width:100px' name='rurl"+count+"' type='text' value='"+arr[i].note+"' /><input name='' οnclick=removefield('rmenu"+count+"') value='删除' type='button' /></p>");
count++;
}
$("#fieldcount").val(count);
var imglink="$!{imagelink}";
$("input[name=tg_content_txt]").val(imglink);
});
function addfield(){
if(parseInt($("#fieldcount").val())<5){
var fieldcount= parseInt($("#fieldcount").val());
$("#fieldContent").append("<p id='rmenu"+fieldcount+"'>字段名:<input style='width:70px' name='rname"+fieldcount+"' type='text' value='' />注释:<input style='width:100px' name='rurl"+fieldcount+"' type='text' value='' /><input name='' οnclick=removefield('rmenu"+fieldcount+"') value='删除' type='button' /></p>");
fieldcount=fieldcount+1;
$("#fieldcount").val(fieldcount);
}else{
alert("数量不能超过5");
}
}
function removefield(id){
$("#"+id).remove();
var fieldcount= parseInt($("#fieldcount").val());
$("#fieldcount").val(fieldcount-1);
}
$("#questionBt1").click(function(){
window.parent.alertMsg.correct('数据提交成功');
});
</script>
<div class="panel mt5">
<h1>调查问卷设置</h1>
<div style="">
<form action="#" method="post" enctype="multipart/form-data" class="pageForm" οnsubmit="return validateCallback(this)" target="callbackframe" id="questionnaire">
<input id="fieldcount" name="fieldcount" type="hidden" value="" />
<input id="json" name="json" type="hidden" value=$!{ext} />
<input id="qid" name="qid" type="hidden" value="$!{qid}" />
<table border="0">
<tr>
<td>标题:<input type="text" name="title" value="$!{title}"/>
<span>出现的时间:<input type="text" name="time" value="$!{time}"/></span>
</td>
<td><a class="button" href="/uc/quserInfoRecord/selectInfo?qid=$!{qid}" target="dialog" rel="dlg_page1" max="true" width="800" height="480"><span>查看数据</span></a></td>
</tr>
<tr>
<td colspan="2">
<span>图片跳转链接:<input type="text" id="link" name="link" size="50" value="$!{link}"/></span>
</td>
</tr>
<tr>
<td colspan="2">
##<iframe src="http://uimg.videocc.net/polyv" frameborder="0" width="400" height="60"></iframe>
<p style="padding:3px 0">
<label>图片地址:</label>
<input type="hidden" id="imagelink" class="textInput" name="imagelink" style="width:120px" value="$!{imagelink}"/>
<input type="text" class="textInput" name="tg_content_txt" style="width:120px" value="$!tg_content_txt"/>
<input type="button" value="上传图片" uimg="parent.input[name=tg_content_txt]" />
<a href="$!{imagelink}" target="_blank">查看当前链接</a>
</p>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td colspan="2"><img src="$!{imagelink}" width="500" height="200"/></td>
</tr>
<tr>
<td>
<input name="" type="button" value="添加" οnclick=addfield() />
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div id="fieldContent"></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><input type="submit" id="questionBt1" value="保存"/></td>
</tr>
</table>
</form>
</div>
</div>
<script>
setTimeout(function(){
$("input[name=tg_position]").each(function(){
if ($(this).val()=="$!tg_position") {
$(this).attr("checked", "1");
}
});
var tg_content = "$!tg_content";
tg_content_type = tg_content.substring(0, tg_content.indexOf(":"));
tg_content_txt = tg_content.substring(tg_content.indexOf(":")+1);
$("input[name=tg_content_type][value="+tg_content_type+"]").attr("checked", "1");
$("input[name=tg_content_txt]").val(tg_content_txt);
$("input[uimg]").uimg();
},50);
function init_tg_content(o){
var type = $(o).find("input[name=tg_content_type]:checked").val();
var txt = $(o).find("input[name=tg_content_txt]").val();
$(o).find("input[name=tg_content]").val(type+":"+txt);
return true;
}
</script>
用于读取参数的xml文件:
if(StringUtil.isFine(vdoc.get("qid"))){
String qid=vdoc.get("qid");
writer.append("<userInfoRecord>");
List<Questionnaire> list=questionnaireService.findOneByqid(qid);
if(list.size()>0){
Questionnaire quest=list.get(0);
writer.append("<userid>").append(xmlattr(quest.getUserid())).append("</userid>");
writer.append("<qid>").append(xmlattr(quest.getQid())).append("</qid>");
writer.append("<title>").append(xmlattr(quest.getTitle())).append("</title>");
writer.append("<time>").append(xmlattr(quest.getTime())).append("</time>");
writer.append("<imagelink>").append(xmlattr(quest.getImagelink())).append("</imagelink>");
writer.append("<link>").append(xmlattr(quest.getLink())).append("</link>");
writer.append("<fields>");
JSONArray jsonArray = JSONArray.fromObject(quest.getExt());
//String[] stringArray = new String[jsonArray.size()];
for(int i=0;i<jsonArray.size();i++){
JSONObject ext=jsonArray.getJSONObject(i);
writer.append("<item>");
writer.append("<name>").append(xmlattr(ext.get("name"))).append("</name>");
writer.append("<msg>").append(xmlattr(ext.get("note"))).append("</msg>");
writer.append("</item>");
}
writer.append("</fields>");
}
writer.append("</userInfoRecord>");
}
ibatis的映射文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="question">
<typeAlias alias="questionnaire" type="com.cc.ovp.domain.Questionnaire" />
<typeAlias alias="doc" type="ayou.util.DOC" />
<sql id="_columns">
qid, userid, title, time, link, imagelink, ext, status
</sql>
<insert id="insert" parameterClass="questionnaire">
<![CDATA[
insert into questionnaire
(qid, userid, title, time, link, imagelink, ext, status)
values
(#qid#, #userid#, #title#, #time#, #link#, #imagelink#, #ext#, #status#)
]]>
</insert>
<select id="selectInfo" parameterClass="questionnaire" resultClass="questionnaire">
select * from questionnaire where userid=#userid#
</select>
<select id="selectInfoByuserid" parameterClass="java.lang.String" resultClass="questionnaire">
select * from questionnaire where userid=#userid#
</select>
<select id="selectInfoByqid" parameterClass="java.lang.String" resultClass="questionnaire">
select * from questionnaire where qid=#qid#
</select>
<update id="updateInfo" parameterClass="questionnaire">
update questionnaire set title=#title#, time=#time#, link=#link#, imagelink=#imagelink#, ext=#ext#, status=#status# where userid=#userid#
</update>
</sqlMap>
部分效果图:(预览地址: http://v.polyv.net/uc/user/login)