首页>代码>SpringBoot整合MyBatis实现记录孩子成长过程的博客系统>/babylog/src/main/java/net/vv2/admin/web/AdminHealthyController.java
package net.vv2.admin.web;

import com.xiaoleilu.hutool.date.DateUtil;
import net.vv2.baby.domain.Baby;
import net.vv2.baby.domain.Healthy;
import net.vv2.baby.service.impl.BabyServiceImpl;
import net.vv2.baby.service.impl.HealthyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author J.Sky bosichong@qq.com
 * @create 2017-06-21 20:50
 **/
@Controller
@RequestMapping("/admin/healthy")
public class AdminHealthyController {
    @Autowired
    private HealthyServiceImpl healthyService;
    @Autowired
    private BabyServiceImpl babyService;


    /**
     * 列表页
     * @param model
     * @return
     */
    @RequestMapping("/healthyList")
    public String healthyList(Model model){
        List<Healthy> list = healthyService.selectAll();
        model.addAttribute("list",list);
        return "/admin/healthy/healthyList";
    }

    /**
     * 身高体重更新页
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/editHealthy/{id}")
    public String editHealthy(@PathVariable Integer id,
                              Model model){
        Healthy healthy = healthyService.selectHealthyById(id);
        model.addAttribute("healthy",healthy);
        return "/admin/healthy/editHealthy";
    }


    /**
     * 更新数据
     * @param id
     * @param height
     * @param weight
     * @param create_time
     * @param baby_id
     * @param mv
     * @return
     */
    @RequestMapping("/updHealthy")
    public ModelAndView updHealthy(Integer id,
                                   Integer height,
                                   Float weight,
                                   String create_time,
                                   Integer baby_id,
                                   ModelAndView mv
                                   ){

        Baby baby = babyService.selectBabyById(baby_id);
        Healthy healthy = new Healthy();
        healthy.setId(id);
        healthy.setHeight(height);
        healthy.setWeight(weight);
        healthy.setCreate_time(DateUtil.parse(create_time));
        healthy.setBaby(baby);

        return returnMv((healthyService.updateHealthy(healthy)>0),mv);


    }

    /**
     * 删除数据
     * @param id
     * @param mv
     * @return
     */
    @RequestMapping("/delHealthy/{id}")
    public ModelAndView delHealthy(@PathVariable Integer id,
                                   ModelAndView mv){
        return returnMv((healthyService.deleteHealthy(id)>0),mv);
    }




///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * 选择页面跳转
     *
     * @param bl
     * @param mv
     * @return
     */
    public ModelAndView returnMv(boolean bl, ModelAndView mv) {
        if (bl) {
            return updateDate(mv, "操作成功!", "<meta http-equiv=\"refresh\" content=\"2;url=/admin/healthy/healthyList\">", "/success");
        } else {
            return updateDate(mv, "操作失败!", "<meta http-equiv=\"refresh\" content=\"2;url=/admin/healthy/healthyList\">", "/err");
        }

    }

    /**
     * 页面跳转
     *
     * @param mv
     * @param msg
     * @param url
     * @param viewName
     * @return
     */
    public ModelAndView updateDate(ModelAndView mv, String msg, String url, String viewName) {
        mv.addObject("msg", msg);
        mv.addObject("url", url);
        mv.setViewName(viewName);
        return mv;
    }
}
最近下载更多
kk992127170  LV6 2022年12月27日
tgeuuy  LV10 2022年10月25日
testuser1234567  LV24 2022年6月8日
zhos0212  LV19 2022年4月20日
zackery  LV9 2022年4月19日
fantesy  LV17 2022年3月3日
wang512237140  LV20 2021年12月21日
tansuo阿郎  LV8 2021年11月17日
尹恒yingying  LV18 2021年10月22日
huaua7676  LV30 2021年9月25日
最近浏览更多
860421  LV3 昨天
Boss绝  LV8 4月3日
Gin19960217  LV4 4月1日
13870342 1月11日
暂无贡献等级
要保持微笑  LV4 1月2日
1475059069  LV3 2023年12月27日
pangzhihui  LV12 2023年12月26日
夜起星河  LV8 2023年12月26日
cc7777 2023年12月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友