日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發(fā)布時(shí)間:2023/12/10 数据库 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 淘淘商城项目mysql服务器_SpringMVC+Spring+Mybatis+Mysql+Maven+Svn[ 淘淘商城项目环境搭建 ]... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

背景:淘淘商城項(xiàng)目的環(huán)境搭建

說明:采用SpringMVC+Spring+Mybatis+Mysql+Maven+Svn結(jié)構(gòu)搭建,在開發(fā)之中可以參考其結(jié)構(gòu)和搭建步驟去搭建實(shí)際的工程項(xiàng)目

工程結(jié)構(gòu)簡圖:

項(xiàng)目結(jié)構(gòu):

---------------------------------------------【 以下是項(xiàng)目的搭建過程 】----------------------------------------------------

創(chuàng)建數(shù)據(jù)庫:

taotao-parent:

這是父工程,其他子工程都要繼承它,是個(gè)POM聚合工程,這里集中定義了jar包的版本號(hào),但并不是實(shí)際依賴,其子工程的版本要從這里依賴傳遞,便于維護(hù)。

File--New--Maven--Maven Project

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:

同理創(chuàng)建taotao-common,這個(gè)工程是工具工程,提供通用的工具類,是個(gè)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:

這是個(gè)POM聚合工程,包括controller/service/mapper工程,此工程要繼承父工程taotao-parent,同時(shí)要依賴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,是個(gè)jar工程,不依賴于任何模塊

在taotao-manager工程上右鍵,New--Other--Maven Module--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-manager

0.0.1-SNAPSHOT

com.taotao

taotao-manager-pojo

0.0.1-SNAPSHOT

在src/main/java目錄下,創(chuàng)建package:com.taotao.pojo,使用逆向工程生成POJO類和Mapper接口以及Mapper映射文件,將所有POJO類拷貝到這個(gè)package下

taotao-manager-mapper:

同理創(chuàng)建taotao-manager-mapper,這是jar工程,是mapper層,依賴pojo,和數(shù)據(jù)庫交互,在src/main/java下創(chuàng)建package:com.taotao.mapper,

將逆向工程生成的Mapper接口和Mapper映射文件拷貝至這個(gè)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

同理創(chuàng)建taotao-manager-service,這是jar工程,是service層,調(diào)用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目錄下創(chuàng)建package:com.taotao.service以及com.taotao.service.impl

taotao-manager-web:

同理創(chuàng)建taotao-manager-web,這是表現(xiàn)層Controller,是個(gè)war工程,調(diào)用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

以下步驟在開發(fā)之中根據(jù)實(shí)際情況調(diào)整, 可以先搭建好環(huán)境之后再開發(fā)controller(service層也一樣)

在src/main/resources目錄下創(chuàng)建三個(gè)fold:mybatis、resource、spring

在resource下創(chuàng)建db.properties:

jdbc.driver = com.mysql.jdbc.Driver

jdbc.url = jdbc:mysql://localhost:3306/數(shù)據(jù)庫名?useUnicode=true&characterEncoding=utf-8

jdbc.username = 數(shù)據(jù)庫賬號(hào)

jdbc.password =數(shù)據(jù)庫密碼

在mybatis下創(chuàng)建SqlMapConfig.xml:(這個(gè)文件雖然暫時(shí)沒有寫入什么東西,但是要有這個(gè)文件,否則工程結(jié)構(gòu)不完整,就會(huì)報(bào)錯(cuò))

/p>

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

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

在spring下創(chuàng)建各個(gè)整合的配置文件:

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下創(chuàng)建WEB-INF目錄,其下創(chuàng)建web.xml,并把一些靜態(tài)資源文件和頁面(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下創(chuàng)建index.jsp:

String path = request.getContextPath();

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

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

+ path + "/";

%>

首頁測試

尊敬的用戶,如果您看到此頁面,說明taotao-manager正在運(yùn)行...

到此為止,整個(gè)工程的環(huán)境已經(jīng)搭建完畢,可以做測試(在實(shí)際開發(fā)中要步步為營,每次搭建完一個(gè)模塊就要做一次測試):

將各個(gè)工程及其繼承的工程按順序install到本地倉庫,然后啟動(dòng)在taotao-manager工程上右鍵Run As--Maven Build,輸入clean tomcat7:run,運(yùn)行

如果測試通過,就將項(xiàng)目提交到svn上,這樣,其他組員就可以從svn上檢出項(xiàng)目進(jìn)行開發(fā)

-------------------------------------------以下是將項(xiàng)目提交到svn已經(jīng)從svn檢出項(xiàng)目的步驟-------------------------------------------------------

提交到svn的順序:taotao-parent, taotao-common, taotao-manager(其子工程不需要提交,因?yàn)楦腹こ桃呀?jīng)包含其子工程),

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

右鍵taotao-parent--Team--Share Project...--SVN--Next--創(chuàng)建新的資源庫位置(第一個(gè)工程選這個(gè),后面的工程選擇“使用已有資源庫位置”),

打開VisualSVN Server Manager,在Repositories下右鍵選擇Create New Repository...,為這個(gè)項(xiàng)目的倉庫取個(gè)名字(如taotao-shop),下一步,Create

就可以創(chuàng)建一個(gè)項(xiàng)目的本地倉庫,包含三個(gè)文件夾:branches,tags,trunk(這個(gè)目錄用于存放java代碼),

右鍵剛剛創(chuàng)建的倉庫,選擇Copy URL to Clipboard,將倉庫的URL復(fù)制,粘貼到以下的URL文本框中:

Next

點(diǎn)擊“瀏覽”--路徑指向項(xiàng)目倉庫的trunk目錄,按提示操作,Finish即可,至此,項(xiàng)目并沒有真正地上傳到svn上,只是建立了項(xiàng)目和svn的關(guān)系。

把除了src及其子目錄、pom.xml之外的文件全部 ignore 掉(如果把target/.property/.setting等文件也上傳到svn,那么其他人從svn上down下來的項(xiàng)目可能會(huì)覆蓋掉他自己本地的文件,這些文件都是個(gè)性化的文件,不要上傳到svn!),有些可能要按照順序操作,具體請(qǐng)百度,然后提交到svn,如果沖突就先更新再提交,

其他的項(xiàng)目一樣操作。

這樣項(xiàng)目就全部提交到svn上了, 建議本地的項(xiàng)目(就是您看到的myeclipse中的所有項(xiàng)目)全部都刪除(刪除的時(shí)候把本地磁盤的選項(xiàng)也勾上,表示把磁盤上的也刪除),然后從svn上把項(xiàng)目都down下來,下載順序:taotao-parent---taotao-common---taotao-manager(這是聚合工程),然后你會(huì)發(fā)現(xiàn)taotao-manager下的子工程都沒有,右鍵taotao-manager這個(gè)聚合工程--Import--Maven--Existing Maven Projects--Next

路徑指向聚合工程taotao-manager的目錄,就會(huì)自動(dòng)將其子工程列出來,全選,Next,Finish,就會(huì)把所有的子工程都導(dǎo)入進(jìn)來,你會(huì)發(fā)現(xiàn)taotao-parent, taotao-common, taotao-manager這三個(gè)工程都不是Maven工程,需要將其一 一轉(zhuǎn)成Maven工程,步驟請(qǐng)參考以下鏈接:

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

將項(xiàng)目都轉(zhuǎn)成maven工程之后,至此,整個(gè)項(xiàng)目的就搭建完畢!可以進(jìn)行其他功能的開發(fā)了

------------------------------------------以下是一個(gè)小demo的開發(fā)步驟,其他業(yè)務(wù)模塊一樣操作--------------------------------------------------

在com.taotao.service下創(chuàng)建Service接口:ItemService.java

package com.taotao.service;

import com.taotao.pojo.TbItem;

/**

* 商品Service

*/

public interface ItemService {

TbItem getItemById(long itemId);

}

在com.taotao.service.impl下創(chuàng)建Service接口實(shí)現(xiàn)類: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實(shí)現(xiàn)類

*/

@Service

public class ItemServiceImpl implements ItemService {

// 注入ItemMapper

@Autowired

private TbItemMapper itemMapper;

/**

* 根據(jù)商品Id查詢商品對(duì)象

*/

@Override

public TbItem getItemById(long itemId) {

TbItem item = itemMapper.selectByPrimaryKey(itemId);

return item;

}

}

在src/main/java目錄下創(chuàng)建package:com.taotao.controller,在此package下創(chuàng)建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,啟動(dòng)tomcat之后,在瀏覽器地址欄輸入http://localhost:8080/item/536563

其中, 后面的數(shù)字是要查詢的商品的 id , 回車:

返回json格式數(shù)據(jù), 測試通過!

繼續(xù)開發(fā)其他的業(yè)務(wù)模塊吧!

總結(jié)

以上是生活随笔為你收集整理的淘淘商城项目mysql服务器_SpringMVC+Spring+Mybatis+Mysql+Maven+Svn[ 淘淘商城项目环境搭建 ]...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。