JAVAEE——宜立方商城05:前台系統搭建、首頁展示、Cms系統的實現


1. 學習計划

1、前台系統搭建

2、商城首頁展示

3、Cms系統的實現

a) 內容分類管理

b) 內容管理

4、前台內容動態展示

 

2. 商城首頁展示

 

系統架構:

 

 

頁面位置:

 

 

2.1. 工程搭建

可以參考e3-manager-web工程搭建

 

2.2. 功能分析

請求的url/index

Web.xml中的歡迎頁配置:

 

 

http://localhost:8082/index.html

參數:沒有

返回值:String 邏輯視圖

@Controller

public class IndexController {

 

@RequestMapping("/index")

public String showIndex() {

return "index";

}

}

 

3. 首頁動態展示分析

內容信息要從數據庫中獲得

3.1. 動態展示分析

1、內容需要進行分類

2、分類下有子分類,需要動態管理。

3、分類下有內容列表

4、單點的內容信息

a) 有圖片

b) 有鏈接

c) 有標題

d) 有價格

e) 包含大文本類型,可以作為公告

 

需要一個內容分類表和一個內容表。內容分類和內容表是一對多的關系。

內容分類表,需要存儲樹形結構的數據。

內容分類表:tb_content_category

內容表:tb_content

 

需要有后台來維護內容信息。Cms系統。

 

需要創建一個內容服務系統。可以參考e3-manager創建。

E3-content:聚合工程打包方式pom

|--e3-content-interface jar

|--e3-content-Service  war

 

4. 內容服務系統創建

4.1. 工程搭建

可以參考e3-manager工程搭建。

 

 

4.2. E3-content

 

4.2.1. Pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>cn.e3mall</groupId>

<artifactId>e3-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

<groupId>cn.e3mall</groupId>

<artifactId>e3-content</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<dependencies>

<dependency>

<groupId>cn.e3mall</groupId>

<artifactId>e3-common</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

</dependencies>

<!-- 配置tomcat插件 -->

<build>

<plugins>

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat7-maven-plugin</artifactId>

<configuration>

<port>8083</port>

<path>/</path>

</configuration>

</plugin>

</plugins>

</build>

</project>

 

4.3. e3-content-interface

 

4.3.1. Pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>cn.e3mall</groupId>

<artifactId>e3-content</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

<artifactId>e3-content-interface</artifactId>

<dependencies>

<dependency>

<groupId>cn.e3mall</groupId>

<artifactId>e3-manager-pojo</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

</dependencies>

</project>

 

4.4. e3-content-service

 

4.4.1. Pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>cn.e3mall</groupId>

<artifactId>e3-content</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

<artifactId>e3-content-service</artifactId>

<packaging>war</packaging>

<dependencies>

<dependency>

<groupId>cn.e3mall</groupId>

<artifactId>e3-manager-dao</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

<dependency>

<groupId>cn.e3mall</groupId>

<artifactId>e3-content-interface</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

<!-- spring的依賴 -->

<!-- Spring -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-beans</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aspects</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jms</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context-support</artifactId>

</dependency>

<!-- dubbo相關 -->

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>dubbo</artifactId>

<!-- 排除依賴 -->

<exclusions>

<exclusion>

<groupId>org.springframework</groupId>

<artifactId>spring</artifactId>

</exclusion>

<exclusion>

<groupId>org.jboss.netty</groupId>

<artifactId>netty</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.apache.zookeeper</groupId>

<artifactId>zookeeper</artifactId>

</dependency>

<dependency>

<groupId>com.github.sgroschupf</groupId>

<artifactId>zkclient</artifactId>

</dependency>

</dependencies>

</project>

 

4.5. 框架整合

參考e3-manager

 

 

5. Cms系統實現

5.1. 內容分類管理

5.1.1. 展示內容分類

功能分析

 

 

請求的url/content/category/list

請求的參數:id,當前節點的id。第一次請求是沒有參數,需要給默認值“0

響應數據:List<EasyUITreeNode>@ResponseBody

Json數據。

[{id:1,text:節點名稱,state:open(closed)},

{id:2,text:節點名稱2,state:open(closed)},

{id:3,text:節點名稱3,state:open(closed)}]

業務邏輯:

1、取查詢參數idparentId

2、根據parentId查詢tb_content_category,查詢子節點列表。

3、得到List<TbContentCategory>

4、把列表轉換成List<EasyUITreeNode>

 

Dao

使用逆向工程

 

Service

參數:long parentId

返回值:List<EasyUITreeNode>

@Service

public class ContentCategoryServiceImpl implements ContentCategoryService {

 

@Autowired

private TbContentCategoryMapper contentCategoryMapper;

 

@Override

public List<EasyUITreeNode> getContentCategoryList(long parentId) {

// 1、取查詢參數id,parentId

// 2、根據parentId查詢tb_content_category,查詢子節點列表。

TbContentCategoryExample example = new TbContentCategoryExample();

//設置查詢條件

Criteria criteria = example.createCriteria();

criteria.andParentIdEqualTo(parentId);

//執行查詢

// 3、得到List<TbContentCategory>

List<TbContentCategory> list = contentCategoryMapper.selectByExample(example);

// 4、把列表轉換成List<EasyUITreeNode>ub

List<EasyUITreeNode> resultList = new ArrayList<>();

for (TbContentCategory tbContentCategory : list) {

EasyUITreeNode node = new EasyUITreeNode();

node.setId(tbContentCategory.getId());

node.setText(tbContentCategory.getName());

node.setState(tbContentCategory.getIsParent()?"closed":"open");

//添加到列表

resultList.add(node);

}

return resultList;

}

 

}

發布服務

 

 

表現層

E3-manager-web

依賴e3-content-interface模塊

 

 

Springmvc.xml中添加服務的引用:

 

 

 

 

 

Controller

@Controller

@RequestMapping("/content/category")

public class ContentCategoryController {

 

@Autowired

private ContentCategoryService contentCategoryService;

 

@RequestMapping("/list")

@ResponseBody

public List<EasyUITreeNode> getContentCatList(

@RequestParam(value="id", defaultValue="0") Long parentId) {

 

List<EasyUITreeNode> list = contentCategoryService.getContentCategoryList(parentId);

return list;

}

}

 

5.1.2. 新增節點

功能分析

 

 

請求的url/content/category/create

請求的參數:

Long parentId

String name

響應的結果:

json數據,E3Result,其中包含一個對象,對象有id屬性,新生產的內容分類id

業務邏輯:

1、接收兩個參數:parentIdname

2、tb_content_category表中插入數據。

a) 創建一個TbContentCategory對象

b) 補全TbContentCategory對象的屬性

c) tb_content_category表中插入數據

3、判斷父節點的isparent是否為true,不是true需要改為true

4、需要主鍵返回。

5、返回E3Result,其中包裝TbContentCategory對象

 

Dao

可以使用逆向工程。

需要添加主鍵返回:

 

 

注意:修改完代碼后,需要向本地倉庫安裝e3-manager-dao

Service

參數:parentIdname

返回值:返回E3Result,其中包裝TbContentCategory對象

@Override

public E3Result addContentCategory(long parentId, String name) {

// 1、接收兩個參數:parentId、name

// 2、向tb_content_category表中插入數據。

// a)創建一個TbContentCategory對象

TbContentCategory tbContentCategory = new TbContentCategory();

// b)補全TbContentCategory對象的屬性

tbContentCategory.setIsParent(false);

tbContentCategory.setName(name);

tbContentCategory.setParentId(parentId);

//排列序號,表示同級類目的展現次序,如數值相等則按名稱次序排列。取值范圍:大於零的整數

tbContentCategory.setSortOrder(1);

//狀態。可選值:1(正常),2(刪除)

tbContentCategory.setStatus(1);

tbContentCategory.setCreated(new Date());

tbContentCategory.setUpdated(new Date());

// c)向tb_content_category表中插入數據

contentCategoryMapper.insert(tbContentCategory);

// 3、判斷父節點的isparent是否為true,不是true需要改為true。

TbContentCategory parentNode = contentCategoryMapper.selectByPrimaryKey(parentId);

if (!parentNode.getIsParent()) {

parentNode.setIsParent(true);

//更新父節點

contentCategoryMapper.updateByPrimaryKey(parentNode);

}

// 4、需要主鍵返回。

// 5、返回E3Result,其中包裝TbContentCategory對象

return E3Result.ok(tbContentCategory);

}

 

發布服務。

 

表現層

請求的url/content/category/create

請求的參數:

Long parentId

String name

響應的結果:

json數據,E3Result

 

@RequestMapping("/create")

@ResponseBody

public E3Result createCategory(Long parentId, String name) {

E3Result result = contentCategoryService.addContentCategory(parentId, name);

return result;

}

 

5.1.3. 內容分類重命名、刪除

重命名

 

 

請求的url/content/category/update

參數:id,當前節點idname,重命名后的名稱。

業務邏輯:根據id更新記錄。

返回值:返回E3Result.ok()

 

作業。

 

刪除節點

 

 

請求的url/content/category/delete/

參數:id,當前節點的id

響應的數據:jsonE3Result

業務邏輯:

1、根據id刪除記錄。

2、判斷父節點下是否還有子節點,如果沒有需要把父節點的isparent改為false

3、如果刪除的是父節點,子節點要級聯刪除。

兩種解決方案:

1)如果判斷是父節點不允許刪除。

2)遞歸刪除。

作業。

 

5.2. 內容管理

5.2.1. 功能點分析

1、內容列表查詢(作業)

2、新增內容

3、編輯內容(作業)

4、刪除內容(作業)

 

5.2.2. 內容列表查詢

請求的url/content/query/list

參數:categoryId 分類id

響應的數據:json數據

{total:查詢結果總數量,rows[{id:1,title:aaa,subtitle:bb,...}]}

EasyUIDataGridResult

描述商品數據List<TbContent>

查詢的表:tb_content

業務邏輯:

根據內容分類id查詢內容列表。要進行分頁處理。

 

5.2.3. 新增內容

功能分析

 

 

新增內容,必須指定一個內容分類。

 

 

提交表單請求的url/content/save

參數:表單的數據。使用pojo接收TbContent

返回值:E3Resultjson數據)

業務邏輯:

1、把TbContent對象屬性補全。

2、向tb_content表中插入數據。

3、返回E3Result

 

Dao

逆向工程

 

Service

參數:TbContent

返回值:E3Result

@Service

public class ContentServiceImpl implements ContentService {

 

@Autowired

private TbContentMapper contentMapper;

 

@Override

public E3Result addContent(TbContent content) {

//補全屬性

content.setCreated(new Date());

content.setUpdated(new Date());

//插入數據

contentMapper.insert(content);

return E3Result.ok();

}

 

}

 

發布服務

 

 

引用服務

Toatao-manager-web工程中引用。

 

Controller

提交表單請求的url/content/save

參數:表單的數據。使用pojo接收TbContent

返回值:E3Resultjson數據)

@Controller

public class ContentController {

 

@Autowired

private ContentService contentService;

 

@RequestMapping("/content/save")

@ResponseBody

public E3Result addContent(TbContent content) {

E3Result result = contentService.addContent(content);

return result;

}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM