学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>
相关推荐
fqbqrr32 分钟前
2606C++,C++构的多态
开发语言·c++
biter down1 小时前
从 0 到 1 搭建 Python 接口自动化测试框架(博客系统实战)
开发语言·python
wang09072 小时前
自己动手写一个spring之IOC_2
java·后端·spring
来杯@Java2 小时前
学生选课管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·maven·mybatis
threelab3 小时前
Three.js 物理模拟着色器 | 三维可视化 / AI 提示词
开发语言·前端·javascript·人工智能·3d·着色器
武器大师723 小时前
lv_binding_js 代码解读
开发语言·javascript·ecmascript
不知名的老吴3 小时前
线程的生命周期之线程“插队“
java·开发语言·python
ANnianStriver3 小时前
PetLumina-02-后端开发与前后端联调
java·ai·sa-token
杨了个杨89824 小时前
Keepalived + Nginx + HAProxy 高可用架构部署实战案例
java·nginx·架构