简单的增删改查-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";
}
}

原文地址:https://www.cnblogs.com/liuzhaolong/p/12880555.html