• 简单的增删改查-controller


    package com.lzl.controller;

    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 com.github.pagehelper.PageInfo;
    import com.lzl.pojo.Shop;
    import com.lzl.service.ShopService;

    @Controller
    public class Shopcontroller {

    @Reference
    ShopService service;

    @RequestMapping("long")
    public String select(Model m, @RequestParam(defaultValue = "1") Integer pageNum,
    @RequestParam(defaultValue = "3") Integer pageSize) {

    PageInfo<Shop> info = service.select(pageNum, pageSize);
    List<Shop> list = info.getList();
    for (Shop shop : list) {
    System.out.println(shop);
    }
    m.addAttribute("info", info);
    return "list";

    }

    @ResponseBody
    @RequestMapping("del")
    public Object del(String sids) {

    boolean flag = service.del(sids);
    return flag;
    }

    @GetMapping("toAdd")
    public String toAdd(Model model, Shop shop) {
    model.addAttribute("shop", shop);
    return "add";
    }
    /**
    * 添加
    * @param shop
    * @return
    */
    @PostMapping("add")
    public String add(Shop shop) {

    service.add(shop);
    return "redirect:long";
    }

    @GetMapping("/toupdate")
    public String toupdate(Integer sid, Model m) {

    Shop shop = service.selectOne(sid);
    System.err.println(shop);
    m.addAttribute("shop", shop);
    return "update";
    }
    /**
    * 修改
    * @param shop
    * @return
    */
    @PostMapping("update")
    public String update(Shop shop) {

    service.update(shop);
    return "redirect:long";
    }
    }

  • 相关阅读:
    (三十七)Unittest单元测试框架之认识unittest-重要的概念
    (三十六)Unittest单元测试框架之认识unittest-认识单元测试
    (三十五)什么是自动化测试模型之数据驱动测试实例
    Django_前介
    Django_JavaScript
    Django_HTML
    LAMP环境搭建,防火墙开启,数据库挂载在逻辑卷
    shell脚本案例
    Linux轻量级自动化运维工具— Ansible
    Docker实战总结
  • 原文地址:https://www.cnblogs.com/liuzhaolong/p/12880555.html
Copyright © 2020-2023  润新知