11 도서 관리 시스템(SSM+LayUi)

6778 단어
1. DAO 계층 인터페이스 및 구현
  • classInfoDao.java에서 쓰기 삭제
  • package com.gychen.dao;
    
    import com.gychen.po.ClassInfo;
    import org.apache.ibatis.annotations.Param;
    import org.apache.ibatis.annotations.Select;
    import org.springframework.stereotype.Component;
    
    import java.util.List;
    
    @Component("classDao")
    public interface ClassInfoDao {
        /**
         *           
         */
    //    @Select("select * from class_info")
    //    List queryClassInfoAll();
    
        List queryClassInfoAll(@Param(value = "name")String name);
    
    
        /**
         *       
         */
        void addBookType(ClassInfo classInfo);
    
        /**
         *      id      
         */
        ClassInfo queryBookTypeById(Integer id);
    
        /**
         *         
         */
        void updateBookType(ClassInfo classInfo);
    
        /**
         *           id  
         */
        void deleteBookTypeByIds(List id);
    
    
    }
    
    
  • ClassInfoDao.xml에서 문장 삭제
  • 
    
    
    
        
        
    
        
        
            insert into class_info (name,remarks) values (#{name},#{remarks})
        
    
        
        
    
        
        
            update class_info set name=#{name},remarks=#{remarks} where id=#{id}
        
    
        
        
            delete from class_info where id in 
            
                #{ids}
            
        
    
    
    

    2. 서비스 층 인터페이스와 실현
  • ClassInfoService에 첨삭
  • 쓰기
    package com.gychen.service;
    
    import com.github.pagehelper.PageInfo;
    import com.gychen.po.ClassInfo;
    
    import java.util.List;
    
    public interface ClassInfoService {
        /**
         *            
         */
        PageInfo queryClassInfoAll(String name,int page,int limit);
    
    
        /**
         *       
         */
        void addBookType(ClassInfo classInfo);
    
        /**
         *      id      
         */
        ClassInfo queryBookTypeById(Integer id);
    
        /**
         *         
         */
        void updateBookType(ClassInfo classInfo);
    
        /**
         *           id  
         */
        void deleteBookTypeByIds(List ids);
    }
    
    
  • ClassInfoServiceImpl리 에서 문장 삭제
  • package com.gychen.service;
    
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import com.gychen.dao.ClassInfoDao;
    import com.gychen.po.ClassInfo;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import java.util.List;
    
    @Service("classInfoService")
    public class ClassInfoServiceImpl implements ClassInfoService {
    
        @Autowired
        private ClassInfoDao classDao;
    
        @Override
        public PageInfo queryClassInfoAll(String name,int page, int limit) {
    
            //     ,    ,   
            PageHelper.startPage(page,limit);
            List list = classDao.queryClassInfoAll(name);
            //               
            PageInfo pageInfo = new PageInfo<>(list);
    
            return pageInfo;
        }
    
        @Override
        public void addBookType(ClassInfo classInfo) {
            classDao.addBookType(classInfo);
        }
    
        @Override
        public ClassInfo queryBookTypeById(Integer id) {
            return classDao.queryBookTypeById(id);
        }
    
        @Override
        public void updateBookType(ClassInfo classInfo) {
            classDao.updateBookType(classInfo);
        }
    
        @Override
        public void deleteBookTypeByIds(List ids) {
            classDao.deleteBookTypeByIds(ids);
        }
    }
    
    

    3. Controller층의 실현
  • TypeController에 수정 사항 추가
  • package com.gychen.controller;
    
    import com.github.pagehelper.PageInfo;
    import com.gychen.po.ClassInfo;
    import com.gychen.service.ClassInfoService;
    import com.gychen.util.RestResponse;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.*;
    
    import java.util.Arrays;
    import java.util.List;
    
    @Controller
    public class TypeController {
    
        @Autowired
        private ClassInfoService classInfoService;  //    classInfoService  ClassInfoServiceImpl        
    
        @RequestMapping("/typeIndex")
        public String typeIndex(){
    
            return "type/typeIndex";
        }
    
        /**
         *        
         */
        @GetMapping("/typeAdd")
        public String typeAdd(){
            return "type/addType";
        }
    
    
        /**
         *   type       
         */
        @RequestMapping("/typeAll")
        @ResponseBody
        public RestResponse typeAll(String name, @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "15") Integer limit){
    
            PageInfo pageInfo = classInfoService.queryClassInfoAll(name, page, limit);
    
            return RestResponse.ok(pageInfo.getList());
        }
    
        /**
         *     
         */
        @ResponseBody
        @RequestMapping("/addBookType")
        public RestResponse addBookType(ClassInfo classInfo){
            classInfoService.addBookType(classInfo);
            return RestResponse.ok();
        }
    
        /**
         *   id  
         */
        @GetMapping("/queryBookTypeById")
        public String queryBookTypeById(Integer id, Model model){
            ClassInfo classInfo = classInfoService.queryBookTypeById(id);
            model.addAttribute("info",classInfo);
            return "type/updateType";
        }
    
        /**
         *       
         */
        @ResponseBody
        @RequestMapping("/updateBookType")
        public RestResponse updateBookType(@RequestBody ClassInfo classInfo){
            classInfoService.updateBookType(classInfo);
            return RestResponse.ok();
        }
    
    
        /**
         *     
         */
        @ResponseBody
        @RequestMapping("/deleteType")
        public RestResponse deleteType(String ids){
            List list = Arrays.asList(ids.split(","));
            classInfoService.deleteBookTypeByIds(list);
            return RestResponse.ok();
        }
    
    }
    
    

    좋은 웹페이지 즐겨찾기