首页>代码>Spring MVC集成Mybatis实现基础的增删改查Demo实例>/springMVC_Mybatis_Test/src/com/ssm/controller/BooksController.java
package com.ssm.controller;
import javax.annotation.Resource;
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.bind.annotation.RequestMethod;
import com.ssm.entity.Books;
import com.ssm.service.BooksService;
@Controller
@RequestMapping("/books")
public class BooksController {
private BooksService booksService;
public BooksService getBooksService() {
return booksService;
}
@Resource
public void setbooksService(BooksService booksService) {
this.booksService = booksService;
}
/*保存数据对象 */
@RequestMapping(value="/save", method = RequestMethod.GET)
public String save(Model model, Books books){
booksService.save(books);
return "redirect:/books/list";
}
/*列出数据对象列表 */
@RequestMapping(value="/list",method = RequestMethod.GET)
public String list(Model model,Books books) {
model.addAttribute("list", booksService.queryResult(books));
model.addAttribute("entity",books);
return "/books_list";
}
/*根据主键更新对象 */
@RequestMapping(value="/edit/{id}",method = RequestMethod.GET)
public String edit(Model model,@PathVariable("id") Integer id) {
model.addAttribute("entity", booksService.getBooks(id));
return "/books_edit";
}
/*根据主键删除对象 */
@RequestMapping(value="/delete/{id}", method = RequestMethod.GET)
public String delete(Model model, @PathVariable("id") Integer id){
booksService.delete(id);
return "redirect:/books/list";
}
@RequestMapping(value="/books_add", method = RequestMethod.GET)
public String books_add(){
return "/books_add";
}
@RequestMapping("/books_list")
public String books_list(){
return "/books_list";
}
}
最近下载更多
it_star LV6
2023年10月31日
李亮 LV19
2023年8月29日
zhumeng168 LV5
2023年7月8日
1257592068 LV6
2023年6月13日
小妹妹 LV7
2023年5月22日
微信网友_6248713511227392 LV11
2022年12月5日
谢谢谢谢谢谢你 LV6
2022年7月19日
彬 LV6
2021年12月22日
9843637 LV9
2021年12月12日
543666826 LV34
2021年11月19日
最近浏览更多
可是不知道么 LV23
3月29日
微信网友_7316199114199040
2024年12月28日
暂无贡献等级
三秋桂子 LV1
2024年12月22日
气之子dss LV4
2024年6月24日
qq970040477 LV24
2024年6月16日
xin xie LV1
2024年6月13日
wwwww816 LV5
2023年12月19日
xiongwei11231 LV9
2023年12月6日
it_star LV6
2023年10月31日
李亮 LV19
2023年8月29日

