当前位置 : 主页 > 编程语言 > java >

spring boot +bootstrap+layer web(图书管理系统)

来源:互联网 收集:自由互联 发布时间:2021-06-28
com.book package com.book.controller;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import org.springframework.data.domain.Sort;import org.springframework.stereotype.Controller;import org.springframework.ui.Mo
com.book
package com.book.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;









import com.book.dao.BookDao;
import com.book.entity.Book;

/**
 * 图书控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/book")
public class BookController {

	@Resource
	private BookDao bookDao;
	
	/**
	 * 查询所有图书
	 * @return
	 */

	@RequestMapping("/list")
	public ModelAndView list(){
		//添加排序
		Sort sort = new Sort(Sort.Direction.DESC, "addtime");
		ModelAndView mav=new ModelAndView();
		mav.addObject("bookList",bookDao.findAll(sort));
		mav.setViewName("bookList");
		return mav;
		
	}
	@RequestMapping(value ="/getall",method=RequestMethod.POST )
	public String girlList(HttpServletRequest request, ModelMap map){  
        System.out.println("查询所有执行");  
        System.out.println(bookDao.findAll().get(0).getName());
       
        map.put("testCaseDtoList", bookDao.findAll());
        return  "book/getall";  
    }  
	
	/**
	 * 添加图书
	 * @param book
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String add(Book book){
	
		if(book.getName().equals("")){
			return "请填写完整";
			
		}else{
		bookDao.save(book);
		return "forward:/book/list";
		}
	}
	
	/**
	 * 根据id查询book实体
	 * @param id
	 * @return
	 */
	@RequestMapping("/preUpdate/{id}")
	public ModelAndView preUpdate(@PathVariable("id")Integer id){
		ModelAndView mav=new ModelAndView();
		System.out.println(id);
		mav.addObject("book", bookDao.getOne(id));
		mav.setViewName("bookUpdate");
		return mav;
	}
	
	/**
	 * 修改图书
	 * @param book
	 * @return
	 */
	@PostMapping(value="/update")
	public String update(Book book){
		bookDao.save(book);
		return "forward:/book/list";
	}
	
	@GetMapping("/delete")
	public String delete(Integer id){
		bookDao.delete(id);
		return "forward:/book/list";
	}
}
网友评论