淘淘商城16_后台内容管理系统04_展示商城大广告位

本文介绍了一种基于RESTful服务的内容分类查询方法,通过HTTP协议传递JSON数据,实现根据内容分类ID查询tb_content表中数据的功能。文章详细展示了service接口、service实现类及controller的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 页面的展示

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值