ssm傻瓜式教程

1. 关于web.xml的配置


* xml头配置
  	* 

*内容`

  test
    
        index.html
        index.htm
        index.jsp
        default.html
        default.htm
        default.jsp
    

    
    
        encoding
        org.springframework.web.filter.CharacterEncodingFilter
        
        
            encoding
            UTF-8
        
    
    
        encoding
        /*
    

    
    
        contextConfigLocation
        /WEB-INF/config/springcontext.xml
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
        
        
            contextConfigLocation
            /WEB-INF/config/springmvc.xml
        
        1
    
    
        springmvc
        /
    

2.关于springmvc的配置

*springmvc头配置



*配置内容

  
    
    
    


    
    
    
    
    

    
    
        
        
        
        

    

3.关于springcontext 的配置


*头部



*主体

 
    

    
    
        
        
        
        
        
        
    

    
    
        
        
        
        
    

    
    
        
        
    

    
    
        
    

    
    



4.关于sqlMapConfig的配置

所有**







5.一:前端控制器 Controller的配置

@Controller
    @RequestMapping("/energy")
    public class IndexController {

        @RequestMapping(value = "/index")
        public ModelAndView index(HttpServletRequest request,
                                  HttpServletResponse response, ModelMap model) {
            ModelAndView mv = new ModelAndView();
            mv.setViewName("Index");
            return mv;
        }

    @RequestMapping(value = "/toLogin")
    public ModelAndView toLogin(HttpServletRequest request,
                                HttpServletResponse response, ModelMap model) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("Login");
        return mv;
    }

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public void login(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        User user = userService.getUserByUsername(username);
        String result = "";
        if (user != null && password.equals(user.getPassword())) {
            req.getSession().setAttribute("user", user);
            result = new Gson().toJson("true");
        } else {
            result = new Gson().toJson("false");
        }
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        String jsonp = req.getParameter("jsoncallback");
        if (jsonp != null) {
            result = jsonp + "(" + result + ")";
        }
        resp.getWriter().write(result);

    }
    @RequestMapping(value = "/toRegister")
    public ModelAndView toRegister(HttpServletRequest request,
                                   HttpServletResponse response, ModelMap model) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("Register");
        return mv;
    }
    @RequestMapping("/saveUser")
    public void saveUser(HttpServletRequest req, HttpServletResponse resp)
            throws IOException, ServletException, ParseException {
        String username = req.getParameter("username");
        User u = userService.getUserByUsername(username);
        String result = null;
        if (u != null) {
            result = new Gson().toJson("false");
        } else {
            String password = req.getParameter("password");
            String nickname = req.getParameter("nickname");
            int sex = Integer.parseInt(req.getParameter("val"));
            int usertype = Integer.parseInt(req.getParameter("item"));
            String bdate = req.getParameter("birthdate");
            String dlt = req.getParameter("dltime");
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date birthdate = null;
            Date dltime = null;
            try {
                birthdate = format.parse(bdate);
                dltime = format.parse(dlt);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            User user = new User();
            String id = UUID.randomUUID().toString();
            user.setId(id);
            user.setUsername(username);
            user.setPassword(password);
            user.setCreatetime(new Date());
            user.setNickname(nickname);
            user.setBirthdate(birthdate);
            user.setSex(sex);
            user.setDltime(dltime);
            user.setUsertype(usertype);
            userService.saveUser(user);
            result = new Gson().toJson(user);
        }
        String jsonp = req.getParameter("jsoncallback");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        if (jsonp != null) {
            result = jsonp + "(" + result + ")";
            resp.getWriter().write(result);
        } else {
            resp.getWriter().write(result);
        }
    }


6.关于UserMapper。xml的配置




    
        
        
        
        
        
        
        
        
        
        
    

    



你可能感兴趣的:(概念偷换)