Maven 初学者 用IDEA 搭建Maven+SSM项目

  初学Maven,并且放弃了之前使用得Eclipse,利用IDEA开发。感受了一遍生无可恋得感觉,费劲两天时间总算把第一个项目成功发布了。写一点心得,希望能帮助到和我一样情况的朋友。

    首先是如何创建Maven项目

    1.FIle-New-Project-Maven

     选择你的JDK,选择webapp模板,下一步

Maven 初学者 用IDEA 搭建Maven+SSM项目_第1张图片

填写你的GroupId 和 ArtifactId     Version不用改

   


点击+号    添加一项archetypeCatalogy = internal

如果不加  在创建模板时会很慢  具体原因

https://www.cnblogs.com/hihtml5/p/6305804.html  可以参考一下这个博客

Maven 初学者 用IDEA 搭建Maven+SSM项目_第2张图片

  然后是下一步 完成  等待项目模板构建完成

    2.修改你的目录结构  

        自己生成的结构还缺少一些东西  需要自己补齐    resource(自动创建)里面写配置文件   Java(自己创建)里面写你的代码    WEB-INF下可以创建几个 css  js jsp html(自己创建)  文件夹 放你相应的页面  terget不需要管  运行一遍项目后会自己创建

Maven 初学者 用IDEA 搭建Maven+SSM项目_第3张图片

  3.配置

        接下来就是配置了  首先是  pom.xml

xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>com.liv587groupId>
    <artifactId>bbsartifactId>
    <version>1.0-SNAPSHOTversion>

    <properties>

        <junit.version>4.12junit.version>
        <spring.version>4.2.6.RELEASEspring.version>
        <mybatis.version>3.2.8mybatis.version>
        <mybatis.spring.version>1.2.2mybatis.spring.version>
        <mybatis.paginator.version>1.2.15mybatis.paginator.version>
        <mysql.version>5.1.32mysql.version>
        <slf4j.version>1.7.7slf4j.version>
        <logback.version>1.1.7logback.version>
        <jackson.version>2.4.2jackson.version>
        <druid.version>1.0.9druid.version>
        <jstl.version>1.2jstl.version>
        <servlet-api.version>2.5servlet-api.version>
        <jsp-api.version>2.0jsp-api.version>
        <commons-lang3.version>3.3.2commons-lang3.version>
        <commons-io.version>1.3.2commons-io.version>
        <commons-net.version>3.3commons-net.version>
        <commons-logging.version>1.2commons-logging.version>
        <pagehelper.version>3.4.2pagehelper.version>
        <jsqlparser.version>0.9.1jsqlparser.version>
        <commons-fileupload.version>1.3.1commons-fileupload.version>
    properties>
    <dependencies>
        
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-lang3artifactId>
            <version>${commons-lang3.version}version>
        dependency>
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-ioartifactId>
            <version>${commons-io.version}version>
        dependency>
        <dependency>
            <groupId>commons-netgroupId>
            <artifactId>commons-netartifactId>
            <version>${commons-net.version}version>
        dependency>
        
        <dependency>
            <groupId>com.fasterxml.jackson.coregroupId>
            <artifactId>jackson-databindartifactId>
            <version>${jackson.version}version>
        dependency>
        
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>${junit.version}version>
            <scope>testscope>
        dependency>

        
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-apiartifactId>
            <version>${slf4j.version}version>
        dependency>
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>jul-to-slf4jartifactId>
            <version>${slf4j.version}version>
        dependency>
        <dependency>
            <groupId>ch.qos.logbackgroupId>
            <artifactId>logback-coreartifactId>
            <version>${logback.version}version>
        dependency>
        <dependency>
            <groupId>ch.qos.logbackgroupId>
            <artifactId>logback-classicartifactId>
            <version>${logback.version}version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4jgroupId>
                    <artifactId>slf4j-apiartifactId>
                exclusion>
            exclusions>
        dependency>
        <dependency>
            <groupId>commons-logginggroupId>
            <artifactId>commons-loggingartifactId>
            <version>${commons-logging.version}version>
        dependency>


        
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
            <version>${mybatis.version}version>
        dependency>
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatis-springartifactId>
            <version>${mybatis.spring.version}version>
        dependency>
        <dependency>
            <groupId>com.github.miemiedevgroupId>
            <artifactId>mybatis-paginatorartifactId>
            <version>${mybatis.paginator.version}version>
        dependency>
        
        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelperartifactId>
            <version>${pagehelper.version}version>
        dependency>
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>${mysql.version}version>
        dependency>
        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>${druid.version}version>
        dependency>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-beansartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webmvcartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-jdbcartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-aspectsartifactId>
            <version>${spring.version}version>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-context-supportartifactId>
            <version>${spring.version}version>
        dependency>
        
        <dependency>
            <groupId>jstlgroupId>
            <artifactId>jstlartifactId>
            <version>${jstl.version}version>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>servlet-apiartifactId>
            <version>${servlet-api.version}version>
            <scope>providedscope>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>jsp-apiartifactId>
            <version>${jsp-api.version}version>
            <scope>providedscope>
        dependency>
        
        <dependency>
            <groupId>commons-fileuploadgroupId>
            <artifactId>commons-fileuploadartifactId>
            <version>${commons-fileupload.version}version>
        dependency>
        <dependency>
            <groupId>org.apache.tomcat.embedgroupId>
            <artifactId>tomcat-embed-coreartifactId>
            <version>7.0.47version>
        dependency>
    dependencies>
    <build>
        <finalName>${project.artifactId}finalName>
        <defaultGoal>compiledefaultGoal>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-resources-pluginartifactId>
                <version>2.7version>
                <configuration>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.2version>
                <configuration>
                    <source>1.7source>
                    <target>1.7target>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.tomcat.mavengroupId>
                <artifactId>tomcat7-maven-pluginartifactId>
                <version>2.2version>
                <configuration>
                    <port>8080port>
                    <path>/path>
                configuration>
            plugin>
            <plugin>
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.2version>
                <configuration>
                          <configurationFile>src/main/resources/generatorConfig.xmlconfigurationFile>
                    <verbose>trueverbose>
                    <overwrite>trueoverwrite>
                configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifactsid>
                        <goals>
                            <goal>generategoal>
                        goals>
                    execution>
                executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generatorgroupId>
                        <artifactId>mybatis-generator-coreartifactId>
                        <version>1.3.2version>
                    dependency>
                dependencies>
            plugin>
        plugins>
        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.xmlinclude>
                    <include>**/*.propertiesinclude>
                    <include>**/*.iniinclude>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>
    build>


project>

    然后是web.xml  spring mybatis jdbc 的一些相关配置文件。大家可以用自己之前的项目直接复制文件就行

    也可以粘贴我的   我把我的配置文件留下供参考

  

     web.xml

xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ssm_bbsdisplay-name>
  <welcome-file-list>

    <welcome-file>login.jspwelcome-file>

  welcome-file-list>
  
  <context-param>
    <param-name>contextConfigLocationparam-name>
    <param-value>classpath:spring/ApplicationContext-*.xmlparam-value>
  context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
  listener>

  
  <servlet>
    <servlet-name>SpringMvcservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
    
    <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>classpath:spring/SpringMvc.xmlparam-value>
    init-param>

    
    <load-on-startup>1load-on-startup>

  servlet>


  <servlet-mapping>
    <servlet-name>SpringMvcservlet-name>
    <url-pattern>*.actionurl-pattern>
  servlet-mapping>

  
  <filter>
    <filter-name>CharacterEncodingFilterfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
      <param-name>encodingparam-name>
      <param-value>utf-8param-value>
    init-param>
  filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilterfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>


web-app>

    mybatis-config.xml

          

xml version="1.0" encoding="UTF-8" ?>
 configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
   <typeAliases>
      <typeAlias type="com.liv587.pojo.Massage" alias="Massage"/>
      <typeAlias type="com.liv587.pojo.User" alias="User"/>
      <typeAlias type="com.liv587.pojo.Comment" alias="Comment"/>
      <typeAlias type="com.liv587.pojo.Essay" alias="Essay"/>
   typeAliases>
   
   
   <mappers>
      <mapper resource="com/liv587/dao/UserMapper.xml"/>
      <mapper resource="com/liv587/dao/MassageMapper.xml"/>
   mappers>
configuration>

   

Spring.xml

xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.1.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
    ">



   
   <context:component-scan base-package="com.liv587.controller">context:component-scan>


   
   
   <mvc:annotation-driven conversion-service="conversionService">mvc:annotation-driven>

   <bean id="conversionService"
        class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
      <property name="converters">
         <set>
            <bean class="com.liv587.converter.CustomGlobalStrToDateConverter"/>
         set>
      property>
   bean>

   
   
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/">property>
      <property name="suffix" value=".jsp">property>
   bean>


   <mvc:interceptors>
      <mvc:interceptor>
         <mvc:mapping path="/**"/>
         <bean class="com.liv587.interceptor.LoginInterceptor">bean>
      mvc:interceptor>
   mvc:interceptors>

beans>


然后完善你的项目  (有需要源码的可以找我要)


4.配置WEB 项目

    快捷键  crtl+alt+shift+s  打开Project Struture---Artifact-----上方的+号 然后点图中的选项

  Maven 初学者 用IDEA 搭建Maven+SSM项目_第4张图片


选择你的项目  点OK

Maven 初学者 用IDEA 搭建Maven+SSM项目_第5张图片


5.配置tomcat

点右上方的选项

  



点+号 ----Tomcat Server --- Local

Maven 初学者 用IDEA 搭建Maven+SSM项目_第6张图片

配置下面信息  

Maven 初学者 用IDEA 搭建Maven+SSM项目_第7张图片


Maven 初学者 用IDEA 搭建Maven+SSM项目_第8张图片

然后OK

启动你的Tomcat   测试

    Maven 初学者 用IDEA 搭建Maven+SSM项目_第9张图片

圆满结束   希望能对大家有帮助吧,  如有错误 各位及时指正

你可能感兴趣的:(Maven 初学者 用IDEA 搭建Maven+SSM项目)