In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Xiaobian to share with you how to use Springmvc to complete the Ajax function, I hope you have some gains after reading this article, let's discuss it together!
1. Add Jackson's jar package
2. Add @ResponseBody to the response method: convert java objects to json objects
3. The return value of the method can be an object collection string
$.post("ajax/Ajax1",{"name":"zhu"},function(data){ $.each(data,function(i,n){ alert(n.name); }) })
Can return strings
@RequestMapping(value="Ajax1", products = "text/html;charset=UTF-8") @ResponseBody public String ajax1(String name) { System.out.println(name); return "hello"; }
You can also return objects.
@RequestMapping("Ajax2") @ResponseBody public User ajax2(String name) { User user=new User("中","1"); return user; }
You can also return collections
@RequestMapping("Ajax3") @ResponseBody public List ajax3(String name) { User user1 =new User("中","1"); User user2 =new User("","2"); User user3 =new User("","3"); List list=new ArrayList(); list.add(user1); list.add(user2); list.add(user3); return list; }
When returning a character string, if the input Chinese characters will appear garbled, the solution is as follows
1. Change @RequestMapping
@RequestMapping(value="Ajax1",produces="text/html;charset=UTF-8")
2. Rewrite the code in the springMVC configuration file with the org.springframework.web.servlet.view.InternalResourceViewResolver class.
After reading this article, I believe you have a certain understanding of "how to use Springmvc to complete the Ajax function". If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.