Maven父子工程配置文件详解

项目骨架搭建成功之后。

因为父工程管理子工程。子工程相当于继承于子工程,所以子工程可以调用父工程里面的东西。那么就可以将jar包对应的配置文件书写到父工程的pom.xml文件中,注意:父工程的打包方式为pom。代码如下:(如果另有需要可以自己添加所需jar包)。




    4.0.0

    com.hd
    online_retailers
    pom
    1.0-SNAPSHOT

    
        online_pojo
        online_web
        online_dao
        online_service
    

    
        5.0.2.RELEASE
        1.8
        1.8
    

    
        
            junit
            junit
            4.12
            test
        

        
        
        
            javax.servlet
            javax.servlet-api
            3.1.0
            provided
        


        
        
            mysql
            mysql-connector-java
            5.1.38
        

        



        
        
            org.mybatis
            mybatis
            3.2.5
        
        

        
        
            log4j
            log4j
            1.2.17
        
        

        
        
            org.springframework
            spring-core
            ${spring.version}
        

        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-oxm
            ${spring.version}
        
        
            org.springframework
            spring-tx
            ${spring.version}
        


        
            org.springframework
            spring-jdbc
            ${spring.version}
        

        
            org.springframework
            spring-webmvc
            ${spring.version}
        
        
            org.springframework
            spring-aop
            ${spring.version}
        

        
            org.springframework
            spring-context-support
            ${spring.version}
        

        
            org.springframework
            spring-test
            ${spring.version}
        

        
            org.aspectj
            aspectjweaver
            1.6.12
        

        
        

        
            com.fasterxml.jackson.core
            jackson-core
            2.9.4
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.9.4
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.9.4
        
        
        
            com.mchange
            c3p0
            0.9.2.1
        
        

        
        
            org.mybatis
            mybatis-spring
            1.3.0
        

        
        
            jstl
            jstl
            1.2
        

    

SSM框架的项目结构一般分为pojo、web、service、dao,所以建立父子工程项目结构以及配置文件放置位置如下图:

Web

Maven父子工程配置文件详解_第1张图片

pom.xml





    

        online_retailers

        com.hd

        1.0-SNAPSHOT

    

    4.0.0

    war

    online_web

    

    

        

            com.hd

            online_service

            1.0-SNAPSHOT

        



        

            com.hd

            online_pojo

            1.0-SNAPSHOT

        

    

applicationContext.xml




    
    

log4j.properties

# Global logging configuration
#在开发环境下日志级别设置为debug,生产环境下设置成info或error
#log4j.rootLogger=DEBUG, stdout
# Console output...
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=INFO
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c,%L] - %m%n

SpringMvc.xml



    
    

    
    
        
            
            
        
    

Service层:

Maven父子工程配置文件详解_第2张图片

Pom.xml



    
        online_retailers
        com.hd
        1.0-SNAPSHOT
    
    4.0.0
    jar
    online_service
    
    
        
            com.hd
            online_dao
            1.0-SNAPSHOT
        

        
            com.hd
            online_pojo
            1.0-SNAPSHOT
        

    

applicationContext_service.xml




    

    
    
        
    
    
    
        
            
            
            
            
            
            
            
            
        
    
    
    
        
        
    

Pojo

Maven父子工程配置文件详解_第3张图片

Pom.xml



    
        online_retailers
        com.hd
        1.0-SNAPSHOT
    
    4.0.0
    jar
    online_pojo



 

Dao

Maven父子工程配置文件详解_第4张图片

Pom.xml





    

        online_retailers

        com.hd

        1.0-SNAPSHOT

    

    4.0.0

    jar

    online_dao

    

    

        

            com.hd

            online_pojo

            1.0-SNAPSHOT

        

    

applicationContext_dao.xml





    

    



    

        

        

        

        

    



    

        

        

        

    



    



    

    

        

    



    

    


db.properties

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url = jdbc:mysql://localhost:3306/easybuy?useUnicode=true&characterEncoding=utf-8

jdbc.username=root

jdbc.password=123

SqlMapperConfig.xml









    

    

        

        

    



    

        

    

NewMapper.xml







  

    

    

    

    

  

  

    id, title, content, createTime

  

  

  

    delete from easybuy_news

    where id = #{id,jdbcType=INTEGER}

  

  

    insert into easybuy_news (id, title, content,

      createTime)

    values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR},

      #{createtime,jdbcType=VARCHAR})

  

  

    insert into easybuy_news

    

      

        id,

      

      

        title,

      

      

        content,

      

      

        createTime,

      

    

    

      

        #{id,jdbcType=INTEGER},

      

      

        #{title,jdbcType=VARCHAR},

      

      

        #{content,jdbcType=VARCHAR},

      

      

        #{createtime,jdbcType=VARCHAR},

      

    

  

  

    update easybuy_news

    

      

        title = #{title,jdbcType=VARCHAR},

      

      

        content = #{content,jdbcType=VARCHAR},

      

      

        createTime = #{createtime,jdbcType=VARCHAR},

      

    

    where id = #{id,jdbcType=INTEGER}

  

  

    update easybuy_news

    set title = #{title,jdbcType=VARCHAR},

      content = #{content,jdbcType=VARCHAR},

      createTime = #{createtime,jdbcType=VARCHAR}

    where id = #{id,jdbcType=INTEGER}

  



 

你可能感兴趣的:(Maven,Maven,父子工程,配置)