SSM(1)ajax的入门使用
2017-12-01 21:05
225 查看
**# 注册板块的信息获取 #
## 前端jqery发送ajax获取json信息 ##**
1.于com.bean建立Message.java 存放ajax页面的信息
设置code状态码 表示ajax请求成功失败 (通过success和fail存放
设置message 设置信息 (不重要
设置infor的Map 存放ajax的请求信息 (最重要
function介绍 (返回类型都是Message 可以连续请求
success 和fail表明返回的是成功还是失败类型的信息 (static类型
add存放请求和返回信息
`
}
`
2.配置servlet层和controller层
1.servlet层
查询所有人的信息
(example是空 可以直接selectByExample(null)
2.controller层
1. 注解@ResponseBody返回的页面不是html是json
2. 注解@RequestParam(value = “pageNumber”, defaultValue = “1”)请求的页面参数,默认为1 (map没用
3. PageHelper.startPage(pageNumber, 5); //开始的页数和每页数据的个数
4. infors = inforServlet.getInfors(); 获取信息
5. PageInfo page = new PageInfo(infors, 6); 将分页信息传入到Message的map中 并将Message作为ajax信息返回
6. 3,4,5具有顺序性
配置jsp页面
url:
## 前端jqery发送ajax获取json信息 ##**
1.于com.bean建立Message.java 存放ajax页面的信息
设置code状态码 表示ajax请求成功失败 (通过success和fail存放
设置message 设置信息 (不重要
设置infor的Map 存放ajax的请求信息 (最重要
function介绍 (返回类型都是Message 可以连续请求
success 和fail表明返回的是成功还是失败类型的信息 (static类型
add存放请求和返回信息
`
public class JsonMessage { //成功为200 private int code; private String message; private Map<String, Object> map=new HashMap<String, Object>(); //成功 public static JsonMessage success() { JsonMessage jsonMessage=new JsonMessage(); jsonMessage.setCode(200); jsonMessage.setMessage("处理成功"); return jsonMessage; } //失败 public static JsonMessage fail() { JsonMessage jsonMessage=new JsonMessage(); jsonMessage.setCode(500); jsonMessage.setMessage("处理失败"); return jsonMessage; } public JsonMessage add(String key,Object value) { this.getMap().put(key, value); return this; } …… public ……………… get&&put(){ …… }
}
`
2.配置servlet层和controller层
1.servlet层
查询所有人的信息
(example是空 可以直接selectByExample(null)
public List<Infor> getInfors() { List<Infor> infors=null; InforExample inforExample =new InforExample(); Criteria criteria=inforExample.createCriteria(); infors=inforMapper.selectByExample(inforExample); return infors; }
2.controller层
1. 注解@ResponseBody返回的页面不是html是json
2. 注解@RequestParam(value = “pageNumber”, defaultValue = “1”)请求的页面参数,默认为1 (map没用
3. PageHelper.startPage(pageNumber, 5); //开始的页数和每页数据的个数
4. infors = inforServlet.getInfors(); 获取信息
5. PageInfo page = new PageInfo(infors, 6); 将分页信息传入到Message的map中 并将Message作为ajax信息返回
6. 3,4,5具有顺序性
@RequestMapping(value = "/getInforsByJson", method = RequestMethod.GET) @ResponseBody public JsonMessage getInforsByJson(@RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber, Map<String, Object> map) { // 开始的页面和 一夜显示的信息数量 PageHelper.startPage(pageNumber, 5); System.out.println("传递的页面:" + pageNumber); // 获取查询的信息 List<Infor> infors; infors = inforServlet.getInfors(); // 将查询的内容用pageinfo包装,连续显示6页 PageInfo page = new PageInfo(infors, 6); // 分装进model中 return JsonMessage.success().add("pageInfo", page); } @RequestMapping(value = "/getJsonInfor") public String getJsonInfor() { return "getJsonInfor"; }
配置jsp页面
url:
相关文章推荐
- SSM(2)ajax的入门使用
- SSM项目从零开始到入门007-使用接口完成增删改查操作
- SSM框架下使用JSON和AJAX进行前后端数据传输
- ASP.NET AJAX入门系列:使用UpdatePanel控件
- ajax入门 ajax使用方式2-ajax基础
- ssm使用ajax返回总是error错误返回的是object
- ajax使用技巧之初入门
- ASP.NET AJAX入门系列:使用ScriptManagerProxy控件
- ASP.NET MVC 入门11、使用AJAX
- SSM框架——SpringMVC中使用@ResponseBody注解返回值,Ajax取得中文乱码解决方法
- ASP.NET AJAX入门系列:使用ScriptManagerProxy控件
- SSM框架下使用JSON和AJAX进行前后端数据传输
- ASP.NET MVC 入门 -- 11、使用AJAX
- [转]ASP.NET MVC 入门11、使用AJAX
- ajax helloworld jsp ajax入门,后台使用jsp
- ASP.NET MVC 入门11、使用AJAX
- AJAX 入门和使用
- 使用jQuery简化Ajax开发——Ajax开发入门(转载)
- 使用jQuery简化Ajax开发—Ajax开发入门[1]
- SSM框架下使用JSON和AJAX进行前后端数据传输