seo优化:其中一点就是为了在搜索引擎搜索时排名靠前
1. 需求分析
根据内容的分类id查询内容列表,从tb_content表中查询。服务是一个restFul形式的服务。使用http协议传递json格式的数据。根据管广告位的编号,查询出内容分类信息.
2. 代码编写
2.1 service
package com.taotao.rest.service;
import java.util.List;
import com.taotao.pojo.TbContent;
public interface ContentService {
//查询内容分类数据,在tb_content表中
public List<TbContent> getContentByCategoryId(long categoryId);
}
2.2 serviceImpl
package com.taotao.rest.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.taotao.mapper.ContentMapper;
import com.taotao.pojo.TbContent;
import com.taotao.rest.service.ContentService;
@Service
public class ContentServiceImpl implements ContentService {
@Autowired
private ContentMapper contentMapper;
/**
* 根据categoryId查询内容分类信息
*/
@Override
public List<TbContent> getContentByCategoryId(long categoryId) {
List<TbContent> contentList = contentMapper.getContentByCategoryId(categoryId);
return contentList;
}
}
2.3 Controller
package com.taotao.rest.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.taotao.pojo.TbContent;
import com.taotao.rest.service.ContentService;
import com.taotao.utils.TaotaoResult;
@Controller
public class ContentController {
@Autowired
private ContentService contentService;
/**
* 根据categoryid查询内容分类信息
* @param categoryId
* @return
*/
@RequestMapping("/content/{categoryId}")
@ResponseBody
public TaotaoResult getContentByCategoryId(@PathVariable long categoryId){
List<TbContent> list = contentService.getContentByCategoryId(categoryId);
return TaotaoResult.ok(list);
}
}
2.4 页面的展示