Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package mvc.controller;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import mvc.model.Users;
- import mvc.service.UserService;
- import net.sf.json.JSON;
- import net.sf.json.JSONSerializer;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.validation.BindException;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
- import org.springframework.web.servlet.mvc.SimpleFormController;
- /**
- *
- * @author vipin
- */
- @Controller
- public class HomeController {
- @Autowired
- private UserService userService;
- public void setUserService(UserService userService) {
- this.userService = userService;
- }
- public HomeController() {
- }
- // @RequestMapping(value = "/MyData", method = RequestMethod.GET,headers = "Accept=application/json")
- // public @ResponseBody List getData() {
- // return userService.getAll();
- // }
- // protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception {
- // Map model = new HashMap();
- // List l1= userService.getAll();
- // JSON js = JSONSerializer.toJSON(l1);
- // System.out.println(" json----------"+js.toString() );
- // return new ModelAndView("home");
- // }
- @RequestMapping("/home")
- public ModelAndView v() {
- System.out.println("i am in showForm");
- return new ModelAndView("home");
- }
- @RequestMapping("/h")
- public JSON myMethod(){
- // Map<String, Object> result = new HashMap();
- // result.put("identifier", "userId");
- // result.put("label", "userName");
- // List<Map<String, Object>> items = userService.getAll();
- // result.put("items", items);
- // JSON js = JSONSerializer.toJSON(result);
- List l1= userService.getAll();
- JSON u= JSONSerializer.toJSON(l1);
- System.out.println(" json----------"+u );
- return u;
- }
- }
Add Comment
Please, Sign In to add comment