SSM 框架 Maven项目 项目整合 SpringMVC

项目结构

 SSM 框架 Maven项目 项目整合 SpringMVC_第1张图片

web.xml



  Archetype Created Web Application
  
    
    
        encodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        true
        
            encoding
            UTF-8
        
    
    
        encodingFilter
        /*
    
  
    
    
        contextConfigLocation
        classpath:spring-mybatis.xml
    

    
        org.springframework.web.context.ContextLoaderListener
    
    
    
    
    
        springDispatcherServlet
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc.xml
        
        1
    

    
        springDispatcherServlet
        /
    
    


springmvc.xml




      
      

      
    

    
    

      
      
          
          
         
UserController.java

package com.zyh.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zyh.entity.Userinfo;
import com.zyh.service.UserService;

@Controller
public class UserController {

	private static Logger logger = Logger.getLogger(UserController.class);
	
	@Autowired
	UserService userService;
	
	 @RequestMapping("/showUser")
	 public String testtoshowUser(@RequestParam(value = "id") String id, Model model) {
		 logger.info("测试类");
		 Userinfo userinfo = userService.getUserById(id);
		 model.addAttribute("user", userinfo);
	     return "show";
	 }
}

index.jsp



Hello World!

ShowUser page
show.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here



	
	id:${user.id} 
userName: ${user.name}
password: ${user.password}
phone: ${user.phone}
添加Tomcat 运行即可。

效果

SSM 框架 Maven项目 项目整合 SpringMVC_第2张图片
SSM 框架 Maven项目 项目整合 SpringMVC_第3张图片

项目下载地址 :http://download.csdn.net/download/z_demon801/10217874

你可能感兴趣的:(web前端,Spring,MVC,Maven,Mybitas)