当前位置:   article > 正文

学java的第3天 后端商城小程序工作

学java的第3天 后端商城小程序工作

1.数据库的大坑 特殊字段名

’我的图片表中有一个字段是描述我写成desc了,正好是mysql中的关键字 就不能使用了

2.后端编写 

2.1可以把请求分开

在商品浏览页中 只显示商品的大致信息 当用户再点击其他按钮时在发出请求

2.2把请求合并

把数据整合到一起 利用association 和 collection 表示 

2.2.1association

多对一 

  1. <association property="categories" javaType="com.hrmy.entity.Categories">
  2. <id property="id" column="id"/>
  3. <result property="parentId" column="parent_id"/>
  4. <result property="name" column="name"/>
  5. <result property="createdAt" column="created_at"/>
  6. <result property="updatedAt" column="update_at"/>
  7. </association>

2.2.2collection

一对多

2.3遇到的问题

collection中需要ofType 

3.一个框框实现条件模糊查找

  1. @Data
  2. @AllArgsConstructor
  3. @NoArgsConstructor
  4. public class ProductSearchVo {
  5. //商品名称
  6. private String productSearchVo;
  7. }
  1. @ApiOperation(value = "根据商品名字模糊查询商品")
  2. @GetMapping("{nameAndId}")
  3. public Result queryByNameAndId(@ApiParam(value = "商品或者id模糊查询商品") ProductSearchVo productSearchVo) {
  4. return productsService.queryByNameAndId(productSearchVo);
  5. }
  1. <select id="queryByNameAndId" resultType="com.hrmy.entity.Products">
  2. select
  3. id, name, category_id, created_at, updated_at, desc_img, status, sales,main_photo
  4. from products
  5. where ishot = 0
  6. <if test="productSearchVo != null and productSearchVo !=''">
  7. and (name like concat ('%',#{productSearchVo},'%')) or (id like concat('%',#{productSearchVo},'%'))
  8. </if>
  9. </select>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/794492?site
推荐阅读
相关标签
  

闽ICP备14008679号