东湖之滨 发表于 2024-7-11 13:50:05

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

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

’我的图片表中有一个字段是描述我写成desc了,正好是mysql中的关键字 就不能利用了
https://i-blog.csdnimg.cn/direct/e844876df6e2400395ce63e550e5860e.png
2.后端编写 

2.1可以把请求分开
https://i-blog.csdnimg.cn/direct/3ad8958a3d9941b3a3e0284f6b95ec65.png
在商品欣赏页中 只显示商品的大致信息 当用户再点击其他按钮时在发出请求
2.2把请求合并

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

多对一 https://i-blog.csdnimg.cn/direct/f6aef9eb262c41b2b22bac78003d63d2.png
<association property="categories" javaType="com.hrmy.entity.Categories">
            <id property="id" column="id"/>
            <result property="parentId" column="parent_id"/>
            <result property="name" column="name"/>
            <result property="createdAt" column="created_at"/>
            <result property="updatedAt" column="update_at"/>
      </association> 2.2.2collection

一对多
https://i-blog.csdnimg.cn/direct/9168e58ae7b6459d8cc1a23a4889e212.png
https://i-blog.csdnimg.cn/direct/56554f8f305745bca5dafb91689fc0ad.png
2.3碰到的题目

collection中需要ofType 
3.一个框框实现条件模糊查找

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

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 学java的第3天 后端商城小程序工作