学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>
相关推荐
karry_k1 小时前
MyBatis批量insert-select踩坑:useGeneratedKeys=true 可能让PostgreSQL返回大量插入结果
java·后端
karry_k1 小时前
PostgreSQL 在 MyBatis 中执行正常 SQL 失效:一次 DELETE USING 踩坑记录
java·后端
SamDeepThinking5 小时前
从源码到代码:MyBatis-Flex 与 MyBatis-Plus 的逐项对比
java·后端·程序员
她的男孩8 小时前
Spring Boot 接 Flowable 工作流:用 3 个注解搭一个请假审批流程
java·后端·架构
荣码10 小时前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑
java·python
plainGeekDev11 小时前
Gson → kotlinx.serialization
android·java·kotlin
小bo波20 小时前
Java Swing 图形用户界面实验 —— 从算术练习到游戏开发的完整实践
java·课程设计·gui·游戏开发·扫雷·swing
咖啡八杯21 小时前
GoF设计模式——备忘录模式
java·后端·spring·设计模式