ssm框架下如何统计某个页面的浏览量
介绍
这是我自己觉得这样写思路可简单,但是代码可多,我们只需要在建表是加一个字段来统计数量默认值设为零,然后每次访问网页时,先获取当前的点击量,然后更新点击量即可
相关代码
mapper中
<!-- 菜谱点击量 -->
<update id="recipeQuick">
update recipe
set quick = #{arg0}
where id = #{arg1}
</update>
<!-- 得到当前菜谱点击量 -->
<select id="getRecipeQuick" resultType="Integer">
select quick
from recipe
where id = #{id}
</select>
dao层
//增加菜品点击量 id为菜谱id
Integer recipeQuick(Integer quick,Integer id);
//得到当前点击量
Integer getRecipeQuick(Integer id);
service层与dao层代码一样
serviceimpl层只需要调用dao层方法即可
最后controller层
//取出某一菜谱 ??有bug
@ApiOperation("取出某一菜谱")
@CrossOrigin
@ResponseBody
@GetMapping("/getOneRecipe")
public BaseResponse getOneRecipe(Integer id) {
Integer recipeQuick = recipeService.getRecipeQuick(id);
recipeService.recipeQuick(recipeQuick + 1, id);
Recipe recipe = recipeService.selectRecipeByID(id);
List<Meterial> meterialById = meterialService.getMeterialById(id);
List<Step> steps = stepService.selectStepById(id);
if (recipe != null) {
Map<String, Object> map = new HashMap<>();
map.put("recipe", recipe);
map.put("meterial", meterialById);
map.put("step", steps);
return BaseResponse.success("", map);
} else {
return BaseResponse.error("菜谱不存在!");
}
}
干项目,冲冲冲!!!