(1)首先要引入需要pom文件

  <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-json-plugin -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.16.3</version>
</dependency>

(2)需要的数据,返回什么类型的都可以

    private List<Integer> list;  //要返回前台的值  list集合
private Integer productId; //前台获取的值 public Object totalQuantity() {
System.out.println(productId);
list = productService.findByID(productId);
System.out.println(list);
return "ajax";
} //省略getter和setter方法

(3)配置action

result节点中的name:返回的值  type:返回序列化的格式

root:要序列化的对象  默认将序列化当前Action中所有有返回值的getter方法的值

===list( 要返回页面的数据 在action要有getter方法)

 <action name="totalQuantity" class="cn.ssh.action.ProductAction" method="totalQuantity">
<result name="ajax" type="json" >
<param name="root">list</param>
</result>
</action>

(4)前台ajax

  $.ajax({
url:"/totalQuantity.action", //访问action的路径
type:"POST",
data:{
//传递到后台的值
},
dataType:"JSON",
success:function (data) {
//成功操作
$.each(data, function (i, dom) { });
} })

最新文章

  1. POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心
  2. ubuntu一些常用的命令
  3. grep(Global Regular Expression Print)
  4. .NET 分页
  5. 记录一下,关于错误提示:could not find a part of path “X:\”的解决办法
  6. Spring factorybean
  7. spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
  8. 转:【Java并发编程】之一:可重入内置锁
  9. ABP官方文档翻译 4.4 授权
  10. 在Coding上搭建Hexo个人博客
  11. CSS3常用
  12. python 读取excel文件
  13. 搭建opencv javaweb项目
  14. arcgis 获得工具箱工具的个数
  15. python练习题-day9
  16. MySQL数据库的库表基本操作
  17. 玩转 React 【第03期】:邂逅 React 组件
  18. Go语言编程 (许式伟 等 著)
  19. matlab 画图参考小程序
  20. 复选框、单选框 jquery判断是否选中Demo

热门文章

  1. tar打包
  2. G面经Prepare: Print Zigzag Matrix
  3. vue生命周期钩子函数
  4. Raize 重新编译
  5. JavaScript字符串字节长度
  6. 关于config文件中AppSettings和ConnectionStrings的用法跟区别(转)
  7. 使用第三方jar时出现的问题
  8. axios请求
  9. Git 爬坑路(从小白开始入门) ——(1)
  10. 词云(wordcloud2.js js2wordcloud.js)