B2Ctt商城06 cms系统

1 Cms系统
内容管理系统

这里写图片描述
右键可以管理分类,添加删除等
先实现内容的分类管理再实现内容管理。

初始化树形视图的url: ‘/content/category/list’,
(function(){(“#contentCategory”).tree({
url : ‘/content/category/list’,

分析参数
参数是id,当前节点id属性,应该根据此id查询子节点列表。
返回值:包含id、text、state三个属性的json数据列表

service 
入参是页面传递的parentId 
出参:每个节点包含三个属性id、text、state三个属性。可以使用EUTreeNode。

@Service
public class ContentCategoryServiceImpl implements ContentCategoryService {

    @Autowired
    private TbContentCategoryMapper contentCategoryMapper;
    @Override
    public List<EUTreeNode> getCategoryList(long parentId) {
        //根据parentid查询节点列表
        TbContentCategoryExample example = new TbContentCategoryExample();
        Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        //执行查询
        List<TbContentCategory> list = contentCategoryMapper.selectByExample(example);
        List<EUTreeNode> resultList = new ArrayList<>();
        for (TbContentCategory tbContentCategory : list) {
            //创建一个节点
            EUTreeNode node = new EUTreeNode();
            node.setId(tbContentCategory.getId());
            node.setText(tbContentCategory.getName());
            node.setState(tbContentCategory.getIsParent()?"closed":"open");
            // 根据是不是父节点 设置closed 或 open
            resultList.add(node);
        }
        return resultList;
    }

}

controller
@RequestMapping("/list")
     @ResponseBody
    public List<EUTreeNode> getContentCatList(@RequestParam(value="id", defaultValue="0")Long parentId) {
        List<EUTreeNode> list = contentCategoryService.getCategoryList(parentId);
        return list;
    }

3.1.2 内容分类添加

请求的url:/content/category/create

这里写图片描述

参数:
1、parentId父节点id
2、name:当前节点的名称
返回值:TaotaoResult。其中包含节点pojo对象。

service
功能:接收两个参数parentId父节点id、name:当前节点的名称。
返回TaoTaoResult包含记录的pojo对象。
页面的信息里有id,所以需要返回主键信息:

public TaotaoResult insertContentCategory(long parentId, String name) {

        //创建一个pojo
        TbContentCategory contentCategory = new TbContentCategory();
        contentCategory.setName(name);
        contentCategory.setIsParent(false);
        // 新增的内容是叶子
        //'状态。可选值:1(正常),2(删除)',
        contentCategory.setStatus(1);
        contentCategory.setParentId(parentId);
        contentCategory.setSortOrder(1);
        contentCategory.setCreated(new Date());
        contentCategory.setUpdated(new Date());
        //添加记录
        contentCategoryMapper.insert(contentCategory);
        //查看父节点的isParent列是否为true,如果不是true改成true
        TbContentCategory parentCat = contentCategoryMapper.selectByPrimaryKey(parentId);
        //判断是否为true
        if(!parentCat.getIsParent()) {
            parentCat.setIsParent(true);
            //更新父节点
            contentCategoryMapper.updateByPrimaryKey(parentCat);
        }
        //返回结果
        return TaotaoResult.ok(contentCategory);
    }

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

删除分类

$.messager.confirm('确认','确定删除名为 '+node.text +' 的分类吗?',function(r){
            if(r){
                $.post("/content/category/delete",{parentId:node.parentId,id:node.id},function(){
                    tree.tree("remove",node.target);
                }); 
            }
        });

执行报错:
Optional long parameter ‘parentId’ is present but cannot be translated into a null value due to

是因为我们在方法里接口参数parentId,但是实际上页面并没有传入parentId,默认是空,但是又不允许为空,所以把报错

@RequestMapping("/delete")
    @ResponseBody 
    public TaotaoResult deleteContentCategory(long parentId, long id) {
        System.out.println("parentId : " + parentId  + " [id]" + id);
        return categoryService.deleteContentCategory(parentId, id);
    }

检查方法

这里写图片描述

想到一个方法就是parentI的可以通过id查询出来,页面不传递也可以

    @Override
    public TaotaoResult deleteContentCategory(long id) {
        TbContentCategory category = contentcategoryMapper.selectByPrimaryKey(id);
        // 查询父节点内容
        TbContentCategory parentCategory = contentcategoryMapper.selectByPrimaryKey(category.getParentId());
        // 删除本节点
        contentcategoryMapper.deleteByPrimaryKey(id);
        TbContentCategoryExample example = new TbContentCategoryExample();
        Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(parentCategory.getId());
        List<TbContentCategory> list = contentcategoryMapper.selectByExample(example);
        if(list == null){
            //判断父节点是否为parnet 不是设为false更新父节点
            parentCategory.setIsParent(false);
            contentcategoryMapper.updateByPrimaryKeySelective(parentCategory);
        }
        // 返回结果
        return TaotaoResult.ok();
    }

3.2 内容管理
1. 列表
url:’/content/query/list’,queryParams:{categoryId:0}”

业务逻辑:
根据内容分类id查询内容列表。需要实现分页。返回EUDataGridResult

if(tree.tree("isLeaf",node.target)){
                datagrid.datagrid('reload', {
                    categoryId :node.id
                });
            }
传递 categoryId 

 service
 @Override
    public EUDataGridResult getContentList(long categoryId, int page, int rows) {
        TbContentExample example = new TbContentExample();
        Criteria criteria = example.createCriteria();
        criteria.andCategoryIdEqualTo(categoryId);
        // 分页处理
        PageHelper.startPage(page, rows);
        List<TbContent> list = contentMapper.selectByExample(example);

        PageInfo<TbContent> info = new PageInfo<>(list);
        long total = info.getTotal();
        EUDataGridResult data = new EUDataGridResult();
        data.setRows(list);
        data.setTotal(total);
        return data;
    }

    controller 直接调用servic
    @RequestMapping("/query/list")
    @ResponseBody
    public EUDataGridResult queryContentList
        (Integer page, Integer rows,long categoryId) {
        return contentService.getContentList(categoryId, page, rows);
    }       

3.2.2 内容添加

这里写图片描述



@Override
    public TaotaoResult addContent(TbContent content) {
        content.setCreated(new Date());
        content.setUpdated(new Date());
        contentMapper.insert(content);
        return TaotaoResult.ok();
    }

这里写图片描述

4.1 首页大广告方案

这里写图片描述

流程
这里写图片描述

根据内容的分类id查询内容列表,从tb_content表中查询。服务是一个restFul形式的服务。使用http协议传递json格式的数据。

@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private TbContentMapper contentMapper;
    @Override
    public List<TbContent> getContentList(long contentCid) {
        //根据内容分类id查询内容列表
        TbContentExample example = new TbContentExample();
        Criteria criteria = example.createCriteria();
        criteria.andCategoryIdEqualTo(contentCid);
        //执行查询
        List<TbContent> list = contentMapper.selectByExample(example);

        return list;
    }

}


Controller

发布服务。接收查询参数。Restful风格内容分类id应该从url中取。
/rest/content/list/{contentCategoryId}
从url中取内容分类id,

@RequestMapping("/list/{contentCategoryId}")
    @ResponseBody
    public TaotaoResult getContentList(@PathVariable Long contentCategoryId) {
        try {
            List<TbContent> list = contentService.getContentList(contentCategoryId);
            return TaotaoResult.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
            return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
        }
    }

上面的地址 没有aciton 前面是rest
http://localhost:8081/rest/content/list/89

4.4 Httpclient的使用

get请求测试

@Test
    public void doGet() throws Exception {
        //创建一个httpclient对象
        CloseableHttpClient httpClient = HttpClients.createDefault();
        //创建一个GET对象
        HttpGet get = new HttpGet("http://www.sogou.com");
        //执行请求
        CloseableHttpResponse response = httpClient.execute(get);
        //取响应的结果
        int statusCode = response.getStatusLine().getStatusCode();
        System.out.println(statusCode);
        HttpEntity entity = response.getEntity();
        String string = EntityUtils.toString(entity, "utf-8");
        System.out.println(string);
        //关闭httpclient
        response.close();
        httpClient.close();
    }

2 、带参数

//创建一个uri对象
        URIBuilder uriBuilder = new URIBuilder("http://www.sogou.com/web");
        uriBuilder.addParameter("query", "花千骨");
        HttpGet get = new HttpGet(uriBuilder.build());

注意:对于URL必须使用 http://开始,否则会有如下报错信息:
HttpGet get = new HttpGet(“http://www.sogou.com“);
Caused by: org.apache.http.ProtocolException: Target host is not specified

异常:

这里写图片描述

4.4.3.3 使用httpclient执行post请求

post方法
@RequestMapping(value="/httpclient/post", method=RequestMethod.POST)
    @ResponseBody
    public String doPost(String name){
        return "name = " + name;
    }

1、不带参数

public void doPost() throws Exception {
        CloseableHttpClient httpClient = HttpClients.createDefault();

        //创建一个post对象
        HttpPost post = new HttpPost("http://localhost:8082/httpclient/post.html");
        //执行post请求
        CloseableHttpResponse response = httpClient.execute(post);
        String string = EntityUtils.toString(response.getEntity());
        System.out.println(string);
        response.close();
        httpClient.close();

    }

注意:taotao-portalweb.xml中配置了
   <servlet-mapping>
        <servlet-name>taotao-portal</servlet-name>
        <!-- 伪静态化 -->
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    只会拦截。html 所以访问需要加.html
2、 带参数

    //创建一个Entity。模拟一个表单
        List<NameValuePair> kvList = new ArrayList<>();
        kvList.add(new BasicNameValuePair("username", "zhangsan"));
        kvList.add(new BasicNameValuePair("password", "123"));

        //包装成一个Entity对象
        StringEntity entity = new UrlEncodedFormEntity(kvList, "utf-8");
        //设置请求的内容
        post.setEntity(entity);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: DLMS UA CTT是什么?DLMS UA是指DLMS用户协会(DLMS User Association),是一个国际性的组织,致力于推动和发展DLMS/COSEM(Device Language Message Specification/Companion Specification for Energy Metering)标准的使用。 DLMS/COSEM是一种通信协议和数据模型,用于远程仪表抄表、控制和管理等应用。它提供了标准化的通信接口和数据结构,以支持不同厂商的电能计量、电表和其他能源设备的互操作性。 CTT则是指Conformance Test Tool,即符合性测试工具。DLMS UA CTT是DLMS UA组织开发和提供的用于测试设备是否符合DLMS/COSEM标准的工具。 DLMS UA CTT工具可以用于验证厂商设备是否符合DLMS/COSEM标准的要求。通过进行测试,可以检查设备的通信接口、数据模型、协议解析等功能是否符合标准规范。这有助于确保设备在与其他厂商设备进行通信时能够正确交互,并保证数据的准确性和可靠性。 DLMS UA CTT工具为厂商和用户提供了一种简单和可靠的方法来测试设备的符合性。通过使用该工具,可以降低设备在采购和使用过程中出现兼容性问题的风险,提高设备的互操作性和可靠性。 总之,DLMS UA CTT是DLMS用户协会提供的一种测试工具,用于验证设备是否符合DLMS/COSEM标准,以确保设备的互操作性和可靠性。 ### 回答2: DLMS UA CTT(Conformance Test Cases)是DLMS/COSEM通信标准的符合性测试用例。DLMS(Device Language Message Specification)是一种用于远程仪表读数和控制的通信协议,常用于智能电表和能源管理系统等领域。 DLMS UA CTT中的UA代表User Association,即用户关联。在DLMS/COSEM通信中,用户通过一个连接对象(即关联)与远程设备建立通信。用户关联可以是读取和控制仪表数据的客户端应用程序,也可以是远程设备的服务器应用程序。 CTT是指符合性测试用例,用于验证通信系统是否符合DLMS/COSEM标准规范。DLMS UA CTT包含一系列测试用例,涵盖了DLMS协议的各个方面,包括数据读取、写入、事件处理等。通过执行这些符合性测试用例,可以验证通信系统的兼容性和互操作性。 通过执行DLMS UA CTT来测试通信系统的符合性,可以确保DLMS/COSEM通信的正确性和可靠性。这对于保证远程仪表的准确读数、数据安全性以及设备之间的互操作性非常重要。因此,DLMS UA CTT的执行是DLMS/COSEM系统开发和应用的必要步骤之一。 ### 回答3: DLMS UA CTT是指DLMS用户协会(DLMS User Association)的互操作性测试工具(Conformance Test Tool)。DLMS用户协会是国际上一个专门致力于推广和发展DLMS/COSEM(Device Language Message Specification/Companion Specification for Energy Metering)标准的非盈利组织。 DLMS/COSEM是一种用于能量计量领域的通信协议标准,它定义了能量计量设备之间的通信交互方式。DLMS/COSEM支持多种物理通信介质,例如以太网、无线通信和GPRS等。这个标准的主要目标是实现设备之间的互操作性,使不同厂家的能量计量设备能够互相通信和交换数据。 DLMS UA CTT是DLMS用户协会提供的一个测试工具,用于验证厂家生产的能量计量设备是否符合DLMS/COSEM标准。该工具通过执行一系列的测试用例,检查设备是否正确实现了DLMS/COSEM的各项功能和要求。测试包括读写数据、编解码数据、处理事件和异常等。 使用DLMS UA CTT进行测试可以确保厂商生产的能量计量设备能够与其他符合DLMS/COSEM标准的设备进行互联互通,并能够与DLMS/COSEM标准兼容的软件系统进行集成。这有助于提高能量计量设备市场的竞争性,促进能源管理和数据交换的标准化。 总之,DLMS UA CTT是DLMS用户协会提供的一个测试工具,用于验证能量计量设备是否符合DLMS/COSEM标准,确保设备的互操作性和兼容性。这对于促进能源管理和数据交换的标准化具有重要意义。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值