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

摘要

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

所用技术

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

后端:SpringBoot+Spring-Data-Jpa

安全控件:SpringSecurity

页面采用:Thymeleaf

项目管理:Maven

基本功能

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

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

部分代码展示

java 复制代码
@Controller
@RequestMapping(value="/blog")
public class BlogsController extends CommonController<Blogs, Integer, BlogsForm> {
	@Autowired
	private BlogsSerive blogService;
	@Autowired
	private SystemDataService dataService;
	@Autowired
	private UserUtils userUtils;
	@Autowired
	private CommentService commentService;
	
	@Override
	public void manage(ModelMap map) {
		map.put("user", userUtils.getUser());
		super.manage(map);
	}

	@Override
	public void edit(BlogsForm form, ModelMap map) throws InstantiationException, IllegalAccessException {
		map.put("sf", dataService.findByDictionariesCode("SJZD_BKFL"));
		map.put("type", dataService.findByDictionariesCode("SJZD_WZLX"));
		super.edit(form, map);
	}

	@Override
	public Object save(BlogsForm form) {
		System.out.println(form.getText()+"=========");
		form.setUser(userUtils.getUser());
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Blogs model = new Blogs();
			String name = userUtils.getName();
			Integer id = form.getId();
			if(id != null) {
				model = blogService.findById(id);
				model.setUpdateDate(sdf.format(new Date()));
				model.setUpdateName(name);
			}else {
				form.setCreateDate(sdf.format(new Date()));
				form.setCreateName(name);
				model.setUpdateDate(sdf.format(new Date()));
				model.setUpdateName(name);
			}
			BeanUtils.copyProperties(form, model,"id");
			blogService.save(model);
			Integer id2;
			if(form.getId() != null) {
				id2 = form.getId();
			}else {
				id2 = blogService.findByUserNicknameAndUpdateDate(name, model.getUpdateDate()).getId();
			}
			return new AjaxResult(id2+"");
		} catch (Exception e) {
			return new AjaxResult(false,"数据保存失败");
		}
	}
	
	/**
	 * 访问页面
	 * @param id
	 * @param map
	 */
	@RequestMapping(value="/visit")
	public void visit(Integer id, ModelMap map) {
		map.put("blog", blogService.findById(id));
		map.put("comment", commentService.findByBlogId(id));
	}

	/**
	 * 访问页面数据
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/blogText")
	@ResponseBody
	public Object blogText(Integer id) {
		return blogService.findById(id).getText();
	}
	
	@RequestMapping(value="/audit")
	public void audit(ModelMap map) {
		
	}
	
	@RequestMapping(value="/indexBlog")
	public void indexBlog() {
		
	}
	
	/**
	 * 同意
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/consent")
	@ResponseBody
	public Object consent(Integer id) {
		try {
			Blogs blogs = blogService.findById(id);
			blogs.setBlogStatic("审核通过");
			blogService.save(blogs);
			return new AjaxResult("同意成功");
		} catch (Exception e) {
			return new AjaxResult(false,"同意失败");
		}
	}
	
	/**
	 * 拒绝
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/refuse")
	@ResponseBody
	public Object refuse(Integer id, String jy) {
		try {
			Blogs blogs = blogService.findById(id);
			blogs.setBlogStatic("已拒绝");
			blogs.setSuggest(jy);
			blogService.save(blogs);
			return new AjaxResult("拒绝成功");
		} catch (Exception e) {
			return new AjaxResult(false,"拒绝失败");
		}
	}
	
	@RequestMapping(value="/fysj")
	@ResponseBody
	public Object fysj(Integer page, BlogsForm form) {
		Sort sort=Sort.by(Sort.Direction.DESC, "updateDate");
		Pageable pageable = PageRequest.of(page-1, 10, sort);
		Page<Blogs> blog;
		Specification<Blogs> spec = buildSpec2(form);
		blog = blogService.findAll(spec, pageable);
		return FlowloadUtils.buildResult(blog);
	}
	
	@RequestMapping(value="/fysj2")
	@ResponseBody
	public Object fysj2(Integer page, BlogsForm form) {
		Sort sort=Sort.by(Sort.Direction.DESC, "updateDate");
		Pageable pageable = PageRequest.of(page-1, 10, sort);
		Page<Blogs> blog;
		Specification<Blogs> spec = buildSpec3(form);
		blog = blogService.findAll(spec, pageable);
		return FlowloadUtils.buildResult(blog);
	}
	
	private Specification<Blogs> buildSpec3(BlogsForm form) {
		Specification<Blogs> specification = new Specification<Blogs>() {

			private static final long serialVersionUID = 1L;
			
			@Override
			public Predicate toPredicate(Root<Blogs> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				HashSet<Predicate> rules=new HashSet<>();
				Predicate difficultylevel = cb.equal(root.get("blogStatic"), "审核通过");
				rules.add(difficultylevel);
				return cb.and(rules.toArray(new Predicate[rules.size()]));
			}

		};
		return specification;
	}

	private Specification<Blogs> buildSpec2(BlogsForm form) {
		Specification<Blogs> specification = new Specification<Blogs>() {

			private static final long serialVersionUID = 1L;
			
			@Override
			public Predicate toPredicate(Root<Blogs> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				HashSet<Predicate> rules=new HashSet<>();
				SysUser user = userUtils.getUser();
				Predicate difficultylevel = cb.equal(root.get("user").get("id"), user.getId());
				rules.add(difficultylevel);
				return cb.and(rules.toArray(new Predicate[rules.size()]));
			}

		};
		return specification;
	}

	@RequestMapping(value="/page2")
	@ResponseBody
	public HashMap<String, Object> page2(ModelMap map, DataGridParam param, BlogsForm form) {
		Sort sort=Sort.by("id");
		Pageable pabeable = param.getPageable(sort);
		Specification<Blogs> spec = buildSpec1(form);
		Page<Blogs> page = blogService.findAll(spec, pabeable);
		return DataGridUtils.buildResult(page);
	}

	private Specification<Blogs> buildSpec1(BlogsForm form) {
		Specification<Blogs> specification = new Specification<Blogs>() {

			private static final long serialVersionUID = 1L;
			
			@Override
			public Predicate toPredicate(Root<Blogs> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				HashSet<Predicate> rules=new HashSet<>();
				Predicate difficultylevel = cb.like(root.get("blogStatic"), "%待审核%");
				rules.add(difficultylevel);
				return cb.and(rules.toArray(new Predicate[rules.size()]));
			}

		};
		return specification;
	}
	
	/**
	 * 评论
	 */
	@RequestMapping(value="/comment")
	@ResponseBody
	public Object comment(String comment, Integer id) {
		try {
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Comment model = new Comment();
			model.setText(comment);
			model.setUser(userUtils.getUser());
			model.setBlog(blogService.findById(id));
			model.setRead2(false);
			model.setCreateDate(sdf.format(new Date()));
			commentService.save(model);
			return new AjaxResult("评论成功");
		} catch (Exception e) {
			return new AjaxResult(false,"评论失败");
		}
	}
}

演示视频

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

相关推荐
小白学前端66641 分钟前
React Router 深入指南:从入门到进阶
前端·react.js·react
web130933203981 小时前
前端下载后端文件流,文件可以下载,但是打不开,显示“文件已损坏”的问题分析与解决方案
前端
学前端的小朱1 小时前
处理字体图标、js、html及其他资源
开发语言·javascript·webpack·html·打包工具
outstanding木槿1 小时前
react+antd的Table组件编辑单元格
前端·javascript·react.js·前端框架
好名字08212 小时前
前端取Content-Disposition中的filename字段与解码(vue)
前端·javascript·vue.js·前端框架
隐形喷火龙2 小时前
element ui--下拉根据拼音首字母过滤
前端·vue.js·ui
m0_748241122 小时前
Selenium之Web元素定位
前端·selenium·测试工具
风无雨2 小时前
react杂乱笔记(一)
前端·笔记·react.js
前端小魔女2 小时前
2024-我赚到自媒体第一桶金
前端·rust
鑫~阳3 小时前
快速建站(网站如何在自己的电脑里跑起来) 详细步骤 一
前端·内容管理系统cms