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

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

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

2.后端编写

2.1可以把请求分开

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

2.2把请求合并

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

2.2.1association

多对一

XML 复制代码
<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

一对多

2.3遇到的问题

collection中需要ofType

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

java 复制代码
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProductSearchVo {
    //商品名称
    private String productSearchVo;
}
java 复制代码
    @ApiOperation(value = "根据商品名字模糊查询商品")
    @GetMapping("{nameAndId}")
    public Result queryByNameAndId(@ApiParam(value = "商品或者id模糊查询商品")  ProductSearchVo productSearchVo) {
        return productsService.queryByNameAndId(productSearchVo);
    }
XML 复制代码
 <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>
相关推荐
double_eggm14 小时前
5.微信小程序
小程序
踩着两条虫15 小时前
「AI + 低代码」的可视化设计器
开发语言·前端·低代码·设计模式·架构
JoneBB15 小时前
ABAP Webservice连接
运维·开发语言·数据库·学习
budingxiaomoli15 小时前
Spring IoC &DI
java·spring·ioc·di
Spider Cat 蜘蛛猫15 小时前
Springboot SSO系统设计文档
java·spring boot·后端
未若君雅裁15 小时前
MySQL高可用与扩展-主从复制读写分离分库分表
java·数据库·mysql
即使再小的船也能远航15 小时前
【Python】安装
开发语言·python
学习中.........15 小时前
从扰动函数的变化,感受红黑树带来的性能提升
java
Irissgwe15 小时前
类与对象(三)
开发语言·c++·类和对象·友元
计算机安禾16 小时前
【c++面向对象编程】第24篇:类型转换运算符:自定义隐式转换与explicit
java·c++·算法