- 数据层代码
 
// BookDaopackage com.itheima.dao;import com.itheima.domain.Book;import org.apache.ibatis.annotations.Delete;import org.apache.ibatis.annotations.Insert;import org.apache.ibatis.annotations.Select;import org.apache.ibatis.annotations.Update;import java.util.List;public interface BookDao {    // 采用Mapper代理开发    // 采用#{}匹配参数    @Insert("insert into tbl_book (type,name,description) values(#{type},#{name},#{description})")    public void save(Book book);    @Update("update tbl_book set type = #{type}, name = #{name}, description = #{description} where id = #{id}")    public void update(Book book);    @Delete("delete from tbl_book where id = #{id}")    public void delete(Integer id);    @Select("select * from tbl_book where id = #{id}")    public Book getById(Integer id);    @Select("select * from tbl_book")    public List<Book> getAll();}
- 业务层代码
 
// BookServicepackage com.itheima.service;import com.itheima.domain.Book;import org.springframework.transaction.annotation.Transactional;import java.util.List;// 给出事务开启标志@Transactionalpublic interface BookService {    // 采用文档注释,表明各方法作用    /**     * 保存     * @param book     * @return     */    public boolean save(Book book);    /**     * 修改     * @param book     * @return     */    public boolean update(Book book);    /**     * 按id删除     * @param id     * @return     */    public boolean delete(Integer id);    /**     * 按id查询     * @param id     * @return     */    public Book getById(Integer id);    /**     * 查询全部     * @return     */    public List<Book> getAll();}// BookServiceImplpackage com.itheima.service.impl;import com.itheima.dao.BookDao;import com.itheima.domain.Book;import com.itheima.service.BookService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;// 标记为Bean@Servicepublic class BookServiceImpl implements BookService {    // 自动装配    @Autowired    private BookDao bookDao;    public boolean save(Book book) {        bookDao.save(book);        return true;    }    public boolean update(Book book) {        bookDao.update(book);        return true;    }    public boolean delete(Integer id) {        bookDao.delete(id);        return true;    }    public Book getById(Integer id) {        return bookDao.getById(id);    }    public List<Book> getAll() {        return bookDao.getAll();    }}
		  	
经验总结扩展阅读
           - 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
                  有一句俗话:“早起的鸟儿有虫吃。|早睡早起的时间,早起的人更容易获取成功机会 
 
- 
              
              
            
- 
              
              
                  8月,4大星座财运大涨,横财正财偏财齐聚满堂,富贵满堂 
 
- 
              
              
            
- 
              
              
                  裸妆|看来看去,浓妆艳抹不算啥,还是裸妆最百搭,关键实用又简单 
 
- 
              
              
            
- 
              
              
                  健康周谈|冬天是脑梗高发季,该如何度过?医生:做好4件事,或能安稳过冬 
 
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
                  越南|中国男性和越南男性有啥区别?听听越南姑娘是怎么说的 
 
- 
              
              
                  2023年1月4日制作房梁黄道吉日 2023年农历腊月十三制作房梁吉日 
 
- 
              
              
            
- 
              
              
                  2023年5月定亲黄道吉日 2023年5月哪天适合定亲