0
点赞
收藏
分享

微信扫一扫

微服务电商的学习

软件共享软件 2022-03-12 阅读 76

微服务电商的学习

一,框架的搭建

基础框架

  • 创建一个一级父工程,可以删除src,作为父工程都不需要写代码,

  • pom文件的添加

  • 熟悉使用通用mapper在引入基础框架

    • 需要的依赖:(只是针对一张表进行增删改查)
<!--通用mapper起步依赖-->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.0.4</version>
        </dependency>

根据条件查询添加的知识点:在将条件封装在Map或者对象中时,

Example example = new Example(Brand.class);
Example.Criteria criteria = example.createCriteria();
if(map != null){
    // 品牌名称 ,判断map或者对象的值是否含有此条件,再添加至实例中
    if(searchMap.get("name")!=null && !"".equals(searchMap.get("name"))){
        criteria.andLike("name","%"+searchMap.get("name")+"%");
    }
    if(brand.getName()!=null && !"".equals(brand.getName())){
        criteria.andLike("name","%"+searchMap.get("name")+"%");
    }
}
brandMapper.SelectByExample(example);//通过条件查询

根据分页查询:参数为page,size

PageHelper.startPage(page,size);
brandMapper.selectAll();

根据条件查询出的列表进行分页

  • 统一异常处理类
@ControllerActive
public class BaseExceptionHandler{
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, "执行出错");
    }
}
  • 导入了基础框架之后,需要熟悉针对多表操作的添加
  @Select("select name,image from tb_brand where id in (select brand_id from tb_category_brand where category_id in (select id from tb_category where name=#{categoryName}))")
    List<Map> findBrandListByCategoryName(@Param("categoryName") String categoryName);
举报

相关推荐

0 条评论