分佈式:html
按照功能點把系統拆分紅獨立的功能,單獨爲某一結點添加服務器.
例如:訂單系統須要兩臺 而單點登陸系統須要10臺...
複製代碼
SOA:前端
面向服務的架構 ,是把業務層和服務層拆分,而不是根據功能拆分
複製代碼
後臺工程搭建java
用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
**須要在manager的pom裏面設置tomcat ,而後訪問local:host:8080
複製代碼
逆向工程建立表node
mapper放到dao
pojo放到pojo
複製代碼
ssm整合mysql
1.dao層
mybatis的配置文件:SqlMapConfig.xml
不須要配置任何內容,須要有文件頭,文件必須存在
applicationContext-dao.xml(spring配置文件)
mybatis整合spring,經過spring管理SqlSessionFactory mapper代理對象,須要mybatis
和spring 的整合包
2.service層:
applicationContext-service.xml:
全部的service實現類都放在spring容器中管理,並有spring管理事務
3.表現層
Springmvc框架,由springmvc管理controller
springmvc的三大組件
作法:在e3-manager-web下面recouces中建立
conf:db.properties
mybatis:SqlMapConfig.xml
spring:applicationContext-dao.xml 管理dao層數據
applicationContext-service.xml管理service層數據
applicationContext-trans.xml 管理trans層數據
整合測試
svn:建新庫java-EE32
複製代碼
SOA:沒學過.linux
!!maven 的tomcat插件使用會報錯!!nginx
解決了一部分:在pom裏面加了一個...true...git
svn沒學過程序員
把工程改成soa框架github
因爲宜立方商城是基於soa的架構,表現層和服務層是不一樣的工程。因此要實現商品列表查詢須要兩個系統之間進行通訊。
如何實現遠程通訊?
一、Webservice:效率不高基於soap協議。項目中不推薦使用。
二、使用restful形式的服務:http+json。不少項目中應用。若是服務太多,服務之間調用關係混亂,須要治療服務。
三、使用dubbo。使用rpc協議進行遠程調用,直接使用socket通訊。傳輸效率高,而且能夠統計出系統之間的調用關係、調用次數。
複製代碼
Zookeeper:
要先把zookeeper啓動,而後開啓linux中的tomcat,再而後開啓eclipce中的manager manager-web 的clean tomcat7:run
開啓pagehelper
1.先把pageHelper工程導進來
2.在manager-servic 中的sqlMapCOnfig中配置plugin
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 設置數據庫類型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種數據庫-->
<property name="dialect" value="mysql"/>
3.新建pageHelper類(test中)
在interface中的ItemService中定義EasyUIDataGridResult接口
在service 中的ItemService中實現類
表現層:在web中的COntroller中調用
複製代碼
對於dubbo不熟悉,須要瞭解
複製代碼
準備工做
先開虛擬機 開啓zookeeper,而後啓動manager ,manager-web cd zookeeper-3.4.6/bin ./zkServer.sh start
1. 商品類目選擇
**實現層:**
- [ ] 先在common的pojo中創建EasyUITreeNode,id text state屬性 get/set
- [ ] 而後在interface中聲明ItemCatSerice接口
- [ ] 在service中創建ItemCatServiceImpl實現類繼承上述接口
``` java
@Autowired
private TbItemCatMapper ItemCatMapper;
@Override
public List<EasyUITreeNode> getItemCatlist(long parentId) {
//根據parentId查詢子節點列表
TbItemCatExample example=new TbItemCatExample();
Criteria criteria = example.createCriteria();
//設置查詢條件
criteria.andParentIdEqualTo(parentId);
//執行查詢
List<TbItemCat> list = ItemCatMapper.selectByExample(example);
//建立返回結果List
List<EasyUITreeNode> resultList=new ArrayList<>();
//把列表轉換成EasyUITreeoce列表
for (TbItemCat tbItemCat : list) {
EasyUITreeNode node=new EasyUITreeNode();
//設置屬性
node.setId(tbItemCat.getId());
node.setText(tbItemCat.getName());
node.setState(tbItemCat.getIsParent()?"closed":"open");
//添加到結果列表
resultList.add(node);
}
return resultList;
}
```
- [ ] 而後再service.xml中暴露服務 <dubbo:serviceinterface="cn.e3mall.service.ItemCatService" ref="itemCatServiceImpl" timeout="600000"/>
**表現層:**
- [ ] 在web中創建ItemCatController
``` java
-@Autowired
private ItemCatService itemCatService;
@RequestMapping("/item/cat/list")
@ResponseBody
public List<EasyUITreeNode> getItemCatList(
@RequestParam(name="id",defaultValue="0")Long parentId){
//調用服務查詢節點列表
List<EasyUITreeNode> list = itemCatService.getItemCatlist(parentId);
return list;
```
- [ ] 而後在web的springmvc中引用dubbo服務
<dubbo:reference interface="cn.e3mall.service.ItemCatService" id="itemCatService" />
複製代碼
2.Nginx: 是一款高性能的http服務器/反向代理服務器以及電子郵件代理服務器
linux開啓nginx:cd /usr/local/ 而後cd nginx 開啓sbin/nginx 關閉 sbin/nginx -s quit 刷新 sbin/nginx -s reload 查詢是否開啓-aux|grep nginx 修改域名端口.. cd /usr/local/ cd nginx vim nginx.conf,在裏面改域名和端口
反向代理: 我有兩個網站天貓 淘寶,只有一個公用ip,爲了節約成本,一個域名只能綁定一個ip 而後兩個分別部署到兩個tomcat中,而後服務端到nginx中,由它來決定到哪一個服務器 經過一個nginx做爲入口,根據不一樣的請求轉發到不一樣的地方
負載均衡: 在upstream中加一個server ip地址:端口號; 兩臺服務器用同一個網址時一人一次 (例如訪問www.sina.com時index.html每人一次,若是IAOweight則是按權重分配) 實現高可用:(瞭解)
圖片服務器的安裝
首先得把虛擬機的網絡編輯器改爲192.168.25.0(而後能夠改回來) 而後開啓這個圖片服務器,導入這個測試的工程,install後在web中加入這個工程做爲jar包,而後在web中作一個測試方法便可(或者直接工具類) 而後192.168.25.133/group1/.....訪問便可
kindEditor
返回格式(json)
圖片上傳功能實現
在pom.xml中把文件上傳組件粘貼到web pom中 在controller中寫程序代碼,在springmvc裏面掃描conf/recource.properties中的圖片服務器ip地址 或者直接用
@Value("${IMAGE_SERVER_URL}")
private String IMAGE_SERVER_URL;
@RequestMapping(value="/pic/upload",produces=MediaType.TEXT_PLAIN_VALUE+";charset=utf-8")
@ResponseBody
public String uploadFile(MultipartFile uploadFile) {
try {
// 把圖片上傳導圖片服務器
FastDFSClient fastDFSClient = new FastDFSClient("classpath:conf/client.conf");
//取文件擴展名
String originalString =uploadFile.getOriginalFilename();
String extName=originalString.substring(originalString.lastIndexOf(".")+1);
// 獲得一個圖片的地址和文件名
String url=fastDFSClient.uploadFile(uploadFile.getBytes(), extName);
// 補充爲完整的url
url=IMAGE_SERVER_URL+url;
// 封裝到map中返回
Map resultMap=new HashMap<>();
resultMap.put("error", 0);
resultMap.put("url", url);
return JsonUtils.objectToJson(resultMap);
} catch (Exception e) {
e.printStackTrace();
Map resultMap=new HashMap<>();
resultMap.put("error", 1);
resultMap.put("message", "圖片上傳失敗");
return JsonUtils.objectToJson(resultMap);
}
複製代碼
遊覽器兼容問題解決
富文本編輯器
商品添加功能實現
@Autowired
private TbItemDescMapper itemDescMapper;
@Override
public E3Result addItem(TbItem item, String desc) {
//生成商品id
long itemId=IDUtils.genItemId();
//補全item的屬性
item.setId(itemId);
//1-正常 2-下架 3-刪除
item.setStatus((byte) 1);
item.setCreated(new Date());
item.setUpdated(new Date());
//向商品表插入數據
itemMapper.insert(item);
//建立一個商品描述表對應的pojo對象
TbItemDesc itemDesc=new TbItemDesc();
//補全屬性
itemDesc.setItemId(itemId);
itemDesc.setItemDesc(desc);
itemDesc.setCreated(new Date());
itemDesc.setUpdated(new Date());
//向商品描述表插入數據
itemDescMapper.insert(itemDesc);
//返回成功
return E3Result.ok();
複製代碼
@RequestMapping(value="/item/save",method=RequestMethod.POST)
@ResponseBody
public E3Result addItem(TbItem item,String desc) {
E3Result result = itemService.addItem(item, desc);
return result;
}
複製代碼