【涛涛商城】内容服务系统CMS

 

目录

项目:内容服务系统

1、内容服务系统创建

1、1 taotoa-content

1.2 taotao-content-interface

1.3 taotao-content-service

1.4 框架整合

 

2 内容分类管理

2.1展示内容分类

2.2 新增节点

2.3更新节点和删除节点

3、内容管理

3.1 内容列表查询

3.2 新增内容

总结:返回前端三种方式

1、EasyUIDataResult类型:这种是带有分页信息的展览模式

2、EasyUITreeNode类型:这种是展示树形下拉包含父子关系的模式

3、TaotaoResult类型:这种是返回状态信息的模式,如前端根据验证码进行判断处理是否成功


项目:内容服务系统

需要创建一个内容服务系统。可以参考taotao-manager创建。

前提:创建内容服务系统只需要创建两个maven工程,原因是在taotao-manager中pojo和dao都是以jar工程,又因为dao中的mapper文件都是通用的,pojo也是可以通用的,因此我们可以直接在taotao-content-service中导入jar即可。

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

|--taotao-content-interface jar

|--taotao-content-Service  war

1、内容服务系统创建

1、1 taotoa-content

1.1.1 pom.xml

<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>com.taotao</groupId>
		<artifactId>taotao-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<groupId>com.taotao</groupId>
	<artifactId>taotao-content</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	<dependencies>
		<dependency>
			<groupId>com.taotao</groupId>
			<artifactId>taotao-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>

1.2 taotao-content-interface

1.2.1 pom.xml文件

<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>com.taotao</groupId>
		<artifactId>taotao-content</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>taotao-content-interface</artifactId>
	<dependencies>
		<dependency>
			<groupId>com.taotao</groupId>
			<artifactId>taotao-manager-pojo</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>
</project>

1.3 taotao-content-service

1.3.1 pom.xml

<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>com.taotao</groupId>
		<artifactId>taotao-content</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>taotao-content-service</artifactId>
	<packaging>war</packaging>
	<dependencies>
		<dependency>
			<groupId>com.taotao</groupId>
			<artifactId>taotao-manager-dao</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>com.taotao</groupId>
			<artifactId>taotao-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>

1.4 框架整合

 

2 内容分类管理

2.1展示内容分类

2.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. 取查询参数id,parentId
  2. 根据parentId查询tb_content_category,查询子节点列表。
  3. 得到List<TbContentCategory>
  4. 把列表转换成List<EasyUITreeNode>

Dao层:由于查询的是单表,因此使用逆向工程就可以

Service层:

@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;
	}

}

发布服务

引用服务

Taotao-manamanager-web表现层依赖taotao-content-interface模块

  		//pom文件中
<dependency>
  <groupId>com.taotao</groupId>
  <artifactId>taotao-content-interface</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</dependency>

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;
	}
}

2.2 新增节点

功能分析:

        onAfterEdit : function(node){
        	var _tree = $(this);
        	if(node.id == 0){
        		// 新增节点
        		$.post("/content/category/create",{parentId:node.parentId,name:node.text},function(data){
        			if(data.status == 200){
        				_tree.tree("update",{
            				target : node.target,
            				id : data.data.id
            			});
        			}else{
        				$.messager.alert('提示','创建'+node.text+' 分类失败!');
        			}
        		});
        	}else{
        		$.post("/content/category/update",{id:node.id,name:node.text});
        	}
        }

请求的url:/content/category/create

请求的参数:

Long parentId  ---   String name

响应的结果:

json数据,TaotaoResult,其中包含一个对象,对象有id属性,新生产的内容分类id

业务逻辑:

  1. 接收两个参数:parentId、name
  2. 向tb_content_category表中插入数据。
    1. 创建一个TbContentCategory对象
    2. 补全TbContentCategory对象的属性
    3. 向tb_content_category表中插入数据
  3. 判断父节点的isparent是否为true,不是true需要改为true。
  4. 需要主键返回。
  5. 返回TaotaoResult,其中包装TbContentCategory对象

 Dao层:使用逆向工程,但是需要主键返回,目的在于将id不光是存储在数据库中,也需要封装成java对象返回给前端

    	<!-- 返回主键的id,提供给前端,将前端的id由默认值0改成数据库中对应的id -->
	  <selectKey keyProperty="id" resultType="long" order="AFTER">
	  	SELECT LAST_INSERT_ID()
	  
	  </selectKey>

注意:修改完代码后,需要向本地仓库安装taotao-manager-dao包

service层:

public TaotaoResult 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、返回TaotaoResult,其中包装TbContentCategory对象
		return TaotaoResult.ok(tbContentCategory);
	}

表现层Controller

请求的url:/content/category/create

请求的参数:

Long parentId

String name

响应的结果:

json数据,TaotaoResult

@RequestMapping("/create")
	@ResponseBody
	public TaotaoResult createCategory(Long parentId, String name) {
		TaotaoResult result = contentCategoryService.addContentCategory(parentId, name);
		return result;
	}

2.3更新节点和删除节点

删除:

请求的url:/content/category/delete/

参数:id,当前节点的id。

响应的数据:json。TaotaoResult。

业务逻辑:

  1. 根据id删除记录。
  2. 判断父节点下是否还有子节点,如果没有需要把父节点的isparent改为false
  3. 如果删除的是父节点,子节点要级联删除。

两种解决方案:

  1. 如果判断是父节点不允许删除。
  2. 递归删除。

3、内容管理

3.1 内容列表查询

业务逻辑

  1. 请求的url:/content/query/list
  2. 参数:categoryId 分类id
  3. 响应的数据:json数据
  4. {total:查询结果总数量,rows[{id:1,title:aaa,subtitle:bb,...}]} EasyUIDataGridResult
  5. 描述商品数据List<TbContent>
  6. 查询的表:tb_content
  7. 根据内容分类id查询内容列表。要进行分页处理。

Controller层

	/**
	 *根据id查询列表
	 *@RequestParam(name="categoryId",defaultValue="0")
	 */
	@RequestMapping("/query/list")
	@ResponseBody
	public EasyUIDataResult getContentList(long categoryId,Integer page, Integer rows ){
	
	
		EasyUIDataResult result = contentService.queryContentList(categoryId,page,rows);
		System.out.println(result);
		return result;
		
	}

service层

/**
	 * 内容列表查询,展示信息
	 */
	public EasyUIDataResult queryContentList(long categoryId,Integer currentPage, Integer pageSize ) {
		
		//设置分页信息
		PageHelper.startPage(currentPage,pageSize);
//		1、创建查询对象
		TbContentExample example  = new TbContentExample();
//		2、添加查询条件
		Criteria createCriteria = example.createCriteria();
//		3、将categoryid传入
		createCriteria.andCategoryIdEqualTo(categoryId);
//		4、进行查询
		List<TbContent> list = tbContentMapper.selectByExample(example);
		for (TbContent tbContent : list) {
			System.out.println(tbContent);
		}
//		5、对结果集进行解析,获取分页信息
		PageInfo<TbContent> pageInfo = new PageInfo<>(list);
//		6、将结果封装到EasyUIDataResult对象中
		EasyUIDataResult data = new EasyUIDataResult();
		data.setRows(list);
		data.setTotal(pageInfo.getTotal());
//		7、返回结果集
		return data;
	}

3.2 新增内容

功能分析

提交表单请求的url:/content/save

参数:表单的数据。使用pojo接收TbContent

返回值:TaotaoResult(json数据)

业务逻辑:

  1. 把TbContent对象属性补全。
  2. 向tb_content表中插入数据。
  3. 返回TaotaoResult

Service层:

public class ContentServiceImpl implements ContentService {

	@Autowired
	private TbContentMapper contentMapper;
	
	@Override
	public TaotaoResult addContent(TbContent content) {
		//补全属性
		content.setCreated(new Date());
		content.setUpdated(new Date());
		//插入数据
		contentMapper.insert(content);
		return TaotaoResult.ok();
	}

}

发布服务和引用服务

Controller层

@Controller
public class ContentController {

	@Autowired
	private ContentService contentService;
	
	@RequestMapping("/content/save")
	@ResponseBody
	public TaotaoResult addContent(TbContent content) {
		TaotaoResult result = contentService.addContent(content);
		return result;
	}
}

总结:返回前端三种方式

1、EasyUIDataResult类型:这种是带有分页信息的展览模式

2、EasyUITreeNode类型:这种是展示树形下拉包含父子关系的模式

3、TaotaoResult类型:这种是返回状态信息的模式,如前端根据验证码进行判断处理是否成功

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值