Guest User

Untitled

a guest
Jun 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.66 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package mvc.controller;
  6. import java.io.BufferedWriter;
  7. import java.io.IOException;
  8. import java.io.OutputStreamWriter;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import mvc.model.Users;
  16. import mvc.service.UserService;
  17. import net.sf.json.JSON;
  18. import net.sf.json.JSONSerializer;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Controller;
  21. import org.springframework.validation.BindException;
  22. import org.springframework.web.bind.annotation.PathVariable;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. import org.springframework.web.bind.annotation.ResponseBody;
  26. import org.springframework.web.servlet.ModelAndView;
  27. import org.springframework.web.servlet.mvc.SimpleFormController;
  28.  
  29.  
  30. /**
  31.  *
  32.  * @author vipin
  33.  */
  34. @Controller
  35.  
  36. public class HomeController  {
  37.  
  38.     @Autowired
  39.     private UserService userService;
  40.  
  41.     public void setUserService(UserService userService) {
  42.         this.userService = userService;
  43.     }
  44.  
  45.     public HomeController() {
  46.        
  47.     }
  48.    
  49.    
  50.    
  51. //    @RequestMapping(value = "/MyData", method = RequestMethod.GET,headers = "Accept=application/json")
  52. //    public @ResponseBody List getData() {        
  53. //        return userService.getAll();
  54. //    }
  55.    
  56. //    protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception {
  57. //        Map model = new HashMap();
  58. //                List l1= userService.getAll();
  59. //      JSON js = JSONSerializer.toJSON(l1);
  60. //                System.out.println(" json----------"+js.toString() );
  61. //        return new ModelAndView("home");
  62. //    }
  63.    
  64.     @RequestMapping("/home")
  65.     public ModelAndView v() {
  66.         System.out.println("i am in showForm");
  67.         return new ModelAndView("home");
  68.     }
  69.    
  70.     @RequestMapping("/h")
  71.     public JSON myMethod(){
  72. //        Map<String, Object> result = new HashMap();
  73. //        result.put("identifier", "userId");
  74. //        result.put("label", "userName");
  75. //        List<Map<String, Object>> items = userService.getAll();
  76. //        result.put("items", items);        
  77. //        JSON js = JSONSerializer.toJSON(result);
  78.        
  79.        List l1= userService.getAll();
  80.        JSON u= JSONSerializer.toJSON(l1);
  81.       System.out.println(" json----------"+u );
  82.         return u;        
  83.     }
  84.  
  85. }
Add Comment
Please, Sign In to add comment