SpringMVC后台携带数据,实现局部页面跳转

Posted Vodka~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringMVC后台携带数据,实现局部页面跳转相关的知识,希望对你有一定的参考价值。

1.前台ajax


    $.ajax(
        url:"/GetCommentContent",
        type:"post",
        data: ,
        dataType:"json",
        async: true,
        //将后端传回的数据,用于渲染评论区
        success:function(data)
            console.log(data);
        
    );

2.后端springmvc

@Controller
public class CommentController 

    private ProcessComment processComment = new ProcessComment();

    //获取所有评论
    @RequestMapping(value = "/GetCommentContent",produces="text/html;charset=utf-8",method =RequestMethod.GET ,RequestMethod.POST )
    public String GetCommentInfo(HttpServletRequest request, HttpSession session)
        return processComment.GetComment(request,session);
    


@Service
public class ProcessComment 
    //获取评论,传到相应页面,并跳转
    public String GetComment(HttpServletRequest request, HttpSession session) 
        CustomerCommentInfo customerCommentInfo = new CustomerCommentInfo();   //自定义对象
        ArrayList<CustomerCommentInfo> CList = new ArrayList<>();
        //规范日期格式
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        CustomerCommentInfo C1 = new CustomerCommentInfo("vodka","2134239898", "这里的汽车还不错,可选择的品种多,还车方便",Timestamp.valueOf(df.format(new Date().getTime())));
         CustomerCommentInfo C2 = new CustomerCommentInfo("Alice","6456344363", "这里的汽车还不错,可选择的品种多,还车方便",Timestamp.valueOf(df.format(new Date().getTime())));
         CustomerCommentInfo C3 = new CustomerCommentInfo("William","fg46343434", "这里的汽车还不错,可选择的品种多,还车方便",Timestamp.valueOf(df.format(new Date().getTime())));
         CustomerCommentInfo C4 = new CustomerCommentInfo("K","uj65543534", "这里的汽车还不错,可选择的品种多,还车方便",Timestamp.valueOf(df.format(new Date().getTime())));
         CList.add(C1);
         CList.add(C2);
         CList.add(C3);
         CList.add(C4);

         //封装数据进session,再实行跳转
        session.setAttribute("CList",CList);
        session.setAttribute("length",CList.size());
       return "redirect:AdminReview.jsp";   //跳转到自定义页面

    
    

以上是关于SpringMVC后台携带数据,实现局部页面跳转的主要内容,如果未能解决你的问题,请参考以下文章

springmvc ajax 页面无法重定向问题!!!!

vue页面跳转

Android系统路由之-scheme实现网页链接携带参数跳转到Activity

微型小程序页面跳转加携带数据

js跳转vue

ajax怎样从后台获取数据进行局部刷新