热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【转载】使用IntelliJIDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

 一、创建一个空的项目作为存放整个项目的路径1、选择File——new——Project——EmptyProject2、WorkspaceforTest为项目存放文件夹。  

 


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

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文件下添加

pom,e3-parent是打成pom文件的。

 

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


e3-parent的pom.xml


4.0.0
e3.mall
e3-parent
1.0-SNAPSHOT
e3-parent

pom


4.12
4.2.4.RELEASE
3.2.8
1.2.2
1.2.15
5.1.46
1.6.4
2.4.2
1.0.9
4.3.5
1.2
2.5
2.0
2.5
3.3.2
1.3.2
3.3

3.4.2-fix
0.9.1
1.3.1
2.7.2
4.10.3
2.5.3
3.4.7
0.1
5.11.2
2.3.23
2.2.2





joda-time
joda-time
${joda-time.version}



org.apache.commons
commons-lang3
${commons-lang3.version}


org.apache.commons
commons-io
${commons-io.version}


commons-net
commons-net
${commons-net.version}



com.fasterxml.jackson.core
jackson-databind
${jackson.version}



org.apache.httpcomponents
httpclient
${httpclient.version}



org.quartz-scheduler
quartz
${quartz.version}



junit
junit
${junit.version}
test



org.slf4j
slf4j-log4j12
${slf4j.version}



org.mybatis
mybatis
${mybatis.version}


org.mybatis
mybatis-spring
${mybatis.spring.version}


com.github.miemiedev
mybatis-paginator
${mybatis.paginator.version}


com.github.pagehelper
pagehelper
${pagehelper.version}



mysql
mysql-connector-java
${mysql.version}



com.alibaba
druid
${druid.version}



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


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


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


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


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


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


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



jstl
jstl
${jstl.version}


javax.servlet
servlet-api
${servlet-api.version}
provided


javax.servlet
jsp-api
${jsp-api.version}
provided



commons-fileupload
commons-fileupload
${commons-fileupload.version}



redis.clients
jedis
${jedis.version}



org.apache.solr
solr-solrj
${solrj.version}



com.alibaba
dubbo
${dubbo.version}


org.apache.zookeeper
zookeeper
${zookeeper.version}


com.github.sgroschupf
zkclient
${zkclient.version}


org.apache.activemq
activemq-all
${activemq.version}


org.freemarker
freemarker
${freemarker.version}




${project.artifactId}




org.apache.maven.plugins
maven-resources-plugin
2.7

UTF-8




org.apache.maven.plugins
maven-compiler-plugin
3.2

1.7
1.7
UTF-8







org.apache.tomcat.maven
tomcat7-maven-plugin
2.2





  

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下面添加

jar,如下图所示。

 

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

e3-common的 pom.xml



e3-parent
e3.mall
1.0-SNAPSHOT
../e3-parent/pom.xml

4.0.0
e3-common

jar
e3-common



joda-time
joda-time



org.apache.commons
commons-lang3


org.apache.commons
commons-io


commons-net
commons-net



com.fasterxml.jackson.core
jackson-databind



org.apache.httpcomponents
httpclient



org.quartz-scheduler
quartz



junit
junit
test



org.slf4j
slf4j-log4j12



  

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

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

 

 

 

 

 14、再在pom.xml下面添加

pom,如下图所示。

e3-common的 pom.xml文件

 



e3-parent
e3.mall
1.0-SNAPSHOT
../e3-parent/pom.xml

4.0.0
e3-manager

pom

e3-manager-pojo
e3-manager-dao
e3-manager-interface
e3-manager-service
e3-manager-web



e3-common
e3.mall
1.0-SNAPSHOT






org.apache.tomcat.maven
tomcat7-maven-plugin

8080

/





  

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下面添加

pom,如下图所示。

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



e3-manager
e3.mall
1.0-SNAPSHOT

4.0.0
e3-manager-pojo

jar
e3-manager-pojo

  

e3-manager-dao 的pom.xml



e3-manager
e3.mall
1.0-SNAPSHOT

4.0.0
e3-manager-dao

jar
e3-manager-dao


e3.mall
e3-manager-pojo
1.0-SNAPSHOT



org.mybatis
mybatis


org.mybatis
mybatis-spring


com.github.miemiedev
mybatis-paginator


com.github.pagehelper
pagehelper



mysql
mysql-connector-java



com.alibaba
druid






src/main/java

**/*.properties
**/*.xml

false




  

 e3-manager-interface 的pom.xml



e3-manager
e3.mall
1.0-SNAPSHOT

4.0.0
e3-manager-interface

jar
e3-manager-interface


e3.mall
e3-manager-pojo
1.0-SNAPSHOT



  

 e3-manager-servicer 的pom.xml



e3-manager
e3.mall
1.0-SNAPSHOT

4.0.0
e3-manager-service
e3-manager-service

jar


e3.mall
e3-manager-dao
1.0-SNAPSHOT


e3.mall
e3-manager-interface
1.0-SNAPSHOT




org.springframework
spring-context


org.springframework
spring-beans


org.springframework
spring-webmvc


org.springframework
spring-jdbc


org.springframework
spring-aspects


org.springframework
spring-jms


org.springframework
spring-context-support



  

 

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

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

只是下面需要注意一下。

 21、再在pom.xml下面添加

war,如下图所示。

 

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



e3-parent
e3.mall
1.0-SNAPSHOT
../e3-parent/pom.xml

4.0.0
e3-manager

pom

e3-manager-pojo
e3-manager-dao
e3-manager-interface
e3-manager-service
e3-manager-web



e3-common
e3.mall
1.0-SNAPSHOT






org.apache.tomcat.maven
tomcat7-maven-plugin

8080

/





  

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

 


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

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

 

 

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

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

 

 很明图标都不一样了。


四、整合ssm框架

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

 

SqlMapConfig.xml


PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">


  

db.properties

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

  

applicationContext-Dao.xml


xmlns:cOntext="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
























  

applicationContext-service.xml


xmlns:cOntext="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">


  

applicationContext-trans.xml


xmlns:cOntext="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
























  

springmvc.xml


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:cOntext="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">










  

web.xml


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">
e3-manager

index.jsp




contextConfigLocation

classpath:spring/applicationContext-*.xml


org.springframework.web.context.ContextLoaderListener



CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8



CharacterEncodingFilter
/*



e3-manager
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/springmvc.xml

1


e3-manager
/


  

 TbItem.class

package cn.e3mall.pojo;
import java.util.Date;
public class TbItem {
private Long id;
private String title;
private String sellPoint;
private Long price;
private Integer num;
private String barcode;
private String image;
private Long cid;
private Byte status;
private Date created;
private Date updated;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
public String getSellPoint() {
return sellPoint;
}
public void setSellPoint(String sellPoint) {
this.sellPoint = sellPoint == null ? null : sellPoint.trim();
}
public Long getPrice() {
return price;
}
public void setPrice(Long price) {
this.price = price;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode == null ? null : barcode.trim();
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image == null ? null : image.trim();
}
public Long getCid() {
return cid;
}
public void setCid(Long cid) {
this.cid = cid;
}
public Byte getStatus() {
return status;
}
public void setStatus(Byte status) {
this.status = status;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
}

  

TbItemMapper.class  接口

package cn.e3mall.mapper;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.pojo.TbItemExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TbItemMapper {
int countByExample(TbItemExample example);
int deleteByExample(TbItemExample example);
int deleteByPrimaryKey(Long id);
int insert(TbItem record);
int insertSelective(TbItem record);
List selectByExample(TbItemExample example);
TbItem selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") TbItem record, @Param("example") TbItemExample example);
int updateByExample(@Param("record") TbItem record, @Param("example") TbItemExample example);
int updateByPrimaryKeySelective(TbItem record);
int updateByPrimaryKey(TbItem record);
}

  

TbItemMapper.xml

























and ${criterion.condition}


and ${criterion.condition} #{criterion.value}


and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}


and ${criterion.condition}

#{listItem}

















and ${criterion.condition}


and ${criterion.condition} #{criterion.value}


and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}


and ${criterion.condition}

#{listItem}










id, title, sell_point, price, num, barcode, image, cid, status, created, updated




delete from tb_item
where id = #{id,jdbcType=BIGINT}


delete from tb_item





insert into tb_item (id, title, sell_point,
price, num, barcode,
image, cid, status,
created, updated)
values (#{id,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{sellPoint,jdbcType=VARCHAR},
#{price,jdbcType=BIGINT}, #{num,jdbcType=INTEGER}, #{barcode,jdbcType=VARCHAR},
#{image,jdbcType=VARCHAR}, #{cid,jdbcType=BIGINT}, #{status,jdbcType=TINYINT},
#{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})


insert into tb_item


id,


title,


sell_point,


price,


num,


barcode,


image,


cid,


status,


created,


updated,




#{id,jdbcType=BIGINT},


#{title,jdbcType=VARCHAR},


#{sellPoint,jdbcType=VARCHAR},


#{price,jdbcType=BIGINT},


#{num,jdbcType=INTEGER},


#{barcode,jdbcType=VARCHAR},


#{image,jdbcType=VARCHAR},


#{cid,jdbcType=BIGINT},


#{status,jdbcType=TINYINT},


#{created,jdbcType=TIMESTAMP},


#{updated,jdbcType=TIMESTAMP},





update tb_item


id = #{record.id,jdbcType=BIGINT},


title = #{record.title,jdbcType=VARCHAR},


sell_point = #{record.sellPoint,jdbcType=VARCHAR},


price = #{record.price,jdbcType=BIGINT},


num = #{record.num,jdbcType=INTEGER},


barcode = #{record.barcode,jdbcType=VARCHAR},


image = #{record.image,jdbcType=VARCHAR},


cid = #{record.cid,jdbcType=BIGINT},


status = #{record.status,jdbcType=TINYINT},


created = #{record.created,jdbcType=TIMESTAMP},


updated = #{record.updated,jdbcType=TIMESTAMP},







update tb_item
set id = #{record.id,jdbcType=BIGINT},
title = #{record.title,jdbcType=VARCHAR},
sell_point = #{record.sellPoint,jdbcType=VARCHAR},
price = #{record.price,jdbcType=BIGINT},
num = #{record.num,jdbcType=INTEGER},
barcode = #{record.barcode,jdbcType=VARCHAR},
image = #{record.image,jdbcType=VARCHAR},
cid = #{record.cid,jdbcType=BIGINT},
status = #{record.status,jdbcType=TINYINT},
created = #{record.created,jdbcType=TIMESTAMP},
updated = #{record.updated,jdbcType=TIMESTAMP}





update tb_item


title = #{title,jdbcType=VARCHAR},


sell_point = #{sellPoint,jdbcType=VARCHAR},


price = #{price,jdbcType=BIGINT},


num = #{num,jdbcType=INTEGER},


barcode = #{barcode,jdbcType=VARCHAR},


image = #{image,jdbcType=VARCHAR},


cid = #{cid,jdbcType=BIGINT},


status = #{status,jdbcType=TINYINT},


created = #{created,jdbcType=TIMESTAMP},


updated = #{updated,jdbcType=TIMESTAMP},


where id = #{id,jdbcType=BIGINT}


update tb_item
set title = #{title,jdbcType=VARCHAR},
sell_point = #{sellPoint,jdbcType=VARCHAR},
price = #{price,jdbcType=BIGINT},
num = #{num,jdbcType=INTEGER},
barcode = #{barcode,jdbcType=VARCHAR},
image = #{image,jdbcType=VARCHAR},
cid = #{cid,jdbcType=BIGINT},
status = #{status,jdbcType=TINYINT},
created = #{created,jdbcType=TIMESTAMP},
updated = #{updated,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}


  

ItemService.class  接口

package cn.e3mall.service;
import cn.e3mall.pojo.TbItem;
/**
* 商品管理Service
*/
public interface ItemService {
/**
* 根据商品id查询商品信息
*
* @param id
* @return
*/
public TbItem getItemByid(long id);
}

  

ItemServiceImpl.class 实现类

package cn.e3mall.service.impl;
import cn.e3mall.service.ItemService;
import cn.e3mall.mapper.TbItemMapper;
import cn.e3mall.pojo.TbItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 商品管理Service
*/
@Service
class ItemServiceImpl implements ItemService {
@Autowired
private TbItemMapper itemMapper;
/**
* 根据id查询商品
* @param id
* @return
*/
@Override
public TbItem getItemByid(long id) {
TbItem item = itemMapper.selectByPrimaryKey(id);
return item;
}
}

 

ItemController.Class

package cn.e3mall.controller;
import cn.e3mall.service.ItemService;
import cn.e3mall.pojo.TbItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 商品管理Controller
*/
@Controller
public class ItemController {
@Autowired
private ItemService itemService;
@RequestMapping("/item/{itemId}")
@ResponseBody
public TbItem getItemById(@PathVariable Long itemId){
System.out.println(itemId);
TbItem item=itemService.getItemByid(itemId);
System.out.println(item.toString());
return item;
}
}

 


五、intellij maven工程运行

 

 

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

 

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


推荐阅读
author-avatar
政凯雅惠1663
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有