B2Ctt商城06 cms系统
来源:互联网 发布:yii框架 商城源码 编辑:程序博客网 时间:2024/05/22 10:34
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。@Servicepublic 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格式的数据。
@Servicepublic 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 所以访问需要加.html2、 带参数 //创建一个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);
- B2Ctt商城06 cms系统
- 逐浪CMS商城系统
- B2Ctt商城01
- B2Ctt商城02
- B2Ctt商城03 nginx
- B2Ctt商城03 ftp
- B2Ctt商城07 redis
- B2Ctt商城08 Solr
- B2Ctt商城03 添加商品
- B2Ctt商城04 ftp 商品规格实现
- B2Ctt商城05 前台首页商品展示
- B2Ctt商城09 商品详情页面
- 国内主流CMS、SNS、商城等建站系统汇总
- 学习淘淘商城第二十五课(CMS内容管理系统表设计及内容工程搭建)
- 商城系统
- CMS系统
- cms系统
- 商城CMS之OpenCart二次开发详细入门教程
- java 解决母牛生牛问题 2种方法 2头母牛,3岁后每年生1头,9岁直接不生 15岁直接死亡
- 如何将eclipse设置为炫丽的背景!
- Kafka学习笔记 --- 概念梳理
- 笨办法13参数、解包、变量_草稿
- 使用 jquery 获取一组或者单个 checkbox 的选中状态的id
- B2Ctt商城06 cms系统
- 重撸Android事件分发
- 机器学习系统设计 学习笔记
- document 对象 、 自定义对象 、 事件
- linux环境下生成文件,文件名称中文乱码
- 一个像素的Activity
- Linux工具--sed
- 常用Git命令大全思维导图
- PHP读取XML