SSM 框架集成环境搭建方式

FU
如需要跟多资料请点击下方图片⬇(扫码加好友→备注66,不备注拒绝添加哦)
SSM 框架集成环境搭建方式_第1张图片

  • jar 包依赖添加
  • web.xml 文件配置
  • Springmvc 配置文件 servlet-context.xml 添加
  • Spring.xml 配置

案例实操

1.jar 包依赖添加(原有基础上继续添加 springmvc 相关依赖 jar 包及对应 jetty 插件) 修改 pom.xml 文件

 

    4.0.0 

    com.xxx 

    spring_mybatis 

    war 

    0.0.1-SNAPSHOT 

    spring_mybatis Maven Webapp 

    http://maven.apache.org 

     

         

         

            junit 

            junit 

            4.12 

            test 

         

         

         

            org.springframework 

            spring-context 

            4.3.2.RELEASE 

         

         

         

            org.springframework 

            spring-test 

            4.3.2.RELEASE 

         

         

        

            org.springframework 

            spring-jdbc 

            4.3.2.RELEASE 

         

         

         

            org.springframework 

            spring-tx 

            4.3.2.RELEASE 

         

         

         

            org.aspectj 

            aspectjweaver 

            1.8.9 

         

         

         

            c3p0 

            c3p0 

            0.9.1.2 

         

         

         

            org.mybatis 

            mybatis 

            3.4.1 

         

     

         

            org.mybatis 

            mybatis-spring 

            1.3.0 

         

         

         

            mysql 

            mysql-connector-java 

            5.1.39 

         

         

         

            org.slf4j 

            slf4j-log4j12 

            1.7.2 

         

         

            org.slf4j 

            slf4j-api 

            1.7.2 

         

         

         

            com.github.pagehelper 

            pagehelper 

            4.1.0 

         

         

         

            org.springframework 

            spring-web 

            4.3.2.RELEASE 

         

         

         

            org.springframework 

            spring-webmvc 

            4.3.2.RELEASE 

         

         

         

            javax.servlet 

            javax.servlet-api 

            3.0.1 

         

         

         

            com.fasterxml.jackson.core 

            jackson-core 

            2.7.0 

         

         

            com.fasterxml.jackson.core 

            jackson-databind 

            2.7.0 

         

         

            com.fasterxml.jackson.core 

            jackson-annotations 

            2.7.0 

         

         

             

            commons-fileupload 

            commons-fileupload 

            1.3.2 

         

     

     

        ssm 

         

             

                **src/main/resources** 

             

             

                **src/main/java** 

                 

                    ***\*/\*.xml** 

                    ***\*/\*.properties** 

                    ***\*/\*.tld** 

                 

                **false** 

         

     

     

             

                org.mybatis.generator 

                mybatis-generator-maven-plugin 

                1.3.2 

                 

                 src/main/resources/generatorConfig.xml 

                    true 

                    true 

                 

         

             

                org.mybatis.generator 

                mybatis-generator-core 

                1.3.2 

             

         

         

         

         

            org.apache.maven.plugins 

            maven-compiler-plugin 

            2.3.2 

             

                1.7 

                1.7 

                UTF-8 

                 

                    ${project.basedir}/lib/rt.jar 

                 

             

         

         

         

            org.mortbay.jetty 

            maven-jetty-plugin 

            6.1.21 

             

                10 

                /ssm 

             

         

     

     

 

2.web.xml 文件配置

 

 

     

        contextConfigLocation 

        classpath:spring.xml 

     

     

    org.springframework.web.context.ContextLoaderListener 

     

     

        char encoding filter 

    encodingFilter 

    org.springframework.web.filter.CharacterEncodingFilter 

         

        encoding 

        UTF-8 

         

     

     

        encodingFilter 

        /* 

     

     

    springMvc 

    org.springframework.web.servlet.DispatcherServlet 

         

            contextConfigLocation 

            classpath:servlet-context.xml 

         

        1 

     

     

        springMvc 

        *.do 

     

 

3.Springmvc 配置文件 servlet-context.xml 添加

 

 

     

     

     

     

     

     

         

         

         

         

     

     

     

     

     

         

     

         

     

     

     

     

     

         

        104857600 

         

         

        4096 

         

     

 

4.Spring.xml 配置

 

 

     

     

      

     

     

     

     

     

     

         

         

         

         

     

     

     

         

     

     

     

         

             

             

             

             

             

             

             

             

         

     

     

     

     

          

     

     

     

         

         

         

     

     

     

     

         

         

     

 

扩展

Helloworld 编写

搭建好SSM集成框架,Hellocontroller 的编写就变得非常简单

@Controller 

public class HelloController { 

    /** 

    * 注入 service 层 userService 接口 

    */ 

    @Autowired 

    private UserService userService; 

    @RequestMapping("/hello") 

    public ModelAndView hello(){ 

        ModelAndView mv=new ModelAndView(); 

        /** 

        * 调用 service 层查询方法 

        */ 

        User user=userService.queryUserById(7); 

        System.out.println(user); 

        mv.addObject("user", user); 

        mv.setViewName("hello"); 

        return mv; 

    } 

} 

视图页面部分代码接收结果显示:

 

    欢迎你,${user.userName} 

 

启动 jetty 服务器,访问地址: http://localhost:8080/ssm/hello.do