18、内容服务系统——内容管理

内容服务系统——内容管理

功能点分析

  • 内容列表查询
  • 新增内容
  • 编辑内容
  • 删除内容

在这里插入图片描述
GET http://localhost:8081/content/query/list?categoryId=0&page=1&rows=20 404 (Not Found)

内容列表查询

  • 请求的 url:/content/query/list
  • 参数:categoryId 分类id
  • 响应的数据:json数据
    {total:查询结果总数量,rows[{id:1,title:aaa,subtitle:bb,…}]}
    EasyUIDataGridResult
    描述商品数据List
    查询的表:tb_content
  • 业务逻辑:
    根据内容分类id查询内容列表。要进行分页处理。
package cn.ynx.e3mall.content.service;

import cn.ynx.e3mall.common.pojo.EasyUIDataGridResult;

public interface ContentService {

    EasyUIDataGridResult getContentList(long categoryId, int page, int rows);

}
package cn.ynx.e3mall.content.service.impl;

import cn.ynx.e3mall.common.pojo.EasyUIDataGridResult;
import cn.ynx.e3mall.content.service.ContentService;
import cn.ynx.e3mall.mapper.TbContentMapper;
import cn.ynx.e3mall.pojo.TbContent;
import cn.ynx.e3mall.pojo.TbContentExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ContentServiceImpl implements ContentService {

    @Resource
    private TbContentMapper tbContentMapper;

    @Override
    public EasyUIDataGridResult getContentList(long categoryId, int page, int rows) {
        //设置分页信息
        PageHelper.startPage(page, rows);

        //根据分类id查询内容列表
        //设置查询条件
        TbContentExample example = new TbContentExample();
        TbContentExample.Criteria criteria = example.createCriteria();
        criteria.andCategoryIdEqualTo(categoryId);
        //执行查询
        List<TbContent> list = tbContentMapper.selectByExample(example);

        //取分页信息
        PageInfo<TbContent> pageInfo = new PageInfo<>(list);

        //创建返回结果对象
        EasyUIDataGridResult result = new EasyUIDataGridResult();
        result.setTotal((int)pageInfo.getTotal());
        result.setRows(list);

        return result;
    }

}

发布服务:

接收服务:

package cn.ynx.e3mall.controller;

import cn.ynx.e3mall.common.pojo.EasyUIDataGridResult;
import cn.ynx.e3mall.content.service.ContentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/content")
public class ContentController {

    @Resource
    private ContentService contentService;

    @RequestMapping("/query/list")
    @ResponseBody
    public EasyUIDataGridResult getContentList(Long categoryId, Integer page, Integer rows){
        EasyUIDataGridResult result = contentService.getContentList(categoryId, page, rows);
        return result;
    }

}

新增内容

功能分析
在这里插入图片描述

新增内容,必须指定一个内容分类。
在这里插入图片描述

在这里插入图片描述

  • 提交表单请求的url:/content/save
  • 参数:表单的数据。使用pojo接收TbContent
  • 返回值:E3Result(json数据)
  • 业务逻辑:
    1、把TbContent对象属性补全。
    2、向tb_content表中插入数据。
    3、返回E3Result

Dao

逆向工程

Service

参数:TbContent
返回值:E3Result

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

发布服务:

表现层

引用服务:

e3-manager-web工程中引用。

Controller

提交表单请求的url:/content/save
参数:表单的数据。使用pojo接收TbContent
返回值:E3Result(json数据)

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

测试

编辑内容

删除内容

猜你喜欢

转载自blog.csdn.net/weixin_42112635/article/details/84993789