zoukankan      html  css  js  c++  java
  • 双表的增删改查-controller

    package com.lzl.controller;

    import java.io.IOException;
    import java.util.List;

    import org.apache.dubbo.config.annotation.Reference;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PostMapping;
    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.multipart.MultipartFile;

    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.JSONArray;
    import com.github.pagehelper.PageInfo;
    import com.lzl.pojo.Doctor;
    import com.lzl.service.DoctorService;


    @Controller
    public class DoctorController {

    @Reference
    DoctorService service;

    @RequestMapping("list")
    public String list(Model m,@RequestParam(defaultValue = "1")Integer pageNum,
    @RequestParam(defaultValue = "3")Integer pageSize,Doctor doctor) {

    PageInfo<Doctor> info = service.findAll(pageNum, pageSize, doctor);

    List<Doctor> list = service.findProvince();

    List<Doctor> findDepart = service.findDepart();
    m.addAttribute("info", info);
    m.addAttribute("province", list);
    m.addAttribute("listDepart", findDepart);
    m.addAttribute("doctor", doctor);


    return "list";
    }

    /**
    * 回显省市区
    * @param id
    * @return
    */
    @RequestMapping("city")
    @ResponseBody
    public JSONArray city(Integer id) {
    List<Doctor> list = service.findTown(id);
    return JSONArray.parseArray(JSON.toJSONString(list));
    }
    @GetMapping("add")
    public String getAdd(Model model) {
    //查找省
    List<Doctor> list = service.findProvince();
    //回显科室
    List<Doctor> listDepart = service.findDepart();
    //查到擅长所有的数据
    List<Doctor> shanchang = service.findByShanChang();
    model.addAttribute("province", list);
    model.addAttribute("listDepart", listDepart);
    model.addAttribute("shanchang", shanchang);
    return "add";
    }
    @PostMapping("add")
    @ResponseBody
    public int postAdd(Doctor doctor,MultipartFile file) {
    try {
    String processFile = FileUtils.processFile(file);
    doctor.setTouxiang(processFile);
    } catch (IllegalStateException | IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    int i = service.add(doctor);
    return i;

    }
    @GetMapping("update")
    public String getUpdate(Model model,Integer id) {
    //查找所有的数据
    Doctor doctor = service.findById(id);
    //查找省
    List<Doctor> list = service.findProvince();
    //回显科室
    List<Doctor> listDepart = service.findDepart();
    //查到擅长所有的数据
    List<Doctor> shanchang = service.findByShanChang();
    model.addAttribute("province", list);
    model.addAttribute("listDepart", listDepart);
    model.addAttribute("shanchang", shanchang);
    model.addAttribute("d", doctor);
    return "update";
    }
    @RequestMapping("update")
    @ResponseBody
    public int postUpdate(Doctor doctor,MultipartFile file) {
    try {
    String processFile = FileUtils.processFile(file);
    System.err.println(processFile);
    doctor.setTouxiang(processFile);
    System.err.println(doctor);

    } catch (IllegalStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    int i = service.update(doctor);
    return i;
    }

    }

  • 相关阅读:
    你知道线程池是如何退出程序的吗?
    华为云GuassDB(for Redis)发布全新版本推出:Lua脚本和SSL连接加密
    分布式消息流平台:不要只想着Kafka,还有Pulsar
    新来的前端小姐姐问:Vue路由history模式刷新页面出现404问题
    1ms的时延,10Gbps速率…5G通信技术解读
    一分钟带你了解Huawei LiteOS组件开发指南
    资深Linux 系统管理员常用的15个很好用的Cron工作示例
    C语言中动态内存分配的本质是什么?
    Python连载8datetime包函数介绍 心悦君兮君不知
    Python连载7time包的其他函数 心悦君兮君不知
  • 原文地址:https://www.cnblogs.com/liuzhaolong/p/12874546.html
Copyright © 2011-2022 走看看