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;
    }

    }

  • 相关阅读:
    日志记录到txt文件
    使用NuGet安装EntityFramework4.2
    Redis 安装与简单示例 <第一篇>
    时间加减时间段(年、月、日、分、秒)
    控件属性设置
    window.showModalDialog 与window.open传递参数的不同?
    如何进行js动态生成option?如何实现二级连动?
    System.Data.SqlClient.SqlError: 备份集中的数据库备份与现有的 'XXX' 数据库不同
    如何激发手机的高分辨率
    PHP--正则表达式和样式匹配--小记
  • 原文地址:https://www.cnblogs.com/liuzhaolong/p/12874546.html
Copyright © 2011-2022 走看看