学习目标:
SSM框架项目实践
学习了基于二分搜索树对于集合的实现
学习内容:
实现CategoryService分类数据查询,开发了BooksService实现图书分类查询
核心代码如下:
package com.imooc.reader.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.imooc.reader.entity.Category; import com.imooc.reader.mapper.CategoryMapper; import com.imooc.reader.service.CategoryService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @Service @Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true) public class CategoryServiceImpl implements CategoryService { @Resource private CategoryMapper categoryMapper; @Override public List<Category> selectAll() { QueryWrapper wrapper = new QueryWrapper(); wrapper.orderByAsc("category_id"); return categoryMapper.selectList(wrapper); } }
package com.imooc.reader.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.imooc.reader.entity.Book; import com.imooc.reader.mapper.BookMapper; import com.imooc.reader.service.BookService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; @Service @Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true) public class BookServiceImpl implements BookService { @Resource private BookMapper bookMapper; @Override public IPage<Book> selectPage(Long categoryId, String order, Integer page, Integer rows) { IPage<Book> p = new Page<>(page,rows); QueryWrapper<Book> wrapper = new QueryWrapper<>(); if(categoryId!=null&&categoryId!=-1){ wrapper.eq("category_id", categoryId); } if (order != null) { if (order.equals("quantity")) { wrapper.orderByDesc("evaluation_quantity"); } else if (order.equals("score")) { wrapper.orderByDesc("evaluation_score"); } }else { wrapper.orderByDesc("evaluation_quantity"); } p=bookMapper.selectPage(p, wrapper); return p; } }
学习时间:
08:00-11:50 13:30-15:00 17:00-17:30
学习产出:
熟悉了SSM框架开发项目的基本流程,对于代码的业务逻辑有了一定的认识。