关闭

SpringMVC+AJAX

2438人阅读 评论(0) 收藏 举报
分类:

AJAX


JSP

   1、添加书签 :    <a href="JavaScript:void(0)" onclick="bookmark()">添加书签</a>  

 

   2、AJAX 

   <script type="text/javascript">  
  function bookmark(){
  $.ajax({
                url:"book_mark?"+"id=<%=chartid%>&line=0",
                type: 'get',
                
                dataType:"text",
                success:function(data){
                    
                    alert(data);
                },
                error:function(data){
                    
                    alert(data);
                }
            }); 
           }
 </script>


3、后台处理

@RequestMapping(value = "/home/book_mark", method = RequestMethod.GET)
public ModelAndView book_mark(HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap) throws Exception {
String flag = "success";
try {
VUser user = (VUser) request.getSession().getAttribute("User");
String bookSN = request.getParameter("bookSN");
String line = request.getParameter("line");
String id = request.getParameter("id");


Sbook book = savebook.fetchbookBySN(savechartbook.fetchChartById(
Integer.parseInt(request.getParameter("id").toString()))
.getBookSN(), String.valueOf(user.getUserLevel()));
BookSheet sheet = new BookSheet();
sheet.setBookId(book.getBookId());
sheet.setU_OId(user.getU_OId());
sheet.setReadState("0");
sheet.setChartId(Integer.parseInt(request.getParameter("id")
.toString()));
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss");
Date curDate = new Date(System.currentTimeMillis());//  
String str = formatter.format(curDate);
sheet.setLastDate(str);
sheet.setMarkPosition("0");
// 如果书签存在,覆盖以前的书签
if (booksheet.fetchBookSheetByConditionAndId(user.getU_OId(), "0",
book.getBookId()).size() > 0) {
sheet.setUserBookId(booksheet.fetchBookSheetByConditionAndId(
user.getU_OId(), "0", book.getBookId()).get(0)
.getUserBookId());
booksheet.modifyBoookSheet(sheet);
} else if (booksheet.fetchBookSheetByConditionAndId(
user.getU_OId(), "1", book.getBookId()).size() > 0) { // 如果书签停用,激活书签
sheet.setUserBookId(booksheet.fetchBookSheetByConditionAndId(
user.getU_OId(), "1", book.getBookId()).get(0)
.getUserBookId());
sheet.setReadState("0");
booksheet.modifyBoookSheet(sheet);
} else {// 如果书签不重在,直接添加书签
booksheet.saveBookSheet(sheet);
}
} catch (Exception e) {


flag = "false";
e.printStackTrace();
}
modelMap.put("flag", flag);
return new ModelAndView("/home/bookmark", modelMap);
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:212085次
    • 积分:2462
    • 等级:
    • 排名:第15916名
    • 原创:43篇
    • 转载:53篇
    • 译文:0篇
    • 评论:17条
    最新评论
    阻止网站镜像技术