赞
踩
最近帮小伙伴做了个基于SpringBoot和协同过滤算法的体育商城系统。
现如今后台开源框架主流的有SSH、SSM、SpringBoot,但是SSH、SSM框架的环境配置项较多,而SpringBoot主要的设计思想就是约定大于配置,故而SpingBoot在设计时几乎达到零配置。SpringBoot整合了业界上的开源框架。具体采用技术框架描述如下:
(1)Mybatis:Mybatis:提供自动映射,动态SQL,级联,缓存,注解,代码和SQL分离等特性,使用方便,同时也对SQL进行优化。
(2)SpringMVC:通过一套MVC注解,让POJO成为处理请求的控制器,无需实现任何接口,同时,SpringMVC还支持REST风格的URL请求。
(3)SpringBoot:从本质上来说,Spring Boot就是Spring,它做了那些没有它你也会去做的Spring Bean配置。
SpringBoot是一款非常强大后台框架,因为SpringBoot开发时可以基本不用写配置文件,所以使用SpringBoot搭建网站的后台环境,在SpringBoot的yml配置文件中写入项目启动端口,项目就可以启动。项目的Java文件还有静态文件都是由SpringBoot来管理。
协同过滤算法常用于推荐,根据用户的喜好或者兴趣进行推荐。是基于邻域的方法,而这种方法主要有两种算法:基于用户的协同过滤算法(给用户推荐和他兴趣相似的其他用户喜欢的产品)和基于物品的协同过滤算法(给用户推荐和他之前喜欢的物品相似的物品)。
系统的功能如下所示:
@RestController @RequestMapping("/aboutus") public class AboutusController { @Autowired private AboutusService aboutusService; /** * 后端列表 */ @RequestMapping("/page") public R page(@RequestParam Map<String, Object> params,AboutusEntity aboutus, HttpServletRequest request){ EntityWrapper<AboutusEntity> ew = new EntityWrapper<AboutusEntity>(); PageUtils page = aboutusService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, aboutus), params), params)); return R.ok().put("data", page); } /** * 前端列表 */ @IgnoreAuth @RequestMapping("/list") public R list(@RequestParam Map<String, Object> params,AboutusEntity aboutus, HttpServletRequest request){ EntityWrapper<AboutusEntity> ew = new EntityWrapper<AboutusEntity>(); PageUtils page = aboutusService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, aboutus), params), params)); return R.ok().put("data", page); } /** * 列表 */ @RequestMapping("/lists") public R list( AboutusEntity aboutus){ EntityWrapper<AboutusEntity> ew = new EntityWrapper<AboutusEntity>(); ew.allEq(MPUtil.allEQMapPre( aboutus, "aboutus")); return R.ok().put("data", aboutusService.selectListView(ew)); } /** * 查询 */ @RequestMapping("/query") public R query(AboutusEntity aboutus){ EntityWrapper< AboutusEntity> ew = new EntityWrapper< AboutusEntity>(); ew.allEq(MPUtil.allEQMapPre( aboutus, "aboutus")); AboutusView aboutusView = aboutusService.selectView(ew); return R.ok("查询关于我们成功").put("data", aboutusView); } /** * 后端详情 */ @RequestMapping("/info/{id}") public R info(@PathVariable("id") Long id){ AboutusEntity aboutus = aboutusService.selectById(id); return R.ok().put("data", aboutus); } /** * 前端详情 */ @IgnoreAuth @RequestMapping("/detail/{id}") public R detail(@PathVariable("id") Long id){ AboutusEntity aboutus = aboutusService.selectById(id); return R.ok().put("data", aboutus); } /** * 后端保存 */ @RequestMapping("/save") public R save(@RequestBody AboutusEntity aboutus, HttpServletRequest request){ aboutus.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); //ValidatorUtils.validateEntity(aboutus); aboutusService.insert(aboutus); return R.ok(); } /** * 前端保存 */ @RequestMapping("/add") public R add(@RequestBody AboutusEntity aboutus, HttpServletRequest request){ aboutus.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); //ValidatorUtils.validateEntity(aboutus); aboutusService.insert(aboutus); return R.ok(); } /** * 修改 */ @RequestMapping("/update") @Transactional public R update(@RequestBody AboutusEntity aboutus, HttpServletRequest request){ //ValidatorUtils.validateEntity(aboutus); aboutusService.updateById(aboutus);//全部更新 return R.ok(); } /** * 删除 */ @RequestMapping("/delete") public R delete(@RequestBody Long[] ids){ aboutusService.deleteBatchIds(Arrays.asList(ids)); return R.ok(); } /** * 提醒接口 */ @RequestMapping("/remind/{columnName}/{type}") public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, @PathVariable("type") String type,@RequestParam Map<String, Object> map) { map.put("column", columnName); map.put("type", type); if(type.equals("2")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); Date remindStartDate = null; Date remindEndDate = null; if(map.get("remindstart")!=null) { Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH,remindStart); remindStartDate = c.getTime(); map.put("remindstart", sdf.format(remindStartDate)); } if(map.get("remindend")!=null) { Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH,remindEnd); remindEndDate = c.getTime(); map.put("remindend", sdf.format(remindEndDate)); } } Wrapper<AboutusEntity> wrapper = new EntityWrapper<AboutusEntity>(); if(map.get("remindstart")!=null) { wrapper.ge(columnName, map.get("remindstart")); } if(map.get("remindend")!=null) { wrapper.le(columnName, map.get("remindend")); } int count = aboutusService.selectCount(wrapper); return R.ok().put("count", count); }
@RestController @RequestMapping("/cart") public class CartController { @Autowired private CartService cartService; /** * 后端列表 */ @RequestMapping("/page") public R page(@RequestParam Map<String, Object> params,CartEntity cart, HttpServletRequest request){ if(!request.getSession().getAttribute("role").toString().equals("管理员")) { cart.setUserid((Long)request.getSession().getAttribute("userId")); } EntityWrapper<CartEntity> ew = new EntityWrapper<CartEntity>(); PageUtils page = cartService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, cart), params), params)); return R.ok().put("data", page); } /** * 前端列表 */ @IgnoreAuth @RequestMapping("/list") public R list(@RequestParam Map<String, Object> params,CartEntity cart, HttpServletRequest request){ EntityWrapper<CartEntity> ew = new EntityWrapper<CartEntity>(); PageUtils page = cartService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, cart), params), params)); return R.ok().put("data", page); } /** * 列表 */ @RequestMapping("/lists") public R list( CartEntity cart){ EntityWrapper<CartEntity> ew = new EntityWrapper<CartEntity>(); ew.allEq(MPUtil.allEQMapPre( cart, "cart")); return R.ok().put("data", cartService.selectListView(ew)); } /** * 查询 */ @RequestMapping("/query") public R query(CartEntity cart){ EntityWrapper< CartEntity> ew = new EntityWrapper< CartEntity>(); ew.allEq(MPUtil.allEQMapPre( cart, "cart")); CartView cartView = cartService.selectView(ew); return R.ok("查询购物车表成功").put("data", cartView); } /** * 后端详情 */ @RequestMapping("/info/{id}") public R info(@PathVariable("id") Long id){ CartEntity cart = cartService.selectById(id); return R.ok().put("data", cart); } /** * 前端详情 */ @IgnoreAuth @RequestMapping("/detail/{id}") public R detail(@PathVariable("id") Long id){ CartEntity cart = cartService.selectById(id); return R.ok().put("data", cart); } /** * 后端保存 */ @RequestMapping("/save") public R save(@RequestBody CartEntity cart, HttpServletRequest request){ cart.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); //ValidatorUtils.validateEntity(cart); cart.setUserid((Long)request.getSession().getAttribute("userId")); cartService.insert(cart); return R.ok(); } /** * 前端保存 */ @RequestMapping("/add") public R add(@RequestBody CartEntity cart, HttpServletRequest request){ cart.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); //ValidatorUtils.validateEntity(cart); cartService.insert(cart); return R.ok(); } /** * 修改 */ @RequestMapping("/update") @Transactional public R update(@RequestBody CartEntity cart, HttpServletRequest request){ //ValidatorUtils.validateEntity(cart); cartService.updateById(cart);//全部更新 return R.ok(); } /** * 删除 */ @RequestMapping("/delete") public R delete(@RequestBody Long[] ids){ cartService.deleteBatchIds(Arrays.asList(ids)); return R.ok(); } /** * 提醒接口 */ @RequestMapping("/remind/{columnName}/{type}") public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, @PathVariable("type") String type,@RequestParam Map<String, Object> map) { map.put("column", columnName); map.put("type", type); if(type.equals("2")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); Date remindStartDate = null; Date remindEndDate = null; if(map.get("remindstart")!=null) { Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH,remindStart); remindStartDate = c.getTime(); map.put("remindstart", sdf.format(remindStartDate)); } if(map.get("remindend")!=null) { Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH,remindEnd); remindEndDate = c.getTime(); map.put("remindend", sdf.format(remindEndDate)); } } Wrapper<CartEntity> wrapper = new EntityWrapper<CartEntity>(); if(map.get("remindstart")!=null) { wrapper.ge(columnName, map.get("remindstart")); } if(map.get("remindend")!=null) { wrapper.le(columnName, map.get("remindend")); } if(!request.getSession().getAttribute("role").toString().equals("管理员")) { wrapper.eq("userid", (Long)request.getSession().getAttribute("userId")); } int count = cartService.selectCount(wrapper); return R.ok().put("count", count); }
@RestController public class CommonController{ @Autowired private CommonService commonService; private static AipFace client = null; @Autowired private ConfigService configService; /** * 获取table表中的column列表(联动接口) * @param table * @param column * @return */ @IgnoreAuth @RequestMapping("/option/{tableName}/{columnName}") public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,@RequestParam(required = false) String conditionColumn,@RequestParam(required = false) String conditionValue,String level,String parent) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("column", columnName); if(StringUtils.isNotBlank(level)) { params.put("level", level); } if(StringUtils.isNotBlank(parent)) { params.put("parent", parent); } if(StringUtils.isNotBlank(conditionColumn)) { params.put("conditionColumn", conditionColumn); } if(StringUtils.isNotBlank(conditionValue)) { params.put("conditionValue", conditionValue); } List<String> data = commonService.getOption(params); return R.ok().put("data", data); } /** * 根据table中的column获取单条记录 * @param table * @param column * @return */ @IgnoreAuth @RequestMapping("/follow/{tableName}/{columnName}") public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("column", columnName); params.put("columnValue", columnValue); Map<String, Object> result = commonService.getFollowByOption(params); return R.ok().put("data", result); } /** * 修改table表的sfsh状态 * @param table * @param map * @return */ @RequestMapping("/sh/{tableName}") public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) { map.put("table", tableName); commonService.sh(map); return R.ok(); } /** * 获取需要提醒的记录数 * @param tableName * @param columnName * @param type 1:数字 2:日期 * @param map * @return */ @IgnoreAuth @RequestMapping("/remind/{tableName}/{columnName}/{type}") public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @PathVariable("type") String type,@RequestParam Map<String, Object> map) { map.put("table", tableName); map.put("column", columnName); map.put("type", type); if(type.equals("2")) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); Date remindStartDate = null; Date remindEndDate = null; if(map.get("remindstart")!=null) { Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH,remindStart); remindStartDate = c.getTime(); map.put("remindstart", sdf.format(remindStartDate)); } if(map.get("remindend")!=null) { Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH,remindEnd); remindEndDate = c.getTime(); map.put("remindend", sdf.format(remindEndDate)); } } int count = commonService.remindCount(map); return R.ok().put("count", count); } /** * 单列求和 */ @IgnoreAuth @RequestMapping("/cal/{tableName}/{columnName}") public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("column", columnName); Map<String, Object> result = commonService.selectCal(params); return R.ok().put("data", result); } /** * 分组统计 */ @IgnoreAuth @RequestMapping("/group/{tableName}/{columnName}") public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("column", columnName); List<Map<String, Object>> result = commonService.selectGroup(params); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for(Map<String, Object> m : result) { for(String k : m.keySet()) { if(m.get(k) instanceof Date) { m.put(k, sdf.format((Date)m.get(k))); } } } return R.ok().put("data", result); } /** * (按值统计) */ @IgnoreAuth @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}") public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("xColumn", xColumnName); params.put("yColumn", yColumnName); List<Map<String, Object>> result = commonService.selectValue(params); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for(Map<String, Object> m : result) { for(String k : m.keySet()) { if(m.get(k) instanceof Date) { m.put(k, sdf.format((Date)m.get(k))); } } } return R.ok().put("data", result); } /** * (按值统计)时间统计类型 */ @IgnoreAuth @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}/{timeStatType}") public R valueDay(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("xColumn", xColumnName); params.put("yColumn", yColumnName); params.put("timeStatType", timeStatType); List<Map<String, Object>> result = commonService.selectTimeStatValue(params); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for(Map<String, Object> m : result) { for(String k : m.keySet()) { if(m.get(k) instanceof Date) { m.put(k, sdf.format((Date)m.get(k))); } } } return R.ok().put("data", result); }
我是程序员小孟,感谢点赞关注!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。