一、创建一个空的项目作为存放整个项目的路径

1、选择 File——>new——>Project ——>Empty Project

2、WorkspaceforTest为项目存放文件夹。

二、maven继承:创建父-子项目,聚合工程

比如整个项目。以一个项目来演示。

|--e3-parent:父工程,打包方式pom,管理jar包的版本号。项目中所有工程都应该继承父工程。

  |--e3-common:通用的工具类通用的pojo。打包方式jar

  |--e3-manager:服务层工程。聚合工程。Pom工程

    |--e3-manager-dao:打包方式jar

    |--e3-manager-pojo:打包方式jar

    |--e3-manager-interface:打包方式jar

    |--e3-manager-service:打包方式:jar

   |--e3-manager-web:表现层工程。打包方式war

1、创建maven父工程 e3-parent

File——>New ——>Module.. ——>Maven

2、GroupId一般为公司域名倒过来写。ArtifactId写工程名字。

3、Maven home directory 在这里我选择自己安装的maven,还有User settings file 选择好本地仓库。

4、注意下e3-parent的项目路径,在WorkspaceforTest下面。

5、在e3-parent的pom.xml文件下添加<packaging>pom</packaging>,e3-parent是打成pom文件的。

6、就可以pom文件添加各种依赖了。在这里我的e3-parent的pom.xml文件如下。

e3-parent的pom.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" 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>e3.mall</groupId>
  8. <artifactId>e3-parent</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10.  
  11. <name>e3-parent</name>
  12. <packaging>pom</packaging>
  13. <!-- 集中定义依赖版本号 -->
  14. <properties>
  15. <junit.version>4.12</junit.version>
  16. <spring.version>4.2.4.RELEASE</spring.version>
  17. <mybatis.version>3.2.8</mybatis.version>
  18. <mybatis.spring.version>1.2.2</mybatis.spring.version>
  19. <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
  20. <mysql.version>5.1.46</mysql.version>
  21. <slf4j.version>1.6.4</slf4j.version>
  22. <jackson.version>2.4.2</jackson.version>
  23. <druid.version>1.0.9</druid.version>
  24. <httpclient.version>4.3.5</httpclient.version>
  25. <jstl.version>1.2</jstl.version>
  26. <servlet-api.version>2.5</servlet-api.version>
  27. <jsp-api.version>2.0</jsp-api.version>
  28. <joda-time.version>2.5</joda-time.version>
  29. <commons-lang3.version>3.3.2</commons-lang3.version>
  30. <commons-io.version>1.3.2</commons-io.version>
  31. <commons-net.version>3.3</commons-net.version>
  32. <pagehelper.version>3.4.2-fix</pagehelper.version>
  33. <jsqlparser.version>0.9.1</jsqlparser.version>
  34. <commons-fileupload.version>1.3.1</commons-fileupload.version>
  35. <jedis.version>2.7.2</jedis.version>
  36. <solrj.version>4.10.3</solrj.version>
  37. <dubbo.version>2.5.3</dubbo.version>
  38. <zookeeper.version>3.4.7</zookeeper.version>
  39. <zkclient.version>0.1</zkclient.version>
  40. <activemq.version>5.11.2</activemq.version>
  41. <freemarker.version>2.3.23</freemarker.version>
  42. <quartz.version>2.2.2</quartz.version>
  43. </properties>
  44. <dependencyManagement>
  45. <dependencies>
  46. <!-- 时间操作组件 -->
  47. <dependency>
  48. <groupId>joda-time</groupId>
  49. <artifactId>joda-time</artifactId>
  50. <version>${joda-time.version}</version>
  51. </dependency>
  52. <!-- Apache工具组件 -->
  53. <dependency>
  54. <groupId>org.apache.commons</groupId>
  55. <artifactId>commons-lang3</artifactId>
  56. <version>${commons-lang3.version}</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>org.apache.commons</groupId>
  60. <artifactId>commons-io</artifactId>
  61. <version>${commons-io.version}</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>commons-net</groupId>
  65. <artifactId>commons-net</artifactId>
  66. <version>${commons-net.version}</version>
  67. </dependency>
  68. <!-- Jackson Json处理工具包 -->
  69. <dependency>
  70. <groupId>com.fasterxml.jackson.core</groupId>
  71. <artifactId>jackson-databind</artifactId>
  72. <version>${jackson.version}</version>
  73. </dependency>
  74. <!-- httpclient -->
  75. <dependency>
  76. <groupId>org.apache.httpcomponents</groupId>
  77. <artifactId>httpclient</artifactId>
  78. <version>${httpclient.version}</version>
  79. </dependency>
  80. <!-- quartz任务调度框架 -->
  81. <dependency>
  82. <groupId>org.quartz-scheduler</groupId>
  83. <artifactId>quartz</artifactId>
  84. <version>${quartz.version}</version>
  85. </dependency>
  86. <!-- 单元测试 -->
  87. <dependency>
  88. <groupId>junit</groupId>
  89. <artifactId>junit</artifactId>
  90. <version>${junit.version}</version>
  91. <scope>test</scope>
  92. </dependency>
  93. <!-- 日志处理 -->
  94. <dependency>
  95. <groupId>org.slf4j</groupId>
  96. <artifactId>slf4j-log4j12</artifactId>
  97. <version>${slf4j.version}</version>
  98. </dependency>
  99. <!-- Mybatis -->
  100. <dependency>
  101. <groupId>org.mybatis</groupId>
  102. <artifactId>mybatis</artifactId>
  103. <version>${mybatis.version}</version>
  104. </dependency>
  105. <dependency>
  106. <groupId>org.mybatis</groupId>
  107. <artifactId>mybatis-spring</artifactId>
  108. <version>${mybatis.spring.version}</version>
  109. </dependency>
  110. <dependency>
  111. <groupId>com.github.miemiedev</groupId>
  112. <artifactId>mybatis-paginator</artifactId>
  113. <version>${mybatis.paginator.version}</version>
  114. </dependency>
  115. <dependency>
  116. <groupId>com.github.pagehelper</groupId>
  117. <artifactId>pagehelper</artifactId>
  118. <version>${pagehelper.version}</version>
  119. </dependency>
  120. <!-- MySql -->
  121. <dependency>
  122. <groupId>mysql</groupId>
  123. <artifactId>mysql-connector-java</artifactId>
  124. <version>${mysql.version}</version>
  125. </dependency>
  126. <!-- 连接池 -->
  127. <dependency>
  128. <groupId>com.alibaba</groupId>
  129. <artifactId>druid</artifactId>
  130. <version>${druid.version}</version>
  131. </dependency>
  132. <!-- Spring -->
  133. <dependency>
  134. <groupId>org.springframework</groupId>
  135. <artifactId>spring-context</artifactId>
  136. <version>${spring.version}</version>
  137. </dependency>
  138. <dependency>
  139. <groupId>org.springframework</groupId>
  140. <artifactId>spring-beans</artifactId>
  141. <version>${spring.version}</version>
  142. </dependency>
  143. <dependency>
  144. <groupId>org.springframework</groupId>
  145. <artifactId>spring-webmvc</artifactId>
  146. <version>${spring.version}</version>
  147. </dependency>
  148. <dependency>
  149. <groupId>org.springframework</groupId>
  150. <artifactId>spring-jdbc</artifactId>
  151. <version>${spring.version}</version>
  152. </dependency>
  153. <dependency>
  154. <groupId>org.springframework</groupId>
  155. <artifactId>spring-aspects</artifactId>
  156. <version>${spring.version}</version>
  157. </dependency>
  158. <dependency>
  159. <groupId>org.springframework</groupId>
  160. <artifactId>spring-jms</artifactId>
  161. <version>${spring.version}</version>
  162. </dependency>
  163. <dependency>
  164. <groupId>org.springframework</groupId>
  165. <artifactId>spring-context-support</artifactId>
  166. <version>${spring.version}</version>
  167. </dependency>
  168. <!-- JSP相关 -->
  169. <dependency>
  170. <groupId>jstl</groupId>
  171. <artifactId>jstl</artifactId>
  172. <version>${jstl.version}</version>
  173. </dependency>
  174. <dependency>
  175. <groupId>javax.servlet</groupId>
  176. <artifactId>servlet-api</artifactId>
  177. <version>${servlet-api.version}</version>
  178. <scope>provided</scope>
  179. </dependency>
  180. <dependency>
  181. <groupId>javax.servlet</groupId>
  182. <artifactId>jsp-api</artifactId>
  183. <version>${jsp-api.version}</version>
  184. <scope>provided</scope>
  185. </dependency>
  186. <!-- 文件上传组件 -->
  187. <dependency>
  188. <groupId>commons-fileupload</groupId>
  189. <artifactId>commons-fileupload</artifactId>
  190. <version>${commons-fileupload.version}</version>
  191. </dependency>
  192. <!-- Redis客户端 -->
  193. <dependency>
  194. <groupId>redis.clients</groupId>
  195. <artifactId>jedis</artifactId>
  196. <version>${jedis.version}</version>
  197. </dependency>
  198. <!-- solr客户端 -->
  199. <dependency>
  200. <groupId>org.apache.solr</groupId>
  201. <artifactId>solr-solrj</artifactId>
  202. <version>${solrj.version}</version>
  203. </dependency>
  204. <!-- dubbo相关 -->
  205. <dependency>
  206. <groupId>com.alibaba</groupId>
  207. <artifactId>dubbo</artifactId>
  208. <version>${dubbo.version}</version>
  209. </dependency>
  210. <dependency>
  211. <groupId>org.apache.zookeeper</groupId>
  212. <artifactId>zookeeper</artifactId>
  213. <version>${zookeeper.version}</version>
  214. </dependency>
  215. <dependency>
  216. <groupId>com.github.sgroschupf</groupId>
  217. <artifactId>zkclient</artifactId>
  218. <version>${zkclient.version}</version>
  219. </dependency>
  220. <dependency>
  221. <groupId>org.apache.activemq</groupId>
  222. <artifactId>activemq-all</artifactId>
  223. <version>${activemq.version}</version>
  224. </dependency>
  225. <dependency>
  226. <groupId>org.freemarker</groupId>
  227. <artifactId>freemarker</artifactId>
  228. <version>${freemarker.version}</version>
  229. </dependency>
  230.  
  231. </dependencies>
  232. </dependencyManagement>
  233.  
  234. <build>
  235. <finalName>${project.artifactId}</finalName>
  236. <plugins>
  237. <!-- 资源文件拷贝插件 -->
  238. <plugin>
  239. <groupId>org.apache.maven.plugins</groupId>
  240. <artifactId>maven-resources-plugin</artifactId>
  241. <version>2.7</version>
  242. <configuration>
  243. <encoding>UTF-8</encoding>
  244. </configuration>
  245. </plugin>
  246. <!-- java编译插件 -->
  247. <plugin>
  248. <groupId>org.apache.maven.plugins</groupId>
  249. <artifactId>maven-compiler-plugin</artifactId>
  250. <version>3.2</version>
  251. <configuration>
  252. <source>1.7</source>
  253. <target>1.7</target>
  254. <encoding>UTF-8</encoding>
  255. </configuration>
  256. </plugin>
  257. </plugins>
  258. <pluginManagement>
  259. <plugins>
  260. <!-- 配置Tomcat插件 -->
  261. <plugin>
  262. <groupId>org.apache.tomcat.maven</groupId>
  263. <artifactId>tomcat7-maven-plugin</artifactId>
  264. <version>2.2</version>
  265. </plugin>
  266. </plugins>
  267. </pluginManagement>
  268. </build>
  269.  
  270. </project>

  

7、创建e3-common,e3-common继承父工程parent。而且为了与eclipse下面一样一种好看,common工程的目录也是在WorkspaceforTest目录下,但是是继承了parent工程

File——>New——>module——>Maven

8、common工程也是在WorkspaceforTest目录下的,所以要在Add as module to选项中选择None,如下图所示

9、Parent 中选择继承的父工程e3-parent,如下图所示,再写好ArtifactId.

10、选择maven,如果没有发生改变,就可以直接下一步。

11、注意一下路径,是在WorkspaceforTest下面。

12、再在pom.xml下面添加<packaging>jar</packaging>,如下图所示。

在这个项目的pom文件如下代码所示。

e3-common的 pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" 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. <parent>
  6. <artifactId>e3-parent</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. <relativePath>../e3-parent/pom.xml</relativePath>
  10. </parent>
  11. <modelVersion>4.0.0</modelVersion>
  12.  
  13. <artifactId>e3-common</artifactId>
  14. <packaging>jar</packaging>
  15.  
  16. <name>e3-common</name>
  17. <dependencies>
  18. <!-- 时间操作组件 -->
  19. <dependency>
  20. <groupId>joda-time</groupId>
  21. <artifactId>joda-time</artifactId>
  22. </dependency>
  23. <!-- Apache工具组件 -->
  24. <dependency>
  25. <groupId>org.apache.commons</groupId>
  26. <artifactId>commons-lang3</artifactId>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.apache.commons</groupId>
  30. <artifactId>commons-io</artifactId>
  31. </dependency>
  32. <dependency>
  33. <groupId>commons-net</groupId>
  34. <artifactId>commons-net</artifactId>
  35. </dependency>
  36. <!-- Jackson Json处理工具包 -->
  37. <dependency>
  38. <groupId>com.fasterxml.jackson.core</groupId>
  39. <artifactId>jackson-databind</artifactId>
  40. </dependency>
  41. <!-- httpclient -->
  42. <dependency>
  43. <groupId>org.apache.httpcomponents</groupId>
  44. <artifactId>httpclient</artifactId>
  45. </dependency>
  46. <!-- quartz任务调度框架 -->
  47. <dependency>
  48. <groupId>org.quartz-scheduler</groupId>
  49. <artifactId>quartz</artifactId>
  50. </dependency>
  51. <!-- 单元测试 -->
  52. <dependency>
  53. <groupId>junit</groupId>
  54. <artifactId>junit</artifactId>
  55. <scope>test</scope>
  56. </dependency>
  57. <!-- 日志处理 -->
  58. <dependency>
  59. <groupId>org.slf4j</groupId>
  60. <artifactId>slf4j-log4j12</artifactId>
  61. </dependency>
  62. </dependencies>
  63.  
  64. </project>

  

13、创建manager工程,与common工程的方法一样。

File——>New——>module——>Maven

14、再在pom.xml下面添加<packaging>pom</packaging>,如下图所示。

e3-common的 pom.xml文件

  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. <parent>
  6. <artifactId>e3-parent</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. <relativePath>../e3-parent/pom.xml</relativePath>
  10. </parent>
  11. <modelVersion>4.0.0</modelVersion>
  12.  
  13. <artifactId>e3-manager</artifactId>
  14. <packaging>pom</packaging>
  15. <modules>
  16. <module>e3-manager-pojo</module>
  17. <module>e3-manager-dao</module>
  18. <module>e3-manager-interface</module>
  19. <module>e3-manager-service</module>
  20. <module>e3-manager-web</module>
  21. </modules>
  22. <dependencies>
  23. <dependency>
  24. <artifactId>e3-common</artifactId>
  25. <groupId>e3.mall</groupId>
  26. <version>1.0-SNAPSHOT</version>
  27. </dependency>
  28. </dependencies>
  29.  
  30. <build>
  31. <!-- 配置插件 -->
  32. <plugins>
  33. <plugin>
  34. <groupId>org.apache.tomcat.maven</groupId>
  35. <artifactId>tomcat7-maven-plugin</artifactId>
  36. <configuration>
  37. <port>8080</port>
  38. <path>/</path>
  39. </configuration>
  40. </plugin>
  41. </plugins>
  42. </build>
  43. </project>

  

15,来开始创建e3-manager-pojo、e3-manager-dao、e3-manager-interface、e3-manager-service,这四个工程最终都是打成jar包的,创建过程都是一样的,下面就只写出一个工程的创建过程。

以e3-manager-pojo为例。

16、选中e3-manager——>右击鼠标——>New——Module,因为e3-manager-pojo是e3-manager的子工程。

17、再在pom.xml下面添加<packaging>pom</packaging>,如下图所示。

18、e3-manager-pojo、e3-manager-dao、e3-manager-interface、e3-manager-service,这四个工程都是这样创建。

19、e3-manager-pojo、e3-manager-dao、e3-manager-interface、e3-manager-service,这四个工程的pom.xml文件。

e3-manager-pojo 的pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" 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. <parent>
  6. <artifactId>e3-manager</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11.  
  12. <artifactId>e3-manager-pojo</artifactId>
  13. <packaging>jar</packaging>
  14. <name>e3-manager-pojo</name>
  15.  
  16. </project>

  

e3-manager-dao 的pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" 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. <parent>
  6. <artifactId>e3-manager</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11.  
  12. <artifactId>e3-manager-dao</artifactId>
  13. <packaging>jar</packaging>
  14.  
  15. <name>e3-manager-dao</name>
  16. <dependencies>
  17. <dependency>
  18. <groupId>e3.mall</groupId>
  19. <artifactId>e3-manager-pojo</artifactId>
  20. <version>1.0-SNAPSHOT</version>
  21. </dependency>
  22. <!-- 添加对mybatis的依赖 -->
  23. <dependency>
  24. <groupId>org.mybatis</groupId>
  25. <artifactId>mybatis</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.mybatis</groupId>
  29. <artifactId>mybatis-spring</artifactId>
  30. </dependency>
  31. <dependency>
  32. <groupId>com.github.miemiedev</groupId>
  33. <artifactId>mybatis-paginator</artifactId>
  34. </dependency>
  35. <dependency>
  36. <groupId>com.github.pagehelper</groupId>
  37. <artifactId>pagehelper</artifactId>
  38. </dependency>
  39. <!-- MySql -->
  40. <dependency>
  41. <groupId>mysql</groupId>
  42. <artifactId>mysql-connector-java</artifactId>
  43. </dependency>
  44. <!-- 连接池 -->
  45. <dependency>
  46. <groupId>com.alibaba</groupId>
  47. <artifactId>druid</artifactId>
  48. </dependency>
  49.  
  50. </dependencies>
  51. <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
  52. <build>
  53. <resources>
  54. <resource>
  55. <directory>src/main/java</directory>
  56. <includes>
  57. <include>**/*.properties</include>
  58. <include>**/*.xml</include>
  59. </includes>
  60. <filtering>false</filtering>
  61. </resource>
  62. </resources>
  63. </build>
  64. </project>

  

e3-manager-interface 的pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" 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. <parent>
  6. <artifactId>e3-manager</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11.  
  12. <artifactId>e3-manager-interface</artifactId>
  13. <packaging>jar</packaging>
  14. <name>e3-manager-interface</name>
  15. <dependencies>
  16. <dependency>
  17. <groupId>e3.mall</groupId>
  18. <artifactId>e3-manager-pojo</artifactId>
  19. <version>1.0-SNAPSHOT</version>
  20. </dependency>
  21. </dependencies>
  22. </project>

  

e3-manager-servicer 的pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" 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. <parent>
  6. <artifactId>e3-manager</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11.  
  12. <artifactId>e3-manager-service</artifactId>
  13.  
  14. <name>e3-manager-service</name>
  15. <packaging>jar</packaging>
  16.  
  17. <dependencies>
  18. <dependency>
  19. <groupId>e3.mall</groupId>
  20. <artifactId>e3-manager-dao</artifactId>
  21. <version>1.0-SNAPSHOT</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>e3.mall</groupId>
  25. <artifactId>e3-manager-interface</artifactId>
  26. <version>1.0-SNAPSHOT</version>
  27. </dependency>
  28. <!-- spring的依赖 -->
  29. <!-- Spring -->
  30. <dependency>
  31. <groupId>org.springframework</groupId>
  32. <artifactId>spring-context</artifactId>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework</groupId>
  36. <artifactId>spring-beans</artifactId>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.springframework</groupId>
  40. <artifactId>spring-webmvc</artifactId>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.springframework</groupId>
  44. <artifactId>spring-jdbc</artifactId>
  45. </dependency>
  46. <dependency>
  47. <groupId>org.springframework</groupId>
  48. <artifactId>spring-aspects</artifactId>
  49. </dependency>
  50. <dependency>
  51. <groupId>org.springframework</groupId>
  52. <artifactId>spring-jms</artifactId>
  53. </dependency>
  54. <dependency>
  55. <groupId>org.springframework</groupId>
  56. <artifactId>spring-context-support</artifactId>
  57. </dependency>
  58.  
  59. </dependencies>
  60. </project>

  

20、最后创建e3-manager-web工程,创建过程都与上面的四个过程一样。只是有一个地方需要注意,下面的截图会提示。

选中e3-manager——>右击鼠标——>New——Module,因为e3-manager-web是e3-manager的子工程。

只是下面需要注意一下。

21、再在pom.xml下面添加<packaging>war</packaging>,如下图所示。

22、e3-manager-web的pom.xml文件

  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. <parent>
  6. <artifactId>e3-parent</artifactId>
  7. <groupId>e3.mall</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. <relativePath>../e3-parent/pom.xml</relativePath>
  10. </parent>
  11. <modelVersion>4.0.0</modelVersion>
  12.  
  13. <artifactId>e3-manager</artifactId>
  14. <packaging>pom</packaging>
  15. <modules>
  16. <module>e3-manager-pojo</module>
  17. <module>e3-manager-dao</module>
  18. <module>e3-manager-interface</module>
  19. <module>e3-manager-service</module>
  20. <module>e3-manager-web</module>
  21. </modules>
  22. <dependencies>
  23. <dependency>
  24. <artifactId>e3-common</artifactId>
  25. <groupId>e3.mall</groupId>
  26. <version>1.0-SNAPSHOT</version>
  27. </dependency>
  28. </dependencies>
  29.  
  30. <build>
  31. <!-- 配置插件 -->
  32. <plugins>
  33. <plugin>
  34. <groupId>org.apache.tomcat.maven</groupId>
  35. <artifactId>tomcat7-maven-plugin</artifactId>
  36. <configuration>
  37. <port>8080</port>
  38. <path>/</path>
  39. </configuration>
  40. </plugin>
  41. </plugins>
  42. </build>
  43. </project>

  

23、好了。到此maven聚合工程创建完成。

三、maven工程下创建resources文件夹

步骤:File——>Project Struture——>Modules——>maven工程,如果没有maven工程就点+号来添加

选择到创建resources文件夹的路径,比如图上的选择到main,右击鼠标,选择New Folder新建文件夹resources

再选择resources,右击鼠标选择Resources,可以看到resources文件夹的图标和之前不一样了,就是这样创建一个resources文件夹。再点Ok保存退出 。

很明图标都不一样了。

四、整合ssm框架

直接看项目路径,直接上代码,不懂ssm框架整合的可以百度学习下。

SqlMapConfig.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE configuration
  3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6.  
  7. </configuration>

  

db.properties

  1. jdbc.driver=com.mysql.jdbc.Driver
  2. jdbc.url=jdbc:mysql://localhost:3306/e3mall?charactherEncoding=utf-8
  3. jdbc.username=root
  4. jdbc.password=*****

  

applicationContext-Dao.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
  9. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
  10. <!--数据库连接池-->
  11. <!--加载配置文件-->
  12. <context:property-placeholder location="classpath:properties/db.properties"></context:property-placeholder>
  13. <!--数据库连接池-->
  14. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  15. <property name="driverClassName" value="${jdbc.driver}"></property>
  16. <property name="url" value="${jdbc.url}"></property>
  17. <property name="username" value="${jdbc.username}"></property>
  18. <property name="password" value="${jdbc.password}"></property>
  19. <property name="maxActive" value="10"></property>
  20. <property name="minIdle" value="5"></property>
  21. </bean>
  22. <!--让spring管理sqlsessionFactory,使用mybatis和spring整合包中的-->
  23. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  24. <!--数据库连接池-->
  25. <property name="dataSource" ref="dataSource"></property>
  26. <!--加载mybatis全局配置文件-->
  27. <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>
  28.  
  29. </bean>
  30.  
  31. <!--自动扫描mapper-->
  32. <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  33. <property name="basePackage" value="cn.e3mall.mapper"></property>
  34. </bean>
  35. </beans>

  

applicationContext-service.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
  9. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
  10.  
  11. <context:component-scan base-package="cn.e3mall.service"></context:component-scan>
  12. </beans>

  

applicationContext-trans.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
  9. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
  10. <!--事务管理器-->
  11. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  12. <!--数据源-->
  13. <property name="dataSource" ref="dataSource"/>
  14. </bean>
  15. <!--通知-->
  16. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  17. <tx:attributes>
  18. <tx:method name="save*" propagation="REQUIRED"/>
  19. <tx:method name="insert*" propagation="REQUIRED"/>
  20. <tx:method name="add*" propagation="REQUIRED"/>
  21. <tx:method name="create*" propagation="REQUIRED"/>
  22. <tx:method name="delete*" propagation="REQUIRED"/>
  23. <tx:method name="update*" propagation="REQUIRED"/>
  24. <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
  25. <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
  26. <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
  27. </tx:attributes>
  28.  
  29. </tx:advice>
  30. <!--切面-->
  31. <aop:config>
  32. <aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.e3mall.mapper.*.*(..))"></aop:advisor>
  33. </aop:config>
  34. </beans>

  

springmvc.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 http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  7. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
  8. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
  9. <!--扫描controller-->
  10. <context:component-scan base-package="cn.e3mall.controller"/>
  11. <!--配置适配器映射器-->
  12. <mvc:annotation-driven></mvc:annotation-driven>
  13.  
  14. <!--配置前端控制器-->
  15. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  16. <property name="prefix" value="/WEB-INF/jsp/"/>
  17. <property name="suffix" value=".jsp"/>
  18. </bean>
  19. </beans>

  

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. id="WebApp_ID" version="2.5">
  6. <display-name>e3-manager</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.jsp</welcome-file>
  9. </welcome-file-list>
  10.  
  11. <!--加载spring容器-->
  12. <context-param>
  13. <param-name>contextConfigLocation</param-name>
  14. <param-value>classpath:spring/applicationContext-*.xml</param-value>
  15. </context-param>
  16. <listener>
  17. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  18. </listener>
  19.  
  20. <!--配置post提交乱码-->
  21. <filter>
  22. <filter-name>CharacterEncodingFilter</filter-name>
  23. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  24. <init-param>
  25. <param-name>encoding</param-name>
  26. <param-value>utf-8</param-value>
  27. </init-param>
  28. </filter>
  29. <filter-mapping>
  30. <filter-name>CharacterEncodingFilter</filter-name>
  31. <url-pattern>/*</url-pattern>
  32. </filter-mapping>
  33. <!--spring前端控制器-->
  34. <servlet>
  35. <servlet-name>e3-manager</servlet-name>
  36. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  37. <init-param>
  38. <param-name>contextConfigLocation</param-name>
  39. <param-value>classpath:spring/springmvc.xml</param-value>
  40. </init-param>
  41. <load-on-startup>1</load-on-startup>
  42. </servlet>
  43. <servlet-mapping>
  44. <servlet-name>e3-manager</servlet-name>
  45. <url-pattern>/</url-pattern>
  46. </servlet-mapping>
  47. </web-app>

  

 TbItem.class

  1. package cn.e3mall.pojo;
  2.  
  3. import java.util.Date;
  4.  
  5. public class TbItem {
  6. private Long id;
  7.  
  8. private String title;
  9.  
  10. private String sellPoint;
  11.  
  12. private Long price;
  13.  
  14. private Integer num;
  15.  
  16. private String barcode;
  17.  
  18. private String image;
  19.  
  20. private Long cid;
  21.  
  22. private Byte status;
  23.  
  24. private Date created;
  25.  
  26. private Date updated;
  27.  
  28. public Long getId() {
  29. return id;
  30. }
  31.  
  32. public void setId(Long id) {
  33. this.id = id;
  34. }
  35.  
  36. public String getTitle() {
  37. return title;
  38. }
  39.  
  40. public void setTitle(String title) {
  41. this.title = title == null ? null : title.trim();
  42. }
  43.  
  44. public String getSellPoint() {
  45. return sellPoint;
  46. }
  47.  
  48. public void setSellPoint(String sellPoint) {
  49. this.sellPoint = sellPoint == null ? null : sellPoint.trim();
  50. }
  51.  
  52. public Long getPrice() {
  53. return price;
  54. }
  55.  
  56. public void setPrice(Long price) {
  57. this.price = price;
  58. }
  59.  
  60. public Integer getNum() {
  61. return num;
  62. }
  63.  
  64. public void setNum(Integer num) {
  65. this.num = num;
  66. }
  67.  
  68. public String getBarcode() {
  69. return barcode;
  70. }
  71.  
  72. public void setBarcode(String barcode) {
  73. this.barcode = barcode == null ? null : barcode.trim();
  74. }
  75.  
  76. public String getImage() {
  77. return image;
  78. }
  79.  
  80. public void setImage(String image) {
  81. this.image = image == null ? null : image.trim();
  82. }
  83.  
  84. public Long getCid() {
  85. return cid;
  86. }
  87.  
  88. public void setCid(Long cid) {
  89. this.cid = cid;
  90. }
  91.  
  92. public Byte getStatus() {
  93. return status;
  94. }
  95.  
  96. public void setStatus(Byte status) {
  97. this.status = status;
  98. }
  99.  
  100. public Date getCreated() {
  101. return created;
  102. }
  103.  
  104. public void setCreated(Date created) {
  105. this.created = created;
  106. }
  107.  
  108. public Date getUpdated() {
  109. return updated;
  110. }
  111.  
  112. public void setUpdated(Date updated) {
  113. this.updated = updated;
  114. }
  115. }

  

TbItemMapper.class  接口

  1. package cn.e3mall.mapper;
  2.  
  3. import cn.e3mall.pojo.TbItem;
  4. import cn.e3mall.pojo.TbItemExample;
  5. import java.util.List;
  6. import org.apache.ibatis.annotations.Param;
  7.  
  8. public interface TbItemMapper {
  9. int countByExample(TbItemExample example);
  10.  
  11. int deleteByExample(TbItemExample example);
  12.  
  13. int deleteByPrimaryKey(Long id);
  14.  
  15. int insert(TbItem record);
  16.  
  17. int insertSelective(TbItem record);
  18.  
  19. List<TbItem> selectByExample(TbItemExample example);
  20.  
  21. TbItem selectByPrimaryKey(Long id);
  22.  
  23. int updateByExampleSelective(@Param("record") TbItem record, @Param("example") TbItemExample example);
  24.  
  25. int updateByExample(@Param("record") TbItem record, @Param("example") TbItemExample example);
  26.  
  27. int updateByPrimaryKeySelective(TbItem record);
  28.  
  29. int updateByPrimaryKey(TbItem record);
  30. }

  

TbItemMapper.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="cn.e3mall.mapper.TbItemMapper" >
  4. <resultMap id="BaseResultMap" type="cn.e3mall.pojo.TbItem" >
  5. <id column="id" property="id" jdbcType="BIGINT" />
  6. <result column="title" property="title" jdbcType="VARCHAR" />
  7. <result column="sell_point" property="sellPoint" jdbcType="VARCHAR" />
  8. <result column="price" property="price" jdbcType="BIGINT" />
  9. <result column="num" property="num" jdbcType="INTEGER" />
  10. <result column="barcode" property="barcode" jdbcType="VARCHAR" />
  11. <result column="image" property="image" jdbcType="VARCHAR" />
  12. <result column="cid" property="cid" jdbcType="BIGINT" />
  13. <result column="status" property="status" jdbcType="TINYINT" />
  14. <result column="created" property="created" jdbcType="TIMESTAMP" />
  15. <result column="updated" property="updated" jdbcType="TIMESTAMP" />
  16. </resultMap>
  17. <sql id="Example_Where_Clause" >
  18. <where >
  19. <foreach collection="oredCriteria" item="criteria" separator="or" >
  20. <if test="criteria.valid" >
  21. <trim prefix="(" suffix=")" prefixOverrides="and" >
  22. <foreach collection="criteria.criteria" item="criterion" >
  23. <choose >
  24. <when test="criterion.noValue" >
  25. and ${criterion.condition}
  26. </when>
  27. <when test="criterion.singleValue" >
  28. and ${criterion.condition} #{criterion.value}
  29. </when>
  30. <when test="criterion.betweenValue" >
  31. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  32. </when>
  33. <when test="criterion.listValue" >
  34. and ${criterion.condition}
  35. <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
  36. #{listItem}
  37. </foreach>
  38. </when>
  39. </choose>
  40. </foreach>
  41. </trim>
  42. </if>
  43. </foreach>
  44. </where>
  45. </sql>
  46. <sql id="Update_By_Example_Where_Clause" >
  47. <where >
  48. <foreach collection="example.oredCriteria" item="criteria" separator="or" >
  49. <if test="criteria.valid" >
  50. <trim prefix="(" suffix=")" prefixOverrides="and" >
  51. <foreach collection="criteria.criteria" item="criterion" >
  52. <choose >
  53. <when test="criterion.noValue" >
  54. and ${criterion.condition}
  55. </when>
  56. <when test="criterion.singleValue" >
  57. and ${criterion.condition} #{criterion.value}
  58. </when>
  59. <when test="criterion.betweenValue" >
  60. and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
  61. </when>
  62. <when test="criterion.listValue" >
  63. and ${criterion.condition}
  64. <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
  65. #{listItem}
  66. </foreach>
  67. </when>
  68. </choose>
  69. </foreach>
  70. </trim>
  71. </if>
  72. </foreach>
  73. </where>
  74. </sql>
  75. <sql id="Base_Column_List" >
  76. id, title, sell_point, price, num, barcode, image, cid, status, created, updated
  77. </sql>
  78. <select id="selectByExample" resultMap="BaseResultMap" parameterType="cn.e3mall.pojo.TbItemExample" >
  79. select
  80. <if test="distinct" >
  81. distinct
  82. </if>
  83. <include refid="Base_Column_List" />
  84. from tb_item
  85. <if test="_parameter != null" >
  86. <include refid="Example_Where_Clause" />
  87. </if>
  88. <if test="orderByClause != null" >
  89. order by ${orderByClause}
  90. </if>
  91. </select>
  92. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
  93. select
  94. <include refid="Base_Column_List" />
  95. from tb_item
  96. where id = #{id,jdbcType=BIGINT}
  97. </select>
  98. <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
  99. delete from tb_item
  100. where id = #{id,jdbcType=BIGINT}
  101. </delete>
  102. <delete id="deleteByExample" parameterType="cn.e3mall.pojo.TbItemExample" >
  103. delete from tb_item
  104. <if test="_parameter != null" >
  105. <include refid="Example_Where_Clause" />
  106. </if>
  107. </delete>
  108. <insert id="insert" parameterType="cn.e3mall.pojo.TbItem" >
  109. insert into tb_item (id, title, sell_point,
  110. price, num, barcode,
  111. image, cid, status,
  112. created, updated)
  113. values (#{id,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{sellPoint,jdbcType=VARCHAR},
  114. #{price,jdbcType=BIGINT}, #{num,jdbcType=INTEGER}, #{barcode,jdbcType=VARCHAR},
  115. #{image,jdbcType=VARCHAR}, #{cid,jdbcType=BIGINT}, #{status,jdbcType=TINYINT},
  116. #{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})
  117. </insert>
  118. <insert id="insertSelective" parameterType="cn.e3mall.pojo.TbItem" >
  119. insert into tb_item
  120. <trim prefix="(" suffix=")" suffixOverrides="," >
  121. <if test="id != null" >
  122. id,
  123. </if>
  124. <if test="title != null" >
  125. title,
  126. </if>
  127. <if test="sellPoint != null" >
  128. sell_point,
  129. </if>
  130. <if test="price != null" >
  131. price,
  132. </if>
  133. <if test="num != null" >
  134. num,
  135. </if>
  136. <if test="barcode != null" >
  137. barcode,
  138. </if>
  139. <if test="image != null" >
  140. image,
  141. </if>
  142. <if test="cid != null" >
  143. cid,
  144. </if>
  145. <if test="status != null" >
  146. status,
  147. </if>
  148. <if test="created != null" >
  149. created,
  150. </if>
  151. <if test="updated != null" >
  152. updated,
  153. </if>
  154. </trim>
  155. <trim prefix="values (" suffix=")" suffixOverrides="," >
  156. <if test="id != null" >
  157. #{id,jdbcType=BIGINT},
  158. </if>
  159. <if test="title != null" >
  160. #{title,jdbcType=VARCHAR},
  161. </if>
  162. <if test="sellPoint != null" >
  163. #{sellPoint,jdbcType=VARCHAR},
  164. </if>
  165. <if test="price != null" >
  166. #{price,jdbcType=BIGINT},
  167. </if>
  168. <if test="num != null" >
  169. #{num,jdbcType=INTEGER},
  170. </if>
  171. <if test="barcode != null" >
  172. #{barcode,jdbcType=VARCHAR},
  173. </if>
  174. <if test="image != null" >
  175. #{image,jdbcType=VARCHAR},
  176. </if>
  177. <if test="cid != null" >
  178. #{cid,jdbcType=BIGINT},
  179. </if>
  180. <if test="status != null" >
  181. #{status,jdbcType=TINYINT},
  182. </if>
  183. <if test="created != null" >
  184. #{created,jdbcType=TIMESTAMP},
  185. </if>
  186. <if test="updated != null" >
  187. #{updated,jdbcType=TIMESTAMP},
  188. </if>
  189. </trim>
  190. </insert>
  191. <select id="countByExample" parameterType="cn.e3mall.pojo.TbItemExample" resultType="java.lang.Integer" >
  192. select count(*) from tb_item
  193. <if test="_parameter != null" >
  194. <include refid="Example_Where_Clause" />
  195. </if>
  196. </select>
  197. <update id="updateByExampleSelective" parameterType="map" >
  198. update tb_item
  199. <set >
  200. <if test="record.id != null" >
  201. id = #{record.id,jdbcType=BIGINT},
  202. </if>
  203. <if test="record.title != null" >
  204. title = #{record.title,jdbcType=VARCHAR},
  205. </if>
  206. <if test="record.sellPoint != null" >
  207. sell_point = #{record.sellPoint,jdbcType=VARCHAR},
  208. </if>
  209. <if test="record.price != null" >
  210. price = #{record.price,jdbcType=BIGINT},
  211. </if>
  212. <if test="record.num != null" >
  213. num = #{record.num,jdbcType=INTEGER},
  214. </if>
  215. <if test="record.barcode != null" >
  216. barcode = #{record.barcode,jdbcType=VARCHAR},
  217. </if>
  218. <if test="record.image != null" >
  219. image = #{record.image,jdbcType=VARCHAR},
  220. </if>
  221. <if test="record.cid != null" >
  222. cid = #{record.cid,jdbcType=BIGINT},
  223. </if>
  224. <if test="record.status != null" >
  225. status = #{record.status,jdbcType=TINYINT},
  226. </if>
  227. <if test="record.created != null" >
  228. created = #{record.created,jdbcType=TIMESTAMP},
  229. </if>
  230. <if test="record.updated != null" >
  231. updated = #{record.updated,jdbcType=TIMESTAMP},
  232. </if>
  233. </set>
  234. <if test="_parameter != null" >
  235. <include refid="Update_By_Example_Where_Clause" />
  236. </if>
  237. </update>
  238. <update id="updateByExample" parameterType="map" >
  239. update tb_item
  240. set id = #{record.id,jdbcType=BIGINT},
  241. title = #{record.title,jdbcType=VARCHAR},
  242. sell_point = #{record.sellPoint,jdbcType=VARCHAR},
  243. price = #{record.price,jdbcType=BIGINT},
  244. num = #{record.num,jdbcType=INTEGER},
  245. barcode = #{record.barcode,jdbcType=VARCHAR},
  246. image = #{record.image,jdbcType=VARCHAR},
  247. cid = #{record.cid,jdbcType=BIGINT},
  248. status = #{record.status,jdbcType=TINYINT},
  249. created = #{record.created,jdbcType=TIMESTAMP},
  250. updated = #{record.updated,jdbcType=TIMESTAMP}
  251. <if test="_parameter != null" >
  252. <include refid="Update_By_Example_Where_Clause" />
  253. </if>
  254. </update>
  255. <update id="updateByPrimaryKeySelective" parameterType="cn.e3mall.pojo.TbItem" >
  256. update tb_item
  257. <set >
  258. <if test="title != null" >
  259. title = #{title,jdbcType=VARCHAR},
  260. </if>
  261. <if test="sellPoint != null" >
  262. sell_point = #{sellPoint,jdbcType=VARCHAR},
  263. </if>
  264. <if test="price != null" >
  265. price = #{price,jdbcType=BIGINT},
  266. </if>
  267. <if test="num != null" >
  268. num = #{num,jdbcType=INTEGER},
  269. </if>
  270. <if test="barcode != null" >
  271. barcode = #{barcode,jdbcType=VARCHAR},
  272. </if>
  273. <if test="image != null" >
  274. image = #{image,jdbcType=VARCHAR},
  275. </if>
  276. <if test="cid != null" >
  277. cid = #{cid,jdbcType=BIGINT},
  278. </if>
  279. <if test="status != null" >
  280. status = #{status,jdbcType=TINYINT},
  281. </if>
  282. <if test="created != null" >
  283. created = #{created,jdbcType=TIMESTAMP},
  284. </if>
  285. <if test="updated != null" >
  286. updated = #{updated,jdbcType=TIMESTAMP},
  287. </if>
  288. </set>
  289. where id = #{id,jdbcType=BIGINT}
  290. </update>
  291. <update id="updateByPrimaryKey" parameterType="cn.e3mall.pojo.TbItem" >
  292. update tb_item
  293. set title = #{title,jdbcType=VARCHAR},
  294. sell_point = #{sellPoint,jdbcType=VARCHAR},
  295. price = #{price,jdbcType=BIGINT},
  296. num = #{num,jdbcType=INTEGER},
  297. barcode = #{barcode,jdbcType=VARCHAR},
  298. image = #{image,jdbcType=VARCHAR},
  299. cid = #{cid,jdbcType=BIGINT},
  300. status = #{status,jdbcType=TINYINT},
  301. created = #{created,jdbcType=TIMESTAMP},
  302. updated = #{updated,jdbcType=TIMESTAMP}
  303. where id = #{id,jdbcType=BIGINT}
  304. </update>
  305. </mapper>

  

ItemService.class  接口

  1. package cn.e3mall.service;
  2.  
  3. import cn.e3mall.pojo.TbItem;
  4.  
  5. /**
  6. * 商品管理Service
  7. */
  8. public interface ItemService {
  9. /**
  10. * 根据商品id查询商品信息
  11. *
  12. * @param id
  13. * @return
  14. */
  15. public TbItem getItemByid(long id);
  16. }

  

ItemServiceImpl.class 实现类

  1. package cn.e3mall.service.impl;
  2. import cn.e3mall.service.ItemService;
  3. import cn.e3mall.mapper.TbItemMapper;
  4. import cn.e3mall.pojo.TbItem;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7.  
  8. /**
  9. * 商品管理Service
  10. */
  11. @Service
  12. class ItemServiceImpl implements ItemService {
  13.  
  14. @Autowired
  15. private TbItemMapper itemMapper;
  16.  
  17. /**
  18. * 根据id查询商品
  19. * @param id
  20. * @return
  21. */
  22. @Override
  23. public TbItem getItemByid(long id) {
  24. TbItem item = itemMapper.selectByPrimaryKey(id);
  25. return item;
  26. }
  27. }

ItemController.Class

  1. package cn.e3mall.controller;
  2.  
  3. import cn.e3mall.service.ItemService;
  4. import cn.e3mall.pojo.TbItem;
  5. import org.springframework.beans.factory.annotation.Autowired;
  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.ResponseBody;
  10.  
  11. /**
  12. * 商品管理Controller
  13. */
  14. @Controller
  15. public class ItemController {
  16. @Autowired
  17. private ItemService itemService;
  18.  
  19. @RequestMapping("/item/{itemId}")
  20. @ResponseBody
  21. public TbItem getItemById(@PathVariable Long itemId){
  22. System.out.println(itemId);
  23. TbItem item=itemService.getItemByid(itemId);
  24. System.out.println(item.toString());
  25. return item;
  26. }
  27. }

五、intellij maven工程运行

运行项目后,在控制台可以看到如下图所示。

去浏览器输入地址后可以看到项目运行成功。

【转载】使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化的更多相关文章

  1. 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

    一.创建一个空的项目作为存放整个项目的路径 1.选择 File——>new——>Project ——>Empty Project 2.WorkspaceforTest为项目存放文件夹 ...

  2. IDEA使用maven搭建SSM框架整合项目(超级详细,值得一看)

    目录 温馨提示 简单介绍下SSM 搭建过程 一.框架介绍 二.下载Maven 三.创建Maven项目 四.Maven工程需要引入的Jar 包 五.整合SSM框架.需要的相关配置文件配置项目 六.工程导 ...

  3. idea创建web聚合工程(2)

    参考文档: intelj idea 创建聚合项目(典型web项目,包括子项目util.dao.service) 使用IntelliJ IDEA创建Maven聚合工程.创建resources文件夹.ss ...

  4. Maven 聚合工程

    第一步: 创建Maven聚合工程: 父工程Maven工程的打包方式必须为pom 创建一个Maven工程 修改父工程的pom.xml,设置打包方式为pom <?xml version=" ...

  5. Maven 聚合工程的创建

    简单场景举例 聚合工程创建示例 说明: 创建 Maven Project:表示创建 maven 项目,new Project 方式创建 创建 Maven Module:表示创建 maven 项目,ne ...

  6. maven 聚合工程的创建和打包

    ---恢复内容开始--- 使用eclipse创建maven项目 第一步:创建父工程hg-parent,如图; 右击空白处,new创建新maven工程: 搜索maven项目 父工程使用pom打包方式 第 ...

  7. maven 聚合工程 用spring boot 搭建 spring cloud 微服务 模块式开发项目

    项目的简单介绍: 项目采用maven聚合工程 用spring boot 搭建 spring cloud的微服务 模块式开发 项目的截图: 搭建开始: 能上图 我少打字 1.首先搭建maven的聚合工程 ...

  8. Maven聚合工程的使用

    创建一个service模块 接下来,在该项目中创建一个接口 创建一个实现类,并实现接口 在sm1234-web项目中,调用service的方法,需要在该项目的pom.xml中引入依赖Service模块 ...

  9. 使用Eclipse创建Maven Web工程

    方法/步骤 1 使用Eclipse创建Maven Web工程 2 找到Maven Project,点击Next 3 勾选上Create a simple project (不使用骨架),Next 4 ...

随机推荐

  1. Eclipse导入外部项目问题总结

     此次在项目开发过程中导入从oksvn下载的共享项目时出现几个项目在不同的IDE导入导出时的问题,为免忘记做例如以下笔记: 1 类路径问题 在Java开发中大多数的开发人员使用的IDE是MyEcl ...

  2. LeetCode 171. Excel Sheet Column Number (Excel 表格列数字)

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

  3. 调用线程必须为 STA,因为许多 UI 组件都需要

    WPF中,代码中准备控制控件内容时,有时会报错: 调用线程必须为 STA,因为许多 UI 组件都需要 我知道,在winform下面,使用多线程时,控件的值读取是可以的,但如果要更改,那么就必须进行一些 ...

  4. [转]Dialog

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...

  5. 数组和字符串长度length

    数组.length 字符串.length() list list.size();map map.size();set set.size();1 java中的length属性是针对数组说的,比如说你声明 ...

  6. oracle查询时间段

    select count(*) tt from crm_cisco_call_detailwhere DateTime between to_date('2016-4-5 00:00:00','yyy ...

  7. [Swift通天遁地]八、媒体与动画-(10)在项目中播放GIF动画

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. day03_12/13/2016_bean的管理之初始化和销毁

  9. asp.net MVC 给Controler传一个JSon集合,后台通过List<Model>接收

    需求情景 View层经常需要通过Ajax像后台发送一个json对象的集合,但是在后台通过List<Model>无法接收,最后只能通过妥协的方式,在后台获取一个json的字符串,然后通过Js ...

  10. Java系列学习(一)-JDK下载与安装

    1.Java语言平台版本 J2SE:Java 2 Platform Standard Edition,java平台标准版 J2ME:Java 2 Platform Micro Edition,java ...