springMvc-对servletApi的支持以及把后台对象以json方式传到前台
1.对servletApi的支持:request、response以及session、cookie的支持
2.把后台代码以json格式向前台输出:
代码:
package com.java.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.java.model.Student;
@Controller
@RequestMapping("/student")
public class StudentController {
private static List<Student> studentList=new ArrayList<Student>();
static{
studentList.add(new Student(1,"张三",11));
studentList.add(new Student(2,"李四",12));
studentList.add(new Student(3,"王五",13));
}
@RequestMapping("/list")
public ModelAndView list(){
ModelAndView mav=new ModelAndView();
mav.addObject("studentList", studentList);
mav.setViewName("student/list");
return mav;
}
@RequestMapping("/preSave")
public ModelAndView preSave(@RequestParam(value="id",required=false) String id){
ModelAndView mav=new ModelAndView();
if(id!=null){
mav.addObject("student", studentList.get(Integer.parseInt(id)-1));
mav.setViewName("student/update");
}else{
mav.setViewName("student/add");
}
return mav;
}
@RequestMapping("/save")
public String save(Student student){
if(student.getId()!=0){
Student s=studentList.get(student.getId()-1);
s.setName(student.getName());
s.setAge(student.getAge());
}else{
studentList.add(student);
}
// return "redirect:/student/list.do";
return "forward:/student/list.do";
}
@RequestMapping("/delete")
public String delete(@RequestParam("id") int id){
studentList.remove(id-1);
return "redirect:/student/list.do";
}
}
springMvc-对servletApi的支持以及把后台对象以json方式传到前台的更多相关文章
- 后台对象转JSON字符串传到前台,前台JSON字符串转对象绑定标签赋值
/// <summary> /// 创建换货单-自动获取对应的数据(后端) /// </summary> [HttpGet] public ActionResult GetPr ...
- SpringMVC对ServletAPI的支持和JSON格式的转换
package com.hongcong.controller; import java.io.UnsupportedEncodingException; import java.net.URLDec ...
- 【JSON 注解】JSON循环引用2----JSON注解@JsonIgnoreProperties+JAVA关键字transient+后台对象与JSON数据的格式互相转化
接着来说这个JSON循环引用的问题: 关于JSON格式的转化,其实关键就是这几个依赖: <!-- json --> <!-- 1号 --> <dependency> ...
- .netcore+vue+elementUI 前后端分离---支持前端、后台业务代码扩展的快速开发框架
框架采用.NetCore + Vue前后端分离,并且支持前端.后台代码业务动态扩展,框架内置了一套有着20多种属性配置的代码生成器,可灵活配置生成的代码,代码生成器界面配置完成即可生成单表(主表)的增 ...
- springmvc 支持对象与json 自动转换的配置
基于maven的工程, 需要在pom.xml中添加如下依赖 <dependency> <groupId>javax.servlet</groupId> <ar ...
- springMVC对异常处理的支持
无论做什么项目,进行异常处理都是非常有必要的,而且你不能把一些只有程序员才能看懂的错误代码抛给用户去看,所以这时候进行统一的异常处理,展现一个比较友好的错误页面就显得很有必要了.跟其他MVC框架一样, ...
- 【Spring】18、springMVC对异常处理的支持
无论做什么项目,进行异常处理都是非常有必要的,而且你不能把一些只有程序员才能看懂的错误代码抛给用户去看,所以这时候进行统一的异常处理,展现一个比较友好的错误页面就显得很有必要了.跟其他MVC框架一样, ...
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
最近angularjs post到后台 400一头雾水 没有任何错误. 最后发现好文,感谢作者 SpringMVC中出现" 400 Bad Request "错误(用@Respon ...
- 与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载)
原文:与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载) [索引页][源码下载] 与众不同 windows phone (13) ...
随机推荐
- raspberry是个什么玩意
今天Wilson同学取回一个书本大小的包裹,说买回来一台小电脑,只有信用卡大小! 这是第一次听说和看见raspberry Pi. 一块开发板上有四个USB.一个视频接口.一个音频接口.一个网线接口和电 ...
- hello markdown
目录 标题 标题1 标题2 标题3 有序列表 无序列表 插入图片 插入链接 粗体.斜体.删除线 引用 表格 代码 目录 新的开始 希望能够坚持下去 cnblogs也支持markdown 之前看了写ma ...
- 打开Visual Studio Code,rg.exe占用CPU过高
打开Visual Studio Code,再打开文件-首选项-设置 搜索“followSymlinks” 将“√”给取消掉
- 如何使用visual studio 2017创建C语言项目
使用visual studio 2017创建一个C语言项目,步骤如下: (1)打开Visual Studio 2017环境后出现欢迎界面,如图1所示. 图1 Visual Studio 2017欢迎 ...
- 第三章 Goroutine调度策略(16)
本文是<Go语言调度器源代码情景分析>系列的第16篇,也是第三章<Goroutine调度策略>的第1小节. 在调度器概述一节我们提到过,所谓的goroutine调度,是指程序代 ...
- 网格概念 Gutter
Bootstrap4也是由以上基础概念作为发展 Bootstrap 栅栏式排版 , 总栏数为12 (以下代码探寻问题, 实际上使用方法是错误的) <style> .box { heigh ...
- es6- Generator函数实现长轮询
1.Generator 函数是 ES6 提供的一种异步编程解决方案,语法行为与传统函数完全不同. 语法上,首先可以把它理解成,Generator 函数是一个状态机,封装了多个内部状态.形式上,Gene ...
- 51nod 1354【DP】
(我一定是A了一题假DP) 给定序列a[0],a[1],a[2],...,a[n-1] 和一个整数K时, 有多少子序列所有元素乘起来恰好等于K. K<=1e8; 思路: 感觉 k 的 约数是突破 ...
- C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest
We call a string as a 0689-string if this string only consists of digits '0', '6', '8' and '9'. Give ...
- D. Vitya and Strange Lesson
http://codeforces.com/contest/842/problem/D 1.整体的数组是不用变的,比如数组a[]经过一次询问x后,然后再询问y,相当于询问x ^ y ^ a[i]后的m ...