spring json
生活随笔
收集整理的這篇文章主要介紹了
spring json
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
控制器返回json代碼:
?
package com.trol;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;import com.entity.User;@Controller public class UserController {@RequestMapping("/listJson")@ResponseBodypublic User list(){User user = new User();user.setPwd("bbb");return user;}@RequestMapping("/{id}/delete")public String delete(@PathVariable int id){System.out.println("delete--"+id);return "index";}}實體類:
?
?
package com.entity; import java.io.Serializable;public class User implements Serializable {//私有字段;private String username;private String pwd;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}}?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的spring json的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring上传
- 下一篇: spring转发和重定向