SSM个人博客搭建(一)

SSM个人博客搭建

使用Maven来建立

Maven给我感觉就是能够通过依赖自己导入jar,项目搭建更加方便.

SSM个人博客搭建(一)_第1张图片

SSM个人博客搭建(一)_第2张图片

注意要pom方式打包(其实它神秘也不会做),这种打包方式用于父模块.

会生成如下的样式:


更改它的pom.xml文件,这个文件添加整个项目的依赖:

  4.0.0

  com.ysfBlog

  ysf-parent

  0.0.1-SNAPSHOT

  pom

 

       

                 4.12

                   4.1.3.RELEASE

                   3.2.8

                   1.2.2

                   1.2.15

                   5.1.32

                   1.6.4

                   2.4.2

                   1.0.9

                   1.2

                   2.5

                   2.0

                   3.3.2

                   1.3.2

                   3.3

                   0.9.1

                   1.3.1

       

       

       

       

       

                           

                                     org.apache.commons

                                     commons-lang3

                                     ${commons-lang3.version}

                           

                           

                                     org.apache.commons

                                     commons-io

                                     ${commons-io.version}

                           

                           

                                     commons-net

                                     commons-net

                                     ${commons-net.version}

                           

                           

                           

                                     com.fasterxml.jackson.core

                                     jackson-databind

                                     ${jackson.version}

                           

                           

                           

                                     org.apache.httpcomponents

                                     httpclient

                                     ${httpclient.version}

                           

                           

                           

                                     junit

                                     junit

                                     ${junit.version}

                                     test

                           

                           

                           

                                     org.slf4j

                                     slf4j-log4j12

                                     ${slf4j.version}

                           

                           

                           

                                     org.mybatis

                                     mybatis

                                     ${mybatis.version}

                           

                           

                                     org.mybatis

                                     mybatis-spring

                                     ${mybatis.spring.version}

                           

                           

                                     com.github.miemiedev

                                     mybatis-paginator

                                     ${mybatis.paginator.version}

                           

                           

                                     com.github.pagehelper

                                     pagehelper

                                     ${pagehelper.version}

                           

                           

                           

                                     mysql

                                     mysql-connector-java

                                     ${mysql.version}

                           

                           

                           

                                     com.alibaba

                                     druid

                                     ${druid.version}

                           

                           

                           

                                     org.springframework

                                     spring-context

                                     ${spring.version}

                           

                           

                                     org.springframework

                                     spring-beans

                                     ${spring.version}

                           

                           

                                     org.springframework

                                     spring-webmvc

                                     ${spring.version}

                           

                           

                                     org.springframework

                                     spring-jdbc

                                     ${spring.version}

                           

                           

                                     org.springframework

                                     spring-aspects

                                     ${spring.version}

                           

                           

                                     org.springframework

                                     spring-context-support

                                     ${spring.version}

                           

                           

                           

                                     jstl

                                     jstl

                                     ${jstl.version}

                           

                           

                                     javax.servlet

                                     servlet-api

                                     ${servlet-api.version}

                                     provided

                           

                           

                                     javax.servlet

                                     jsp-api

                                     ${jsp-api.version}

                                     provided

                           

                           

                           

                                     commons-fileupload

                                     commons-fileupload

                                     ${commons-fileupload.version}

                           

                           

                                     org.freemarker

                                     freemarker

                                     ${freemarker.version}

                           

                           

                                     org.quartz-scheduler

                                     quartz

                                     ${quartz.version}

                           

                  

        

创建ysf-common

创建另一个模块ysf-common,打包方式jar:

建立好就是下图这样:

SSM个人博客搭建(一)_第3张图片

接下来我们来修改pom.xml文件

  4.0.0

 

    com.ysfBlog

    ysf-parent

    0.0.1-SNAPSHOT

 

  com.ysfBlog

  ysf-common

  0.0.1-SNAPSHOT

 

 

   

      log4j

      log4j

      1.2.17

   

   

      org.slf4j

      slf4j-api

      1.7.21

   

   

     

      commons-logging

      commons-logging

      1.2

   

   

   

      junit

      junit

      4.12

      test

   

 

添加完依赖之后的项目是这样的,你可以看到多了一个maven Dependencies,这说明我们需要的jar依赖都已经添加进来了.

SSM个人博客搭建(一)_第4张图片

SSM个人博客搭建(一)_第5张图片

聚合模块ysf-manager

接下来我们创建一个聚合模块,ysf-manager

打包方式pm

创建完成如下:


在pom.xml文件先添加依赖:

  4.0.0

 

    com.ysfBlog

    ysf-parent

    0.0.1-SNAPSHOT

 

  com.ysfBlog

  ysf-manager

  0.0.1-SNAPSHOT

  pom

 

 

        com.ysfBlog

        ysf-common

        0.0.1-SNAPSHOT

 

 

在聚合模块创建子模块ysf-manager-pojo

SSM个人博客搭建(一)_第6张图片

SSM个人博客搭建(一)_第7张图片

不需要修改pojo中的pom.xml文件,注意观察ysf-manager的pom.xml文件’

会自动生成一个标签,这就是maven的作用之一了,是不是很方便.会自动生成模块

SSM个人博客搭建(一)_第8张图片

创建子模块ysf-manager-dao

也是同样的方法

其pom.xml文件如下

  4.0.0

 

    com.ysfBlog

    ysf-manager

    0.0.1-SNAPSHOT

 

  ysf-common-dao

 

        

                  

                            com.taotao

                            taotao-manager-pojo

                            0.0.1-SNAPSHOT

                  

                  

                  

                            org.mybatis

                            mybatis

                  

                  

                            org.mybatis

                            mybatis-spring

                  

                  

                            com.github.miemiedev

                            mybatis-paginator

                  

                  

                  

                  

                            mysql

                            mysql-connector-java

                  

                  

                  

                            com.alibaba

                            druid

                  

        


创建子模块ysf-manager-service

方法一样

Pom.xml文件如下:

  4.0.0

 

    com.ysfBlog

    ysf-manager

    0.0.1-SNAPSHOT

 

  ysf-manager-service

 

                  

                            com.taotao

                            taotao-manager-dao

                            0.0.1-SNAPSHOT

                  

                  

                            org.springframework

                            spring-context

                  

                  

                            org.springframework

                            spring-beans

                  

                  

                            org.springframework

                            spring-webmvc

                  

                  

                            org.springframework

                            spring-jdbc

                  

                  

                            org.springframework

                            spring-aspects

                  

                  

                            org.springframework

                            spring-context-support

                  

        

 

 

创建子模块ysf-manager-web

SSM个人博客搭建(一)_第9张图片

这里要注意,打包方式是war

  pom.xml代码如下:

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

         4.0.0

 

    com.ysfBlog

    ysf-manager

    0.0.1-SNAPSHOT

 

  ysf-manager-web

  war

 

 

       3.1

 

 

                  

                            com.taotao

                            taotao-manager-service

                            0.0.1-SNAPSHOT

                  

                  

                  

                            jstl

                            jstl

                  

                  

                            javax.servlet

                            servlet-api

                            provided

                  

                  

                            javax.servlet

                            jsp-api

                            provided

                  

                  

                  

                            commons-fileupload

                            commons-fileupload

                  

        

这样我们项目初步就创建好了,接下来我们开始整合ssm框架.

SSM个人博客搭建(一)_第10张图片

首先我们整合dao层

applicationContext-dao.xml

         xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"

         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

 

        

        

        

        

        

                   destroy-method="close">

                  

                  

                  

                  

                  

                  

        

        

        

                  

                  

                  

                  

        

        

                  

        

自己配置连接池属性db.properties

配置service层

applicationContext-service.xml代码

         xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"

         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

 

        

        

 

 

applicationContext-trans.xml

         xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"

         xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

        

        

                   class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

                  

                  

        

        

        

                  

                           

                           

                           

                           

                           

                           

                           

                           

                           

                           

                  

        

        

        

                  

                            pointcut="execution(* com.ysfBlog.service.*.*(..))" />

        

配置表现层

springMVC.xml

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"

         xmlns:context="http://www.springframework.org/schema/context"

         xmlns:mvc="http://www.springframework.org/schema/mvc"

         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

   

       

   

   

   

   

   

                   class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                  

                  

        

        

 

  

 

Web.xml

xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         id="taotao" version="2.5">

         ysf-manager

        

                   index.html

                   index.htm

                   index.jsp

                   default.html

                   default.htm

                   default.jsp

        

        

        

                   contextConfigLocation

                   classpath:spring/applicationContext-*.xml

        

        

                   org.springframework.web.context.ContextLoaderListener

        

 

        

        

                   CharacterEncodingFilter

                   org.springframework.web.filter.CharacterEncodingFilter

                  

                            encoding

                            utf-8

                  

        

        

                   CharacterEncodingFilter

                   /*

        

 

 

        

        

                   ysf-manager

                   org.springframework.web.servlet.DispatcherServlet

                  

                  

                            contextConfigLocation

                            classpath:spring/springmvc.xml

                  

                   1

        

        

                   ysf-manager

                   /

        

        


 到这里我们的maven项目就搭建完成了,ssm配置也已经写好了,可以开始写自己的代码了.

你可能感兴趣的:(项目)