淘淘商城项目mysql服务器_SpringMVC+Spring+Mybatis+Mysql+Maven+Svn[ 淘淘商城项目环境搭建 ]...

背景:淘淘商城项目的环境搭建

说明:采用SpringMVC+Spring+Mybatis+Mysql+Maven+Svn结构搭建,在开发之中可以参考其结构和搭建步骤去搭建实际的工程项目

工程结构简图:

1b820386cbb945b1b72b38be8c2d5a8c.png

项目结构:

fcb36e5537cff2cb408663d4cb657577.png

b0656e5cbcef2ef63720f4981be30ff5.png

722db3b49966dcac1107346996fc3564.png

d1d7820fe8c38498b412d71c7fa8bf74.png

b6027b4575898865a518770124f8772a.png

c48a549b968a6c65b2f31482fde35ac9.png

---------------------------------------------【 以下是项目的搭建过程 】----------------------------------------------------

创建数据库:

taotao-parent:

这是父工程,其他子工程都要继承它,是个POM聚合工程,这里集中定义了jar包的版本号,但并不是实际依赖,其子工程的版本要从这里依赖传递,便于维护。

File--New--Maven--Maven Project

d6f6f7272c4faa72c98a43271255d0f7.png

a603cab1b66273930e9ed02d048fb59c.png

Next--Finish

修改pom.xml:

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

4.0.0

com.taotao

taotao-parent

0.0.1-SNAPSHOT

pom

4.12

4.1.3.RELEASE

3.2.8

1.2.2

1.2.15

5.1.32

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

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}

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}

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}

${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

taotao-common:

同理创建taotao-common,这个工程是工具工程,提供通用的工具类,是个jar工程,此工程要继承父工程taotao-parent

修改pom.xml:

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

4.0.0

com.taotao

taotao-parent

0.0.1-SNAPSHOT

com.taotao

taotao-common

0.0.1-SNAPSHOT

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

junit

junit

test

org.slf4j

slf4j-log4j12

com.jcraft

jsch

0.1.49

taotao-manager:

这是个POM聚合工程,包括controller/service/mapper工程,此工程要继承父工程taotao-parent,同时要依赖taotao-common工具工程

修改pom.xml:

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

4.0.0

com.taotao

taotao-parent

0.0.1-SNAPSHOT

com.taotao

taotao-manager

0.0.1-SNAPSHOT

pom

com.taotao

taotao-common

0.0.1-SNAPSHOT

taotao-manager-pojo

taotao-manager-mapper

taotao-manager-service

taotao-manager-web

org.apache.tomcat.maven

tomcat7-maven-plugin

8080

/

taotao-manager-pojo:

这是POJO,是个jar工程,不依赖于任何模块

在taotao-manager工程上右键,New--Other--Maven Module--Next--Finish

c40950a5f4f8ae1a79f5d530a7aa024d.png

pom.xml:无需修改

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

4.0.0

com.taotao

taotao-manager

0.0.1-SNAPSHOT

com.taotao

taotao-manager-pojo

0.0.1-SNAPSHOT

在src/main/java目录下,创建package:com.taotao.pojo,使用逆向工程生成POJO类和Mapper接口以及Mapper映射文件,将所有POJO类拷贝到这个package下

taotao-manager-mapper:

同理创建taotao-manager-mapper,这是jar工程,是mapper层,依赖pojo,和数据库交互,在src/main/java下创建package:com.taotao.mapper,

将逆向工程生成的Mapper接口和Mapper映射文件拷贝至这个package下

修改pom.xml:

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

4.0.0

com.taotao

taotao-manager

0.0.1-SNAPSHOT

com.taotao

taotao-manager-mapper

0.0.1-SNAPSHOT

com.taotao

taotao-manager-pojo

0.0.1-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

taotao-manager-service

同理创建taotao-manager-service,这是jar工程,是service层,调用mapper层

修改pom.xml:

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

4.0.0

com.taotao

taotao-manager

0.0.1-SNAPSHOT

com.taotao

taotao-manager-service

0.0.1-SNAPSHOT

com.taotao

taotao-manager-mapper

0.0.1-SNAPSHOT

org.springframework

spring-context

org.springframework

spring-beans

org.springframework

spring-webmvc

org.springframework

spring-jdbc

org.springframework

spring-aspects

在src/main/java目录下创建package:com.taotao.service以及com.taotao.service.impl

taotao-manager-web:

同理创建taotao-manager-web,这是表现层Controller,是个war工程,调用service工程

修改pom.xml:

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

4.0.0

com.taotao

taotao-manager

0.0.1-SNAPSHOT

com.taotao

taotao-manager-web

0.0.1-SNAPSHOT

war

com.taotao

taotao-manager-service

0.0.1-SNAPSHOT

jstl

jstl

javax.servlet

servlet-api

provided

javax.servlet

jsp-api

provided

commons-fileupload

commons-fileupload

以下步骤在开发之中根据实际情况调整, 可以先搭建好环境之后再开发controller(service层也一样)

在src/main/resources目录下创建三个fold:mybatis、resource、spring

在resource下创建db.properties:

jdbc.driver = com.mysql.jdbc.Driver

jdbc.url = jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=utf-8

jdbc.username = 数据库账号

jdbc.password =数据库密码

在mybatis下创建SqlMapConfig.xml:(这个文件虽然暂时没有写入什么东西,但是要有这个文件,否则工程结构不完整,就会报错)

/p>

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

在spring下创建各个整合的配置文件:

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.0.xsd

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

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

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

destroy-method="close">

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.0.xsd

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

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.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.0.xsd

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

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

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

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

pointcut="execution(* com.taotao.service.*.*(..))" />

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.xsd

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

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

在webapp下创建WEB-INF目录,其下创建web.xml,并把一些静态资源文件和页面(css/js/jsp)拷贝到WEB-INF下

web.xml:

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

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

id="taotao" version="2.5">

taotao-manager

index.html

index.htm

index.jsp

default.html

default.htm

default.jsp

contextConfigLocation

classpath:spring/applicationContext-*.xml

org.springframework.web.context.ContextLoaderListener

CharacterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

CharacterEncodingFilter

/*

taotao-manager

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring/springmvc.xml

1

taotao-manager

/

在webapp下创建index.jsp:

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>

首页测试

尊敬的用户,如果您看到此页面,说明taotao-manager正在运行...

到此为止,整个工程的环境已经搭建完毕,可以做测试(在实际开发中要步步为营,每次搭建完一个模块就要做一次测试):

beb59a39f413820acae1676844735ecc.png

将各个工程及其继承的工程按顺序install到本地仓库,然后启动在taotao-manager工程上右键Run As--Maven Build,输入clean tomcat7:run,运行

如果测试通过,就将项目提交到svn上,这样,其他组员就可以从svn上检出项目进行开发

-------------------------------------------以下是将项目提交到svn已经从svn检出项目的步骤-------------------------------------------------------

提交到svn的顺序:taotao-parent, taotao-common, taotao-manager(其子工程不需要提交,因为父工程已经包含其子工程),

以taotao-parent为例,其他同理:

右键taotao-parent--Team--Share Project...--SVN--Next--创建新的资源库位置(第一个工程选这个,后面的工程选择“使用已有资源库位置”),

打开VisualSVN Server Manager,在Repositories下右键选择Create New Repository...,为这个项目的仓库取个名字(如taotao-shop),下一步,Create

8385af0a3d35b92ed9a1c4d28f1dc0c3.png

就可以创建一个项目的本地仓库,包含三个文件夹:branches,tags,trunk(这个目录用于存放java代码),

右键刚刚创建的仓库,选择Copy URL to Clipboard,将仓库的URL复制,粘贴到以下的URL文本框中:

2aaa394c0f5c52b53fb23c3d5dab5961.png

Next

8b50ce14bf4bc13810e577af94437459.png

点击“浏览”--路径指向项目仓库的trunk目录,按提示操作,Finish即可,至此,项目并没有真正地上传到svn上,只是建立了项目和svn的关系。

把除了src及其子目录、pom.xml之外的文件全部 ignore 掉(如果把target/.property/.setting等文件也上传到svn,那么其他人从svn上down下来的项目可能会覆盖掉他自己本地的文件,这些文件都是个性化的文件,不要上传到svn!),有些可能要按照顺序操作,具体请百度,然后提交到svn,如果冲突就先更新再提交,

其他的项目一样操作。

这样项目就全部提交到svn上了, 建议本地的项目(就是您看到的myeclipse中的所有项目)全部都删除(删除的时候把本地磁盘的选项也勾上,表示把磁盘上的也删除),然后从svn上把项目都down下来,下载顺序:taotao-parent---taotao-common---taotao-manager(这是聚合工程),然后你会发现taotao-manager下的子工程都没有,右键taotao-manager这个聚合工程--Import--Maven--Existing Maven Projects--Next

d2557643ceb46213635920adee27a8fd.png

路径指向聚合工程taotao-manager的目录,就会自动将其子工程列出来,全选,Next,Finish,就会把所有的子工程都导入进来,你会发现taotao-parent, taotao-common, taotao-manager这三个工程都不是Maven工程,需要将其一 一转成Maven工程,步骤请参考以下链接:

http://www.cnblogs.com/josephcnblog/articles/6616563.html

将项目都转成maven工程之后,至此,整个项目的就搭建完毕!可以进行其他功能的开发了

------------------------------------------以下是一个小demo的开发步骤,其他业务模块一样操作--------------------------------------------------

在com.taotao.service下创建Service接口:ItemService.java

package com.taotao.service;

import com.taotao.pojo.TbItem;

/**

* 商品Service

*/

public interface ItemService {

TbItem getItemById(long itemId);

}

在com.taotao.service.impl下创建Service接口实现类:ItemServiceImpl.java

package com.taotao.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.taotao.mapper.TbItemMapper;

import com.taotao.pojo.TbItem;

import com.taotao.service.ItemService;

/**

* 商品Service实现类

*/

@Service

public class ItemServiceImpl implements ItemService {

// 注入ItemMapper

@Autowired

private TbItemMapper itemMapper;

/**

* 根据商品Id查询商品对象

*/

@Override

public TbItem getItemById(long itemId) {

TbItem item = itemMapper.selectByPrimaryKey(itemId);

return item;

}

}

在src/main/java目录下创建package:com.taotao.controller,在此package下创建ItemController.java

package com.taotao.controller;

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;

import com.taotao.pojo.TbItem;

import com.taotao.service.ItemService;

/**

* 商品Controller

*/

@Controller

@RequestMapping("/item")

public class ItemController {

// 注入ItemService

@Autowired

private ItemService itemService;

@RequestMapping("/{itemId}")

@ResponseBody

public TbItem getItemById(@PathVariable Long itemId) {

TbItem item = itemService.getItemById(itemId);

return item;

}

}

下面是测试,右键taotao-manager--Run As--Maven Build,启动tomcat之后,在浏览器地址栏输入http://localhost:8080/item/536563

其中, 后面的数字是要查询的商品的 id , 回车:

aa2b628e8bcc866235c3d229dde7da77.png

返回json格式数据, 测试通过!

继续开发其他的业务模块吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值