[javaweb]毕业设计基于Javaweb的宠物医院管理系统源码及其实现过程

主函数:

package com.pet.hospital;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import javax.sql.DataSource;

@SpringBootApplication
@MapperScan("com.pet.hospital.mapper")
public class HospitalApplication {

    public static void main(String[] args) {
        SpringApplication.run(HospitalApplication.class, args);
    }

}

上传控制器:

package com.pet.hospital.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.UUID;


@Controller
public class UploadController {

    @RequestMapping("/uploadImg")
    @ResponseBody
    public JSONObject uploadImg(MultipartFile file, HttpServletRequest request) throws Exception {
        JSONObject res = new JSONObject();
        JSONObject resUrl = new JSONObject();
        //判断文件是否为空
        if (file.isEmpty()) {
            System.out.println("图片为空");
        }
        String ext = FilenameUtils.getExtension(file.getOriginalFilename());
        String filename = UUID.randomUUID().toString().replaceAll("-", "") +"."+ ext;
        String pathName = "D:\\file\\" + filename;

        file.transferTo(new File(pathName));
        res.put("msg", "");
        res.put("code", 0);
        resUrl.put("src", "/pic/" + filename);
        res.put("data", resUrl);
        return res;
    }
}

 宠物控制器:

package com.pet.hospital.controller;

import com.github.pagehelper.PageInfo;
import com.pet.hospital.constants.SysConstant;
import com.pet.hospital.domain.Pet;
import com.pet.hospital.service.PetService;
import com.pet.hospital.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/pet")
public class PetController {

    @Autowired
    PetService petService;

    @RequestMapping("/add")
    @ResponseBody
    public R add(Pet pet) {

        int res = petService.add(pet);
        if (res != 0) {
            return R.exeSuccess();
        }
        return R.exeFail();
    }

    @RequestMapping("/list")
    @ResponseBody
    public R list(Pet pet, @RequestParam(required = false, defaultValue = "10") int limit, @RequestParam(required = false, defaultValue = "1") int page) {
        PageInfo<Pet> pageInfo = petService.list(pet, limit, page);
        if (pageInfo.getList() != null && pageInfo.getList().size() != 0) {
            return R.exeSuccess(pageInfo.getList(), pageInfo.getTotal());
        }
        return R.exeFail(SysConstant.queryFail);

    }

    @RequestMapping("/delete")
    @ResponseBody
    public R delete(String id) {
        if (id != null) {
            int res = petService.delete(id);
            if (res != 0) {
                return R.exeSuccess();
            }
        }
        return R.exeFail(SysConstant.parameterMsg);
    }

    @RequestMapping("/update")
    public String update(String id, Model model) {
        Pet pet = petService.update(id);
        model.addAttribute("pet", pet);
        return "pet/update";
    }

    @RequestMapping("/do_update")
    @ResponseBody
    public R doUpdate(Pet pet) {
        int res = petService.doUpdate(pet);
        if (res != 0) {
            return R.exeSuccess();
        }
        return R.exeFail();
    }
}

登录控制器:

package com.pet.hospital.controller;

import com.pet.hospital.constants.SysConstant;
import com.pet.hospital.domain.Account;
import com.pet.hospital.domain.Doctor;
import com.pet.hospital.service.AccountRelationService;
import com.pet.hospital.service.LoginService;
import com.pet.hospital.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@Controller
public class LoginController {

    @Autowired
    LoginService loginService;
    @Autowired
    AccountRelationService accountRelationService;

    @RequestMapping("/doLogin")
    @ResponseBody
    public R doLogin(Account account, HttpSession session) {
        Account res = loginService.doLogin(account);
        if (res != null) {
            if (SysConstant.accountDoctorType.equals(account.getIdentityId())) {
                //医生身份 保存session
                Long doctorId = accountRelationService.queryByAccountId(res.getId());
                if (doctorId != null && doctorId != 0) {
                    session.setAttribute("doctorId", doctorId);

                }
            }
            session.setAttribute("account", account.getAccount());
            return R.exeSuccess();
        }
        return R.exeFail();
    }

    @RequestMapping("/logout")
    public void logOut(HttpSession session, HttpServletRequest request, HttpServletResponse response){
        session.removeAttribute("account");
        try {
            request.getRequestDispatcher("/login").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

更多源码参考完整源码下载:

https://download.csdn.net/download/FL1768317420/89322325

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FL1768317420

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值