1、选择 File——>new——>Project ——>Empty Project
2、WorkspaceforTest为项目存放文件夹。
比如整个项目。以一个项目来演示。
|--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文件如下。
pom
3.4.2-fix
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
jar
13、创建manager工程,与common工程的方法一样。
File——>New——>module——>Maven
14、再在pom.xml下面添加
pom,如下图所示。
e3-common的 pom.xml文件
pom 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
jar
e3-manager-dao 的pom.xml
jar
e3-manager-interface 的pom.xml
jar
e3-manager-servicer 的pom.xml
jar
20、最后创建e3-manager-web工程,创建过程都与上面的四个过程一样。只是有一个地方需要注意,下面的截图会提示。
选中e3-manager——>右击鼠标——>New——Module,因为e3-manager-web是e3-manager的子工程。
只是下面需要注意一下。
21、再在pom.xml下面添加
war,如下图所示。
22、e3-manager-web的pom.xml文件
pom 8080 /
23、好了。到此maven聚合工程创建完成。
步骤:File——>Project Struture——>Modules——>maven工程,如果没有maven工程就点+号来添加
选择到创建resources文件夹的路径,比如图上的选择到main,右击鼠标,选择New Folder新建文件夹resources
再选择resources,右击鼠标选择Resources,可以看到resources文件夹的图标和之前不一样了,就是这样创建一个resources文件夹。再点Ok保存退出 。
很明图标都不一样了。
直接看项目路径,直接上代码,不懂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: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: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: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: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
contextConfigLocation classpath:spring/applicationContext-*.xml encoding utf-8 contextConfigLocation classpath:spring/springmvc.xml
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">
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; TbItemMapper.xml ItemService.class 接口 package cn.e3mall.service; ItemServiceImpl.class 实现类 package cn.e3mall.service.impl; ItemController.Class package cn.e3mall.controller; 运行项目后,在控制台可以看到如下图所示。 去浏览器输入地址后可以看到项目运行成功。
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
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);
}
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}
import cn.e3mall.pojo.TbItem;
/**
* 商品管理Service
*/
public interface ItemService {
/**
* 根据商品id查询商品信息
*
* @param id
* @return
*/
public TbItem getItemByid(long id);
}
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;
}
}
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工程运行