首页 > 分享 > 基于Spring Boot的宠物健康咨询系统的设计与实现

基于Spring Boot的宠物健康咨询系统的设计与实现

目录

前言

 一、技术栈

二、系统功能介绍

管理员功能模块的实现

宠物健康知识列表

公告信息管理

公告类型管理

用户管理

健康知识类型管理

三、核心代码

1、登录模块

 2、文件上传模块

3、代码封装

前言

传统信息的管理大部分依赖于管理人员的手工登记与管理,然而,随着近些年信息技术的迅猛发展,让许多比较老套的信息管理模式进行了更新迭代,宠物健康知识信息因为其管理内容繁杂,管理数量繁多导致手工进行处理不能满足广大用户的需求,因此就应运而生出相应的宠物健康咨询系统。

本宠物健康咨询系统分为管理员还有用户两个权限,管理员可以管理用户的基本信息内容,可以管理公告信息以及宠物健康知识信息,能够与用户进行相互交流等操作,用户可以查看宠物健康知识信息,可以查看公告以及查看管理员回复信息等操作。

该宠物健康咨询系统采用的是WEB应用程序开发中最受欢迎的小程序结构模式,使用占用空间小但功能齐全的MySQL数据库进行数据的存储操作,系统开发技术使用到了JSP技术。该宠物健康咨询系统能够解决许多传统手工操作的难题,比如数据查询耽误时间长,数据管理步骤繁琐等问题。总的来说,宠物健康咨询系统性能稳定,功能较全,投入运行使用性价比很高。

 一、技术栈

末尾获取源码
Spring Boot+JS+ jQuery+Ajax...

二、系统功能介绍

管理员功能模块的实现

宠物健康知识列表

如图5.1显示的就是宠物健康知识列表页面,此页面提供给管理员的功能有:查看宠物健康知识、新增宠物健康知识、修改宠物健康知识、删除宠物健康知识等。

 

公告信息管理

管理员可以对公告信息进行管理,可以新增公告信息,修改公告信息,删除无效的公告信息。公告信息管理界面如图5.2所示。

 

公告类型管理

公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。下图就是公告类型管理页面。公告类型管理界面如图5.3所示。

 

用户管理

如图5.4显示的就是用户管理页面,此页面提供给管理员的功能有:新增用户,修改用户,删除用户。

 

健康知识类型管理

如图5.5显示的就是健康知识类型管理页面,此页面提供给管理员的功能有:新增健康知识类型,修改健康知识类型,删除健康知识类型。

 

三、核心代码

1、登录模块

package com.controller;

import java.util.Arrays;

import java.util.Calendar;

import java.util.Date;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.bind.annotation.RestController;

import com.annotation.IgnoreAuth;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import com.entity.TokenEntity;

import com.entity.UserEntity;

import com.service.TokenService;

import com.service.UserService;

import com.utils.CommonUtil;

import com.utils.MD5Util;

import com.utils.MPUtil;

import com.utils.PageUtils;

import com.utils.R;

import com.utils.ValidatorUtils;

@RequestMapping("users")

@RestController

public class UserController{

@Autowired

private UserService userService;

@Autowired

private TokenService tokenService;

@IgnoreAuth

@PostMapping(value = "/login")

public R login(String username, String password, String captcha, HttpServletRequest request) {

UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));

if(user==null || !user.getPassword().equals(password)) {

return R.error("账号或密码不正确");

}

String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());

return R.ok().put("token", token);

}

@IgnoreAuth

@PostMapping(value = "/register")

public R register(@RequestBody UserEntity user){

if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {

return R.error("用户已存在");

}

userService.insert(user);

return R.ok();

}

@GetMapping(value = "logout")

public R logout(HttpServletRequest request) {

request.getSession().invalidate();

return R.ok("退出成功");

}

@IgnoreAuth

@RequestMapping(value = "/resetPass")

public R resetPass(String username, HttpServletRequest request){

UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));

if(user==null) {

return R.error("账号不存在");

}

user.setPassword("123456");

userService.update(user,null);

return R.ok("密码已重置为:123456");

}

@RequestMapping("/page")

public R page(@RequestParam Map<String, Object> params,UserEntity user){

EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();

PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));

return R.ok().put("data", page);

}

@RequestMapping("/list")

public R list( UserEntity user){

EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();

ew.allEq(MPUtil.allEQMapPre( user, "user"));

return R.ok().put("data", userService.selectListView(ew));

}

@RequestMapping("/info/{id}")

public R info(@PathVariable("id") String id){

UserEntity user = userService.selectById(id);

return R.ok().put("data", user);

}

@RequestMapping("/session")

public R getCurrUser(HttpServletRequest request){

Long id = (Long)request.getSession().getAttribute("userId");

UserEntity user = userService.selectById(id);

return R.ok().put("data", user);

}

@PostMapping("/save")

public R save(@RequestBody UserEntity user){

if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {

return R.error("用户已存在");

}

userService.insert(user);

return R.ok();

}

@RequestMapping("/update")

public R update(@RequestBody UserEntity user){

userService.updateById(user);

return R.ok();

}

@RequestMapping("/delete")

public R delete(@RequestBody Long[] ids){

userService.deleteBatchIds(Arrays.asList(ids));

return R.ok();

}

}

 2、文件上传模块

package com.controller;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Arrays;

import java.util.Date;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Random;

import java.util.UUID;

import org.apache.commons.io.FileUtils;

import org.apache.commons.lang3.StringUtils;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.HttpHeaders;

import org.springframework.http.HttpStatus;

import org.springframework.http.MediaType;

import org.springframework.http.ResponseEntity;

import org.springframework.util.ResourceUtils;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.multipart.MultipartFile;

import com.annotation.IgnoreAuth;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import com.entity.ConfigEntity;

import com.entity.EIException;

import com.service.ConfigService;

import com.utils.R;

@RestController

@RequestMapping("file")

@SuppressWarnings({"unchecked","rawtypes"})

public class FileController{

@Autowired

private ConfigService configService;

@RequestMapping("/upload")

public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {

if (file.isEmpty()) {

throw new EIException("上传文件不能为空");

}

String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);

File path = new File(ResourceUtils.getURL("classpath:static").getPath());

if(!path.exists()) {

path = new File("");

}

File upload = new File(path.getAbsolutePath(),"/upload/");

if(!upload.exists()) {

upload.mkdirs();

}

String fileName = new Date().getTime()+"."+fileExt;

File dest = new File(upload.getAbsolutePath()+"/"+fileName);

file.transferTo(dest);

FileUtils.copyFile(dest, new File("C:UsersDesktopjiadianspringbootl7ownsrcmainresourcesstaticupload"+"/"+fileName));

if(StringUtils.isNotBlank(type) && type.equals("1")) {

ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));

if(configEntity==null) {

configEntity = new ConfigEntity();

configEntity.setName("faceFile");

configEntity.setValue(fileName);

} else {

configEntity.setValue(fileName);

}

configService.insertOrUpdate(configEntity);

}

return R.ok().put("file", fileName);

}

@IgnoreAuth

@RequestMapping("/download")

public ResponseEntity<byte[]> download(@RequestParam String fileName) {

try {

File path = new File(ResourceUtils.getURL("classpath:static").getPath());

if(!path.exists()) {

path = new File("");

}

File upload = new File(path.getAbsolutePath(),"/upload/");

if(!upload.exists()) {

upload.mkdirs();

}

File file = new File(upload.getAbsolutePath()+"/"+fileName);

if(file.exists()){

HttpHeaders headers = new HttpHeaders();

headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);

headers.setContentDispositionFormData("attachment", fileName);

return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);

}

} catch (IOException e) {

e.printStackTrace();

}

return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);

}

}

3、代码封装

package com.utils;

import java.util.HashMap;

import java.util.Map;

public class R extends HashMap<String, Object> {

private static final long serialVersionUID = 1L;

public R() {

put("code", 0);

}

public static R error() {

return error(500, "未知异常,请联系管理员");

}

public static R error(String msg) {

return error(500, msg);

}

public static R error(int code, String msg) {

R r = new R();

r.put("code", code);

r.put("msg", msg);

return r;

}

public static R ok(String msg) {

R r = new R();

r.put("msg", msg);

return r;

}

public static R ok(Map<String, Object> map) {

R r = new R();

r.putAll(map);

return r;

}

public static R ok() {

return new R();

}

public R put(String key, Object value) {

super.put(key, value);

return this;

}

}

相关知识

基于spring boot和vue的宠物相亲网站的设计与实现
【2024】Springboot源码之宠物健康咨询系统的设计与实现
构建便捷高效的宠物医疗预约服务平台:基于Spring Boot的实现本文介绍了基于Spring Boot的宠物医疗预约服
构建便捷高效的宠物医疗预约服务平台:基于Spring Boot的实现
基于Spring Boot的宠物健康咨询系统的设计与实现
java毕业设计基于微信小程序的宠物中心系统的设计与实现[附源码]
基于springboot实现宠物咖啡馆平台管理系统项目【项目源码+论文说明】计算机毕业设计
【2024】基于springboot的宠物领养管理系统设计与实现研究思路
基于java的宠物管理系统设计与实现
基于Springboot宠物健康咨询系统的设计与实现

网址: 基于Spring Boot的宠物健康咨询系统的设计与实现 https://m.mcbbbk.com/newsview90591.html

所属分类:萌宠日常
上一篇: DNF:11号金币活动现惊喜!3
下一篇: 社区楼下的萌宠一站式呵护站…深圳