婚纱照网站制作,网络营销的步骤,具有价值的网站制作,南阳高端网站建设1.1 自动展示所有信息 需求描述: 进入新闻首页portal/findAllType, 自动返回所有栏目名称和id   接口描述 url地址#xff1a;portal/findAllTypes 请求方式#xff1a;get 请求参数#xff1a;无 响应数据#xff1a; 成功  
{code:200,mes…1.1 自动展示所有信息 需求描述: 进入新闻首页portal/findAllType, 自动返回所有栏目名称和id   接口描述 url地址portal/findAllTypes 请求方式get 请求参数无 响应数据 成功  
{code:200,message:OKdata:{[{tid:1,tname:新闻},{tid:2,tname:体育},{tid:3,tname:娱乐},{tid:4,tname:科技},{tid:5,tname:其他}]}
}代码编写 PortalController : 
package com.sunsplanter.controller;import com.sunsplanter.service.TypeService;
import com.sunsplanter.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;RestController
RequestMapping(portal)
public class PortalController {Autowiredprivate TypeService typeService;GetMapping(findAllType)public Result findAllTypes(){Result result  typeService.findAllTypes();return result;}
}TypeService: 
package com.sunsplanter.service;import com.sunsplanter.pojo.Type;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sunsplanter.utils.Result;public interface TypeService extends IServiceType{Result findAllTypes();
}TypeServiceImpl: 
package com.sunsplanter.service.impl;import com.sunsplanter.utils.Result;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunsplanter.mapper.TypeMapper;
import com.sunsplanter.pojo.Type;
import com.sunsplanter.service.TypeService;
Service
public class TypeServiceImpl extends ServiceImplTypeMapper, Type implements TypeService{Autowiredprivate TypeMapper typeMapper;Overridepublic Result findAllTypes() {//不传条件构造器,即查询全部ListType types  typeMapper.selectList(null);return Result.ok(types);}
}达到的效果是,不需要任何参数, 只要访问portal/findAllType, 就返回news_type表中的所有数据(version和is_deleted除外, 因为已在实体类中注解为版本和逻辑删除) 
1.2 - 查询头条详情 
需求描述 - 用户点击查看全文时,向服务端发送新闻id - 后端根据新闻id查询完整新闻文章信息并返回 - 后端要同时让新闻的浏览量1 
接口描述 
url地址portal/showHeadlineDetail 
请求方式post 
请求参数: Param传参hid 
响应数据 
成功则 
{code:200,message:success,data:{headline:{hid:1,                     // 新闻id title:马斯克宣布 ... ...,   // 新闻标题article:... ...            // 新闻正文type:1,                    // 新闻所属类别编号typeName:科技,             // 新闻所属类别pageViews:40,              // 新闻浏览量pastHours:3 ,              // 发布时间已过小时数publisher:1 ,              // 发布用户IDauthor:张三                 // 新闻作者}}
}代码实现 controller  Overridepublic Result showHeadlineDetail(Integer hid) {/**注意响应的数据是双层嵌套,即data包裹headline,headline包含查询到的属性参数* 先用一个名为dataMap的Map以键值对的形式存储返回的属性参数* 再将名为data的Map是为一个值,搭配上名为headline的键* 存储进一个名为headlineMap的Map中,最终将Map作为参数传入Result,返回Result*/Map dataMap  headlineMapper.queryDetailMap(hid);Map headlineMap  new HashMap();headlineMap.put(headline,dataMap);/*乐观锁修改阅读量1*上面已经通过hid查到了所有信息,包括当时的版本号,假设是2* 将2直接赋值到新建的headline的Version中* 在最后一句update中,MP会帮我们检查,如果此时该条记录的版本号仍为2,* 则说明这段时间没有人修改过这条记录,可以正常修改*/Headline headline  new Headline();headline.setHid(hid);headline.setPageViews((Integer) headlineMap.get(pageViews)1); //阅读量1headline.setVersion((Integer) headlineMap.get(version)); //设置版本headlineMapper.updateById(headline);return Result.ok(headlineMap);}HeadlineMapper.java接口 
/*** 分页查询头条详情* param hid* return*/
Map selectDetailMap(Integer hid);mapperxml:!--    Map selectDetailMap(Integer hid);
查询目标(三表拼接):hid:1,                     // 新闻id title:马斯克宣布 ... ...,   // 新闻标题article:... ...            // 新闻正文type:1,                    // 新闻所属类别编号typeName:科技,             // 新闻所属类别pageViews:40,              // 新闻浏览量pastHours:3 ,              // 发布时间已过小时数publisher:1 ,              // 发布用户IDauthor:张三                 // 新闻作者--/*
left join news_type t on h.type  t.tid: 这是一个左连接将 news_headline 表与 news_type 表连接。
它的条件是 news_headline 表的 type 字段与 news_type 表的 tid 字段相匹配。
news_type中tid匹配的行会右拼接在headline表中left join news_user u on h.publisher  u.uid: 这也是一个左连接将 news_headline 表与 news_user 表连接。
连接条件是 news_headline 表的 publisher 字段与 news_user 表的 uid 字段相匹配。
news_user中tid匹配的行会右拼接在headline表中(headline先拼type,再拼user)左连接确保左表保留所有信息,右表仅提取符合条件的元素匹配左表
*/
select idselectDetailMap resultTypemapselect hid,title,article,type, h.version ,tname typeName ,page_views pageViews,TIMESTAMPDIFF(HOUR,create_time,NOW()) pastHours,publisher,nick_name author from news_headline hleft join news_type t on h.type  t.tidleft join news_user u  on h.publisher  u.uidwhere hid  #{hid}
/select