初学者搭建ssm框架demo

--------------------- 作者:凉城古梦喵扑街 来源:CSDN 原文:https://blog.csdn.net/ssh159/article/details/80529428?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!

 

从eclipse换到idea,SSM的项目跟maven真的不好配置,下面讲解踩坑步骤(感谢A+大佬帮助以及论坛大佬们的demo)

项目结构:

一、设置Maven:

Maven的官网 点击打开链接

下载解压后,到 maven-XXX /conf/ settings.xml 里配置下,;

1,找到localRepository,设置你的jar包储存目录,可自定义

比如我:  

<localRepository>F:\Java\apache-maven-3.3.9\repo</localRepository>

2,配置云端链接,下载jar包的地址,为了防止有墙或者单个云端挂了,

我们设置三个地址保险一点

 
  1. <mirror>

  2. <id>alimaven</id>

  3. <name>aliyun maven</name>

  4. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

  5. <mirrorOf>central</mirrorOf>

  6. </mirror>

  7.  
  8. <mirror>

  9. <id>ui</id>

  10. <mirrorOf>central</mirrorOf>

  11. <name>Human Readable Name for this Mirror.</name>

  12. <url>http://uk.maven.org/maven2/</url>

  13. </mirror>

  14.  
  15. <mirror>

  16. <id>sprintio</id>

  17. <mirrorOf>central</mirrorOf>

  18. <name>Human Readable Name for this Mirror.</name>

  19. <url>https://repo.spring.io/libs-snapshot/</url>

  20. </mirror>

二、idea创建项目:

1、next->new window open 在新的窗口打开,

这里暂时不用脚手架 ,我的包名是:com.spring 

 

填写你的包名跟项目名后,开始搭建框架

ssmwork,ssmdemo都行,

新建后,这里有java,resources文件,pom.xml,这些都是大致文件

 

2、main.java

 
  1. package com.spring.controller;

  2.  
  3.  
  4. import com.spring.pojo.Admin;

  5. import com.spring.service.AdminService;

  6. import org.springframework.stereotype.Controller;

  7. import org.springframework.web.bind.annotation.PathVariable;

  8. import org.springframework.web.bind.annotation.RequestMapping;

  9. import org.springframework.web.bind.annotation.RequestMethod;

  10. import org.springframework.web.bind.annotation.ResponseBody;

  11.  
  12. import javax.annotation.Resource;

  13.  
  14. @Controller

  15. public class main {

  16.  
  17. @Resource

  18. AdminService adminService;

  19. @RequestMapping("/")

  20. @ResponseBody

  21. public String index(){

  22. return "hello world";

  23. }

  24.  
  25. @RequestMapping(value = "/admin",method = RequestMethod.POST)

  26. @ResponseBody

  27. public int insertUser(Admin admin){

  28. return adminService.insertAdmin(admin);

  29.  
  30. }

  31. @RequestMapping(value = "/admin/{id}",method = RequestMethod.GET)

  32. @ResponseBody

  33. public Admin getUser(@PathVariable Integer id){

  34. return adminService.getAdmin(id);

  35.  
  36. }

  37. }

3、AdminMapper.java (接口)

 
  1. package com.spring.dao;

  2.  
  3. import com.spring.pojo.Admin;

  4.  
  5. public interface AdminMapper {

  6. int deleteByPrimaryKey(Integer id);

  7.  
  8. int insert(Admin record);

  9.  
  10. int insertSelective(Admin record);

  11.  
  12. Admin selectByPrimaryKey(Integer id);

  13.  
  14. int updateByPrimaryKeySelective(Admin record);

  15.  
  16. int updateByPrimaryKey(Admin record);

  17. }

 

4、Admin.java(实体类)

 
  1. package com.spring.pojo;

  2.  
  3. public class Admin {

  4. private Integer id;

  5.  
  6. private String name;

  7.  
  8. private String password;

  9.  
  10. public Integer getId() {

  11. return id;

  12. }

  13.  
  14. public void setId(Integer id) {

  15. this.id = id;

  16. }

  17.  
  18. public String getName() {

  19. return name;

  20. }

  21.  
  22. public void setName(String name) {

  23. this.name = name == null ? null : name.trim();

  24. }

  25.  
  26. public String getPassword() {

  27. return password;

  28. }

  29.  
  30. public void setPassword(String password) {

  31. this.password = password == null ? null : password.trim();

  32. }

  33. }

5、AdminService.java(业务逻辑处理层)

 
  1. package com.spring.service;

  2.  
  3. import com.spring.pojo.Admin;

  4. import com.spring.dao.AdminMapper;

  5. import com.spring.pojo.Admin;

  6. import org.springframework.stereotype.Service;

  7.  
  8. import javax.annotation.Resource;

  9.  
  10. @Service("AdminService")

  11.  
  12. public class AdminService {

  13. @Resource

  14. protected AdminMapper adminMapper;

  15.  
  16.  
  17. public Admin getAdmin(int id){

  18. Admin a=this.adminMapper.selectByPrimaryKey(id);

  19. if(a!=null){

  20. return a;

  21. }

  22. return null;

  23. }

  24.  
  25. public int insertAdmin(Admin admin){

  26. return this.adminMapper.insert(admin);

  27. }

  28.  
  29.  
  30. }

6、AdminMapper.xml(映射)

 
  1. <?xml version="1.0" encoding="UTF-8" ?>

  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

  3. <mapper namespace="com.spring.dao.AdminMapper" >

  4. <resultMap id="BaseResultMap" type="com.spring.pojo.Admin" >

  5. <id column="id" property="id" jdbcType="INTEGER" />

  6. <result column="name" property="name" jdbcType="VARCHAR" />

  7. <result column="password" property="password" jdbcType="VARCHAR" />

  8. </resultMap>

  9. <sql id="Base_Column_List" >

  10. id, name, password

  11. </sql>

  12. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >

  13. select

  14. <include refid="Base_Column_List" />

  15. from admin

  16. where id = #{id,jdbcType=INTEGER}

  17. </select>

  18. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >

  19. delete from admin

  20. where id = #{id,jdbcType=INTEGER}

  21. </delete>

  22. <insert id="insert" parameterType="com.spring.pojo.Admin" >

  23. insert into admin (id, name, password

  24. )

  25. values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}

  26. )

  27. </insert>

  28. <insert id="insertSelective" parameterType="com.spring.pojo.Admin" >

  29. insert into admin

  30. <trim prefix="(" suffix=")" suffixOverrides="," >

  31. <if test="id != null" >

  32. id,

  33. </if>

  34. <if test="name != null" >

  35. name,

  36. </if>

  37. <if test="password != null" >

  38. password,

  39. </if>

  40. </trim>

  41. <trim prefix="values (" suffix=")" suffixOverrides="," >

  42. <if test="id != null" >

  43. #{id,jdbcType=INTEGER},

  44. </if>

  45. <if test="name != null" >

  46. #{name,jdbcType=VARCHAR},

  47. </if>

  48. <if test="password != null" >

  49. #{password,jdbcType=VARCHAR},

  50. </if>

  51. </trim>

  52. </insert>

  53. <update id="updateByPrimaryKeySelective" parameterType="com.spring.pojo.Admin" >

  54. update admin

  55. <set >

  56. <if test="name != null" >

  57. name = #{name,jdbcType=VARCHAR},

  58. </if>

  59. <if test="password != null" >

  60. password = #{password,jdbcType=VARCHAR},

  61. </if>

  62. </set>

  63. where id = #{id,jdbcType=INTEGER}

  64. </update>

  65. <update id="updateByPrimaryKey" parameterType="com.spring.pojo.Admin" >

  66. update admin

  67. set name = #{name,jdbcType=VARCHAR},

  68. password = #{password,jdbcType=VARCHAR}

  69. where id = #{id,jdbcType=INTEGER}

  70. </update>

  71. </mapper>

三、resources设置

1、jdbc.properties (数据库设置连接层)

 
  1. driver=com.mysql.jdbc.Driver

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

  3. username=root

  4. password=123456

  5. #定义初始连接数

  6. initialSize=0

  7. #定义最大连接数

  8. maxActive=20

  9. #定义最大空闲

  10. maxIdle=20

  11. #定义最小空闲

  12. minIdle=1

  13. #定义最长等待时间

  14. maxWait=60000

2、log4j.properties(日志文件记录)

 
  1. #定义LOG输出级别

  2. log4j.rootLogger=INFO,Console,File

  3. #定义日志输出目的地为控制台

  4. log4j.appender.Console=org.apache.log4j.ConsoleAppender

  5. log4j.appender.Console.Target=System.out

  6. #可以灵活地指定日志输出格式,下面一行是指定具体的格式

  7. log4j.appender.Console.layout = org.apache.log4j.PatternLayout

  8. log4j.appender.Console.layout.ConversionPattern=[%c] - %m%n

  9.  
  10. #文件大小到达指定尺寸的时候产生一个新的文件

  11. log4j.appender.File = org.apache.log4j.RollingFileAppender

  12. #指定输出目录

  13. log4j.appender.File.File = logs/ssm.log

  14. #定义文件最大大小

  15. log4j.appender.File.MaxFileSize = 10MB

  16. # 输出所以日志,如果换成DEBUG表示输出DEBUG以上级别日志

  17. log4j.appender.File.Threshold = ALL

  18. log4j.appender.File.layout = org.apache.log4j.PatternLayout

  19. log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

3、log4j.xml

 
  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <!DOCTYPE log4j:configuration SYSTEM "http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd">

  3. <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'

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

  5. xsi:schemaLocation="http://jakarta.apache.org/log4j/ ">

  6. <!-- ===================================================================== -->

  7. <!-- 定义全局输出适配器 -->

  8. <!-- ===================================================================== -->

  9. <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">

  10. <layout class="org.apache.log4j.PatternLayout">

  11. <param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}]-[%c]-[%t] %x - %m%n"/>

  12. </layout>

  13. </appender>

  14.  
  15. <!-- Mybatis and SQL -->

  16. <logger name="org.apache.ibatis" additivity="true">

  17. <level value="DEBUG"/>

  18. <appender-ref ref="consoleAppender"/>

  19. </logger>

  20.  
  21. <logger name="org.mybatis.spring" additivity="true">

  22. <level value="ERROR"/>

  23. <appender-ref ref="consoleAppender"/>

  24. </logger>

  25. <logger name="java.sql" additivity="true">

  26. <level value="DEBUG"/>

  27. <appender-ref ref="consoleAppender"/>

  28. </logger>

  29.  
  30. <logger name="java.sql.Connection" additivity="true">

  31. <level value="DEBUG"/>

  32. <appender-ref ref="consoleAppender"/>

  33. </logger>

  34.  
  35. <logger name="java.sql.Statement" additivity="true">

  36. <level value="DEBUG"/>

  37. <appender-ref ref="consoleAppender"/>

  38. </logger>

  39.  
  40. <logger name="java.sql.PreparedStatement" additivity="true">

  41. <level value="DEBUG"/>

  42. <appender-ref ref="consoleAppender"/>

  43. </logger>

  44.  
  45. <!-- Spring -->

  46. <logger name="org.springframework" additivity="true">

  47. <level value="ERROR"/>

  48. <appender-ref ref="consoleAppender"/>

  49. </logger>

  50.  
  51. <!-- ActiveMQ -->

  52. <logger name="org.apache.activemq" additivity="true">

  53. <level value="ERROR"/>

  54. <appender-ref ref="consoleAppender"/>

  55. </logger>

  56. <!-- ===================================================================== -->

  57. <!-- 根日志记录器 -->

  58. <!-- ===================================================================== -->

  59. <root>

  60. <level value="DEBUG"/>

  61. <appender-ref ref="consoleAppender"/>

  62. </root>

  63. </log4j:configuration>

4、mybatis-config.xml

 
  1. <?xml version="1.0" encoding="UTF-8" ?>

  2. <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

  3. <configuration>

  4. <!--配置全局属性-->

  5. <settings>

  6. <setting name="logImpl" value="LOG4J" />

  7. <setting name="cacheEnabled" value="true"/>

  8. </settings>

  9. </configuration>

5、spring-mvc.xml

 
  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <beans xmlns="http://www.springframework.org/schema/beans"

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

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

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

  6. xsi:schemaLocation="http://www.springframework.org/schema/beans

  7. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

  8. http://www.springframework.org/schema/context

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

  10. http://www.springframework.org/schema/mvc

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

  12. <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->

  13. <context:component-scan base-package="com.spring.controller" />

  14.  
  15. <!--避免IE执行AJAX时,返回JSON出现下载文件 -->

  16. <bean id="mappingJacksonHttpMessageConverter"

  17. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

  18. <property name="supportedMediaTypes">

  19. <list>

  20. <value>text/html;charset=UTF-8</value>

  21. </list>

  22. </property>

  23. </bean>

  24. <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->

  25. <bean

  26. class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

  27. <property name="messageConverters">

  28. <list>

  29. <ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON转换器 -->

  30. </list>

  31. </property>

  32. </bean>

  33. <!-- 定义跳转的文件的前后缀 ,视图模式配置-->

  34. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

  35. <!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->

  36. <property name="prefix" value="/WEB-INF/page/" />

  37. <property name="suffix" value=".jsp" />

  38. </bean>

  39.  
  40. <!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 -->

  41. <bean id="multipartResolver"

  42. class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

  43. <!-- 默认编码 -->

  44. <property name="defaultEncoding" value="utf-8" />

  45. <!-- 文件大小最大值 -->

  46. <property name="maxUploadSize" value="10485760000" />

  47. <!-- 内存中的最大值 -->

  48. <property name="maxInMemorySize" value="40960" />

  49. </bean>

  50.  
  51. </beans>

6、spring-mybatis.xml

 
  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <beans xmlns="http://www.springframework.org/schema/beans"

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

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

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

  6. xsi:schemaLocation="http://www.springframework.org/schema/beans

  7. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

  8. http://www.springframework.org/schema/context

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

  10. http://www.springframework.org/schema/mvc

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

  12. <!-- 自动扫描 -->

  13. <context:component-scan base-package="com.spring" />

  14. <!-- 引入配置文件 -->

  15. <bean id="propertyConfigurer"

  16. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

  17. <property name="location" value="classpath:jdbc.properties" />

  18. </bean>

  19.  
  20. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"

  21. destroy-method="close">

  22. <property name="driverClassName" value="${driver}" />

  23. <property name="url" value="${url}" />

  24. <property name="username" value="${username}" />

  25. <property name="password" value="${password}" />

  26. <!-- 初始化连接大小 -->

  27. <property name="initialSize" value="${initialSize}"></property>

  28. <!-- 连接池最大数量 -->

  29. <property name="maxActive" value="${maxActive}"></property>

  30. <!-- 连接池最大空闲 -->

  31. <property name="maxIdle" value="${maxIdle}"></property>

  32. <!-- 连接池最小空闲 -->

  33. <property name="minIdle" value="${minIdle}"></property>

  34. <!-- 获取连接最大等待时间 -->

  35. <property name="maxWait" value="${maxWait}"></property>

  36. </bean>

  37.  
  38. <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->

  39. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

  40. <property name="dataSource" ref="dataSource" />

  41. <property name="configLocation" value="classpath:/mybatis-config.xml"></property>

  42. <!-- 自动扫描mapping.xml文件 -->

  43. <property name="mapperLocations" value="classpath:com/spring/mapping/*.xml"/>

  44. </bean>

  45.  
  46. <!-- DAO接口所在包名,Spring会自动查找其下的类 -->

  47. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

  48. <property name="basePackage" value="com.spring.dao" />

  49. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

  50. </bean>

  51.  
  52. <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->

  53. <bean id="transactionManager"

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

  55. <property name="dataSource" ref="dataSource" />

  56. </bean>

  57.  
  58. </beans>

四、其他资源:

1、webapp下的web.xml

注意你的项目名

 
  1. <!DOCTYPE web-app PUBLIC

  2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

  3. "http://java.sun.com/dtd/web-app_2_3.dtd" >

  4.  
  5. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  6. xmlns="http://java.sun.com/xml/ns/javaee"

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

  8. version="3.0">

  9. <display-name>SSMDemoTwo</display-name>

  10. <welcome-file-list>

  11. <welcome-file>index.html</welcome-file>

  12. <welcome-file>index.jsp</welcome-file>

  13. </welcome-file-list>

  14. <!-- Spring和mybatis的配置文件 -->

  15. <context-param>

  16. <param-name>contextConfigLocation</param-name>

  17. <param-value>classpath:spring-mybatis.xml</param-value>

  18. </context-param>

  19.  
  20. <!--Log4j配置-->

  21. <context-param>

  22. <param-name>log4jRefreshInterval</param-name>

  23. <param-value>60000</param-value>

  24. </context-param>

  25. <listener>

  26. <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>

  27. </listener>

  28.  
  29.  
  30. <!-- 编码过滤器 -->

  31. <filter>

  32. <filter-name>encodingFilter</filter-name>

  33. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

  34. <init-param>

  35. <param-name>encoding</param-name>

  36. <param-value>UTF-8</param-value>

  37. </init-param>

  38.  
  39. </filter>

  40.  
  41. <filter-mapping>

  42. <filter-name>encodingFilter</filter-name>

  43. <url-pattern>/*</url-pattern>

  44. </filter-mapping>

  45.  
  46. <!--Spring监听器 ApplicationContext 载入 -->

  47. <listener>

  48. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  49. </listener>

  50. <!-- 防止Spring内存溢出监听器 -->

  51. <listener>

  52. <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

  53. </listener>

  54.  
  55.  
  56. <!-- Spring MVC 核心配置开始 -->

  57. <servlet>

  58. <servlet-name>mvc-dispatcher</servlet-name>

  59. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  60. <!-- 可以通过contextConfigLocation来自定义SpringMVC配置文件的位置,如不指定,则默认在WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,

  61. 此时文件名必须为[<servlet-name>]-servlet.xml,否则会出错-->

  62. <!--以下init-param是自定义SpringMVC的配置文件的位置 -->

  63. <init-param>

  64. <param-name>contextConfigLocation</param-name>

  65. <param-value>classpath:spring-mvc.xml</param-value>

  66. </init-param>

  67. <load-on-startup>1</load-on-startup>

  68. <async-supported>true</async-supported>

  69. </servlet>

  70.  
  71.  
  72. <!-- 拦截设置 -->

  73. <servlet-mapping>

  74. <servlet-name>mvc-dispatcher</servlet-name>

  75. <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->

  76. <url-pattern>/</url-pattern>

  77. </servlet-mapping>

  78. <!-- Spring MVC 核心配置结束 -->

  79.  
  80. <!-- 配置SESSION超时,单位是分钟 -->

  81. <session-config>

  82. <session-timeout>15</session-timeout>

  83. </session-config>

  84. </web-app>

2、pom.xml 注意你的包名

温馨提示:mysql 5.1.46这个jar包可以兼容5.6,5.7的版本

build 里面的 port , 可以自定义端口名,这里是8081,项目名是 ssmdemotwo

 
  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <project xmlns="http://maven.apache.org/POM/4.0.0"

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

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

  5. <modelVersion>4.0.0</modelVersion>

  6.  
  7. <groupId>com.ssm.DemoTwo</groupId>

  8. <artifactId>DemoTwo</artifactId>

  9. <version>1.0-SNAPSHOT</version>

  10.  
  11. <name>hugo Maven Webapp</name>

  12. <url>http://maven.apache.org</url>

  13.  
  14. <properties>

  15. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  16. <!-- spring版本号 -->

  17. <spring.version>4.1.4.RELEASE</spring.version>

  18. <!-- mybatis版本号 -->

  19. <mybatis.version>3.2.8</mybatis.version>

  20. <!-- log4j日志文件管理包版本 -->

  21. <slf4j.version>1.7.7</slf4j.version>

  22. <log4j.version>1.2.17</log4j.version>

  23. <!-- jackson包版本 -->

  24. <jackson.version>2.5.0</jackson.version>

  25. </properties>

  26.  
  27. <dependencies>

  28.  
  29. <dependency>

  30. <groupId>junit</groupId>

  31. <artifactId>junit</artifactId>

  32. <version>3.8.1</version>

  33. <scope>test</scope>

  34. </dependency>

  35. <!-- mybatis核心包 -->

  36. <dependency>

  37. <groupId>org.mybatis</groupId>

  38. <artifactId>mybatis</artifactId>

  39. <version>${mybatis.version}</version>

  40. </dependency>

  41. <!-- mybatis/spring包 -->

  42. <dependency>

  43. <groupId>org.mybatis</groupId>

  44. <artifactId>mybatis-spring</artifactId>

  45. <version>1.2.2</version>

  46. </dependency>

  47.  
  48. <!--spring单元测试依赖 -->

  49. <dependency>

  50. <groupId>org.springframework</groupId>

  51. <artifactId>spring-test</artifactId>

  52. <version>4.1.7.RELEASE</version>

  53. <scope>test</scope>

  54. </dependency>

  55.  
  56. <!-- springMVC核心包 -->

  57. <dependency>

  58. <groupId>org.springframework</groupId>

  59. <artifactId>spring-webmvc</artifactId>

  60. <version>${spring.version}</version>

  61. </dependency>

  62.  
  63. <!-- spring核心包 -->

  64. <dependency>

  65. <groupId>org.springframework</groupId>

  66. <artifactId>spring-core</artifactId>

  67. <version>${spring.version}</version>

  68. </dependency>

  69.  
  70. <dependency>

  71. <groupId>org.springframework</groupId>

  72. <artifactId>spring-beans</artifactId>

  73. <version>${spring.version}</version>

  74. </dependency>

  75.  
  76. <dependency>

  77. <groupId>org.springframework</groupId>

  78. <artifactId>spring-context</artifactId>

  79. <version>${spring.version}</version>

  80. </dependency>

  81.  
  82. <dependency>

  83. <groupId>org.springframework</groupId>

  84. <artifactId>spring-context-support</artifactId>

  85. <version>${spring.version}</version>

  86. </dependency>

  87.  
  88. <dependency>

  89. <groupId>org.springframework</groupId>

  90. <artifactId>spring-tx</artifactId>

  91. <version>${spring.version}</version>

  92. </dependency>

  93.  
  94. <dependency>

  95. <groupId>org.springframework</groupId>

  96. <artifactId>spring-web</artifactId>

  97. <version>${spring.version}</version>

  98. </dependency>

  99.  
  100. <dependency>

  101. <groupId>org.springframework</groupId>

  102. <artifactId>spring-jdbc</artifactId>

  103. <version>${spring.version}</version>

  104. </dependency>

  105.  
  106. <dependency>

  107. <groupId>javax.servlet</groupId>

  108. <artifactId>javax.servlet-api</artifactId>

  109. <version>3.0.1</version>

  110. <scope>provided</scope>

  111. </dependency>

  112.  
  113. <dependency>

  114. <groupId>javax.servlet.jsp</groupId>

  115. <artifactId>jsp-api</artifactId>

  116. <version>2.2</version>

  117. <scope>provided</scope>

  118. </dependency>

  119.  
  120. <!-- 导入Mysql数据库链接jar包 -->

  121. <dependency>

  122. <groupId>mysql</groupId>

  123. <artifactId>mysql-connector-java</artifactId>

  124. <version>5.1.46</version>

  125. </dependency>

  126.  
  127. <!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->

  128. <dependency>

  129. <groupId>commons-dbcp</groupId>

  130. <artifactId>commons-dbcp</artifactId>

  131. <version>1.2.2</version>

  132. </dependency>

  133.  
  134. <!-- JSTL标签类 -->

  135. <dependency>

  136. <groupId>jstl</groupId>

  137. <artifactId>jstl</artifactId>

  138. <version>1.2</version>

  139. </dependency>

  140. <!-- 日志文件管理包 -->

  141. <!-- log start -->

  142. <dependency>

  143. <groupId>log4j</groupId>

  144. <artifactId>log4j</artifactId>

  145. <version>${log4j.version}</version>

  146. </dependency>

  147.  
  148.  
  149. <!-- 格式化对象,方便输出日志 -->

  150. <dependency>

  151. <groupId>com.alibaba</groupId>

  152. <artifactId>fastjson</artifactId>

  153. <version>1.1.41</version>

  154. </dependency>

  155.  
  156.  
  157. <dependency>

  158. <groupId>org.slf4j</groupId>

  159. <artifactId>slf4j-api</artifactId>

  160. <version>${slf4j.version}</version>

  161. </dependency>

  162.  
  163. <dependency>

  164. <groupId>org.slf4j</groupId>

  165. <artifactId>slf4j-log4j12</artifactId>

  166. <version>${slf4j.version}</version>

  167. </dependency>

  168. <!-- log end -->

  169. <!-- 映入JSON -->

  170. <dependency>

  171. <groupId>org.codehaus.jackson</groupId>

  172. <artifactId>jackson-mapper-asl</artifactId>

  173. <version>1.9.13</version>

  174. </dependency>

  175.  
  176. <dependency>

  177. <groupId>com.fasterxml.jackson.core</groupId>

  178. <artifactId>jackson-databind</artifactId>

  179. <version>2.1.0</version>

  180. </dependency>

  181. <dependency>

  182. <groupId>com.fasterxml.jackson.core</groupId>

  183. <artifactId>jackson-annotations</artifactId>

  184. <version>2.1.0</version>

  185. </dependency>

  186.  
  187. <!-- 上传组件包 -->

  188. <dependency>

  189. <groupId>commons-fileupload</groupId>

  190. <artifactId>commons-fileupload</artifactId>

  191. <version>1.3.1</version>

  192. </dependency>

  193. <dependency>

  194. <groupId>commons-io</groupId>

  195. <artifactId>commons-io</artifactId>

  196. <version>2.4</version>

  197. </dependency>

  198. <dependency>

  199. <groupId>commons-codec</groupId>

  200. <artifactId>commons-codec</artifactId>

  201. <version>1.9</version>

  202. </dependency>

  203.  
  204. <!-- <dependency>

  205. <groupId>junit</groupId>

  206. <artifactId>junit</artifactId>

  207. <version>4.11</version>

  208. <!– 表示开发的时候引入,发布的时候不会加载此包 –>

  209. <scope>test</scope>

  210. </dependency>-->

  211.  
  212. <!--Spring test相关依赖-->

  213. <dependency>

  214. <groupId>org.springframework</groupId>

  215. <artifactId>spring-test</artifactId>

  216. <version>4.1.7.RELEASE</version>

  217. </dependency>

  218. <dependency>

  219. <groupId>junit</groupId>

  220. <artifactId>junit</artifactId>

  221. <version>RELEASE</version>

  222. </dependency>

  223.  
  224. <dependency>

  225. <groupId>org.jsoup</groupId>

  226. <artifactId>jsoup</artifactId>

  227. <version>1.8.1</version>

  228. </dependency>

  229.  
  230. <dependency>

  231. <groupId>net.sourceforge.htmlunit</groupId>

  232. <artifactId>htmlunit</artifactId>

  233. <version>2.15</version>

  234. </dependency>

  235.  
  236.  
  237. <dependency>

  238. <groupId>org.seleniumhq.selenium</groupId>

  239. <artifactId>selenium-java</artifactId>

  240. <version>2.33.0</version>

  241. </dependency>

  242.  
  243. <dependency>

  244. <groupId>us.codecraft</groupId>

  245. <artifactId>webmagic-core</artifactId>

  246. <version>0.6.1</version>

  247. </dependency>

  248. <dependency>

  249. <groupId>us.codecraft</groupId>

  250. <artifactId>webmagic-extension</artifactId>

  251. <version>0.6.1</version>

  252. </dependency>

  253.  
  254.  
  255. </dependencies>

  256. <!-- <build>

  257. <finalName>hugo</finalName>

  258. <resources>

  259. <resource>

  260. <directory>src/main/java</directory>

  261. <includes>

  262. <include>**/*.xml</include>

  263. </includes>

  264. <filtering>true</filtering>

  265. </resource>

  266. </resources>

  267. </build>-->

  268.  
  269. <build>

  270. <plugins>

  271. <plugin>

  272. <groupId>org.apache.tomcat.maven</groupId>

  273. <artifactId>tomcat7-maven-plugin</artifactId>

  274. <version>2.2</version>

  275. <configuration>

  276. <!-- 端口 -->

  277. <port>8081</port>

  278. <!-- 上下文路径 "/" 表示没有 -->

  279. <path>/ssmDemeTwo</path>

  280. <!-- 忽略war包,tomcat打包会检查项目是否已经变成war,但是对于插件而言不需要打成war包 -->

  281. <ignorePackaging>true</ignorePackaging>

  282. </configuration>

  283. </plugin>

  284. </plugins>

  285. <finalName>hugo</finalName>

  286. <resources>

  287. <resource>

  288. <directory>src/main/java</directory>

  289. <includes>

  290. <include>**/*.xml</include>

  291. </includes>

  292. </resource>

  293. <resource>

  294. <directory>src/main/resources</directory>

  295. <includes>

  296. <include>*.*</include>

  297. </includes>

  298. </resource>

  299. </resources>

  300. </build>

  301.  
  302.  
  303. </project>

五、idea的配置:

1、maven配置

2、为了防止idea抽风说jdk识别有误

3、为项目添加web包

 

maven的好处:自动下载jar包,不必手动寻找添加进入lib,

pom.xml 配置即可!

 

4、添加spring识别(如果已经识别,则不用手动了)

5、配置跑起项目

 

运行后,打开网址输入:localhost:8081/ssmDemoTwo即可看到hello word

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值