• 基于JAVA SpringBoot和HTML美食网站博客程序设计


    摘要

            美食网站是一个提供各种美食信息和食谱的网站,旨在帮助用户发现、学习和分享美食。旨在探讨美食网站在现代社会中的重要性和影响。随着互联网的普及,越来越多的人开始使用美食网站来获取各种美食信息和食谱。这些网站不仅提供了方便快捷的搜索功能,还为用户提供了分享和交流的平台。随着移动互联网的发展,美食网站应该更加注重用户体验和个性化服务,提供更加精准的推荐和定制化的功能。同时,美食网站也应该加强与餐饮业的合作,推动餐饮业的创新和发展。总之,美食网站为用户提供了一个全面了解和学习美食的平台,帮助他们发现新的食谱、餐厅和烹饪技巧,享受美食带来的乐趣。

    所用技术

    前端:LayUI、JQuery、HTML5+CSS3、Ajax

    后端:SpringBoot+Spring-Data-Jpa

    安全控件:SpringSecurity

    页面采用:Thymeleaf

    项目管理:Maven

    基本功能

    拥有管理员和普通用户两种角色;

    注册、登录、发美食博客、查看美食博客、美食博客审核(管理员)、个人资料设置、密码修改、权限修改(管理员)等。

    部分代码展示

    1. @Controller
    2. @RequestMapping(value="/blog")
    3. public class BlogsController extends CommonController {
    4. @Autowired
    5. private BlogsSerive blogService;
    6. @Autowired
    7. private SystemDataService dataService;
    8. @Autowired
    9. private UserUtils userUtils;
    10. @Autowired
    11. private CommentService commentService;
    12. @Override
    13. public void manage(ModelMap map) {
    14. map.put("user", userUtils.getUser());
    15. super.manage(map);
    16. }
    17. @Override
    18. public void edit(BlogsForm form, ModelMap map) throws InstantiationException, IllegalAccessException {
    19. map.put("sf", dataService.findByDictionariesCode("SJZD_BKFL"));
    20. map.put("type", dataService.findByDictionariesCode("SJZD_WZLX"));
    21. super.edit(form, map);
    22. }
    23. @Override
    24. public Object save(BlogsForm form) {
    25. System.out.println(form.getText()+"=========");
    26. form.setUser(userUtils.getUser());
    27. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    28. try {
    29. Blogs model = new Blogs();
    30. String name = userUtils.getName();
    31. Integer id = form.getId();
    32. if(id != null) {
    33. model = blogService.findById(id);
    34. model.setUpdateDate(sdf.format(new Date()));
    35. model.setUpdateName(name);
    36. }else {
    37. form.setCreateDate(sdf.format(new Date()));
    38. form.setCreateName(name);
    39. model.setUpdateDate(sdf.format(new Date()));
    40. model.setUpdateName(name);
    41. }
    42. BeanUtils.copyProperties(form, model,"id");
    43. blogService.save(model);
    44. Integer id2;
    45. if(form.getId() != null) {
    46. id2 = form.getId();
    47. }else {
    48. id2 = blogService.findByUserNicknameAndUpdateDate(name, model.getUpdateDate()).getId();
    49. }
    50. return new AjaxResult(id2+"");
    51. } catch (Exception e) {
    52. return new AjaxResult(false,"数据保存失败");
    53. }
    54. }
    55. /**
    56. * 访问页面
    57. * @param id
    58. * @param map
    59. */
    60. @RequestMapping(value="/visit")
    61. public void visit(Integer id, ModelMap map) {
    62. map.put("blog", blogService.findById(id));
    63. map.put("comment", commentService.findByBlogId(id));
    64. }
    65. /**
    66. * 访问页面数据
    67. * @param id
    68. * @return
    69. */
    70. @RequestMapping(value="/blogText")
    71. @ResponseBody
    72. public Object blogText(Integer id) {
    73. return blogService.findById(id).getText();
    74. }
    75. @RequestMapping(value="/audit")
    76. public void audit(ModelMap map) {
    77. }
    78. @RequestMapping(value="/indexBlog")
    79. public void indexBlog() {
    80. }
    81. /**
    82. * 同意
    83. * @param id
    84. * @return
    85. */
    86. @RequestMapping(value="/consent")
    87. @ResponseBody
    88. public Object consent(Integer id) {
    89. try {
    90. Blogs blogs = blogService.findById(id);
    91. blogs.setBlogStatic("审核通过");
    92. blogService.save(blogs);
    93. return new AjaxResult("同意成功");
    94. } catch (Exception e) {
    95. return new AjaxResult(false,"同意失败");
    96. }
    97. }
    98. /**
    99. * 拒绝
    100. * @param id
    101. * @return
    102. */
    103. @RequestMapping(value="/refuse")
    104. @ResponseBody
    105. public Object refuse(Integer id, String jy) {
    106. try {
    107. Blogs blogs = blogService.findById(id);
    108. blogs.setBlogStatic("已拒绝");
    109. blogs.setSuggest(jy);
    110. blogService.save(blogs);
    111. return new AjaxResult("拒绝成功");
    112. } catch (Exception e) {
    113. return new AjaxResult(false,"拒绝失败");
    114. }
    115. }
    116. @RequestMapping(value="/fysj")
    117. @ResponseBody
    118. public Object fysj(Integer page, BlogsForm form) {
    119. Sort sort=Sort.by(Sort.Direction.DESC, "updateDate");
    120. Pageable pageable = PageRequest.of(page-1, 10, sort);
    121. Page blog;
    122. Specification spec = buildSpec2(form);
    123. blog = blogService.findAll(spec, pageable);
    124. return FlowloadUtils.buildResult(blog);
    125. }
    126. @RequestMapping(value="/fysj2")
    127. @ResponseBody
    128. public Object fysj2(Integer page, BlogsForm form) {
    129. Sort sort=Sort.by(Sort.Direction.DESC, "updateDate");
    130. Pageable pageable = PageRequest.of(page-1, 10, sort);
    131. Page blog;
    132. Specification spec = buildSpec3(form);
    133. blog = blogService.findAll(spec, pageable);
    134. return FlowloadUtils.buildResult(blog);
    135. }
    136. private Specification buildSpec3(BlogsForm form) {
    137. Specification specification = new Specification() {
    138. private static final long serialVersionUID = 1L;
    139. @Override
    140. public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) {
    141. HashSet rules=new HashSet<>();
    142. Predicate difficultylevel = cb.equal(root.get("blogStatic"), "审核通过");
    143. rules.add(difficultylevel);
    144. return cb.and(rules.toArray(new Predicate[rules.size()]));
    145. }
    146. };
    147. return specification;
    148. }
    149. private Specification buildSpec2(BlogsForm form) {
    150. Specification specification = new Specification() {
    151. private static final long serialVersionUID = 1L;
    152. @Override
    153. public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) {
    154. HashSet rules=new HashSet<>();
    155. SysUser user = userUtils.getUser();
    156. Predicate difficultylevel = cb.equal(root.get("user").get("id"), user.getId());
    157. rules.add(difficultylevel);
    158. return cb.and(rules.toArray(new Predicate[rules.size()]));
    159. }
    160. };
    161. return specification;
    162. }
    163. @RequestMapping(value="/page2")
    164. @ResponseBody
    165. public HashMap page2(ModelMap map, DataGridParam param, BlogsForm form) {
    166. Sort sort=Sort.by("id");
    167. Pageable pabeable = param.getPageable(sort);
    168. Specification spec = buildSpec1(form);
    169. Page page = blogService.findAll(spec, pabeable);
    170. return DataGridUtils.buildResult(page);
    171. }
    172. private Specification buildSpec1(BlogsForm form) {
    173. Specification specification = new Specification() {
    174. private static final long serialVersionUID = 1L;
    175. @Override
    176. public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) {
    177. HashSet rules=new HashSet<>();
    178. Predicate difficultylevel = cb.like(root.get("blogStatic"), "%待审核%");
    179. rules.add(difficultylevel);
    180. return cb.and(rules.toArray(new Predicate[rules.size()]));
    181. }
    182. };
    183. return specification;
    184. }
    185. /**
    186. * 评论
    187. */
    188. @RequestMapping(value="/comment")
    189. @ResponseBody
    190. public Object comment(String comment, Integer id) {
    191. try {
    192. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    193. Comment model = new Comment();
    194. model.setText(comment);
    195. model.setUser(userUtils.getUser());
    196. model.setBlog(blogService.findById(id));
    197. model.setRead2(false);
    198. model.setCreateDate(sdf.format(new Date()));
    199. commentService.save(model);
    200. return new AjaxResult("评论成功");
    201. } catch (Exception e) {
    202. return new AjaxResult(false,"评论失败");
    203. }
    204. }
    205. }

    演示视频

    基于JAVA SpringBoot和HTML美食网站博客程序

  • 相关阅读:
    2023年煤气证模拟考试题库及煤气理论考试试题
    PHP基于thinkphp的在线教学网站#毕业设计
    【CSS】实现垂直居中
    RabbitMQ(控制台模拟收发消息与数据隔离)
    Educational Codeforces Round 166 (Rated for Div. 2)题解(A,B,D)
    Redis五大基本数据类型的基本命令
    Linux之grep风骚用法
    部署LVS-DR群集
    jenkins实践篇(2)—— 自动打tag的可回滚发布模式
    深剖数商云B2B电商交易系统营销应用场景,赋能医疗器械企业实现精细化运营
  • 原文地址:https://blog.csdn.net/qq_28245905/article/details/134413675