Compare commits
4 Commits
a7b8646010
...
b77dbadd4a
Author | SHA1 | Date |
---|---|---|
|
b77dbadd4a | |
|
a7afceb704 | |
|
cd1e39271a | |
|
bc7bc4afd2 |
|
@ -0,0 +1,46 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.spzx.manger.service.BrandService;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "品牌管理")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/product/brand")
|
||||
public class BrandController {
|
||||
@Autowired
|
||||
private BrandService brandService;
|
||||
|
||||
@Operation(summary = "品牌列表查询", description = "品牌列表查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
|
||||
PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
|
||||
return Result.success(pageInfo);
|
||||
}
|
||||
|
||||
@Operation(summary = "品牌添加", description = "品牌添加")
|
||||
@PostMapping("save")
|
||||
public Result<Brand> save(@RequestBody Brand brand) {
|
||||
brandService.save(brand);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改品牌", description = "修改品牌")
|
||||
@PutMapping("updateById")
|
||||
public Result<Brand> updateById(@RequestBody Brand brand) {
|
||||
brandService.updateById(brand);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除品牌", description = "删除品牌")
|
||||
@DeleteMapping("deleteById/{id}")
|
||||
public Result<Long> deleteById(@PathVariable Long id) {
|
||||
brandService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.atguigu.spzx.manger.mapper;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BrandMapper {
|
||||
/**
|
||||
* 查找分页品牌
|
||||
*
|
||||
* @return 品牌列表
|
||||
*/
|
||||
List<Brand> findByPage();
|
||||
|
||||
/**
|
||||
* 品牌添加
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void save(Brand brand);
|
||||
|
||||
/**
|
||||
* 修改品牌
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void updateById(Brand brand);
|
||||
|
||||
/**
|
||||
* 根据id删除品牌
|
||||
*
|
||||
* @param id 品牌id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface BrandService {
|
||||
/**
|
||||
* 品牌列表查询
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页大小
|
||||
* @return 品牌分页结果
|
||||
*/
|
||||
PageInfo<Brand> findByPage(Integer page, Integer limit);
|
||||
|
||||
/**
|
||||
* 品牌添加
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void save(Brand brand);
|
||||
|
||||
/**
|
||||
* 修改品牌
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
void updateById(Brand brand);
|
||||
|
||||
/**
|
||||
* 根据id删除品牌
|
||||
*
|
||||
* @param id 品牌id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.spzx.manger.mapper.BrandMapper;
|
||||
import com.atguigu.spzx.manger.service.BrandService;
|
||||
import com.atguigu.spzx.model.entity.product.Brand;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BrandServiceImpl implements BrandService {
|
||||
@Autowired
|
||||
private BrandMapper brandMapper;
|
||||
@Autowired
|
||||
private StringEmptyUtil emptyUtil;
|
||||
|
||||
/**
|
||||
* 品牌列表查询
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param limit 每页大小
|
||||
* @return 品牌分页结果
|
||||
*/
|
||||
@Override
|
||||
public PageInfo<Brand> findByPage(Integer page, Integer limit) {
|
||||
Page<Brand> startPage = PageHelper.startPage(page, limit);
|
||||
// 查找分页品牌
|
||||
List<Brand> brandList = brandMapper.findByPage();
|
||||
startPage.close();
|
||||
return new PageInfo<>(brandList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 品牌添加
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
@Override
|
||||
public void save(Brand brand) {
|
||||
brandMapper.save(brand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改品牌
|
||||
*
|
||||
* @param brand 品牌实体类
|
||||
*/
|
||||
@Override
|
||||
public void updateById(Brand brand) {
|
||||
emptyUtil.isEmpty(brand, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
|
||||
brandMapper.updateById(brand);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除品牌
|
||||
*
|
||||
* @param id 品牌id
|
||||
*/
|
||||
@Override
|
||||
public void deleteById(Long id) {
|
||||
emptyUtil.isEmpty(id, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||
brandMapper.deleteById(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.atguigu.spzx.manger.mapper.BrandMapper">
|
||||
<!-- 用于select查询公用抽取的列 -->
|
||||
<sql id="columns">
|
||||
id,name,logo,create_time,update_time,is_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 品牌添加 -->
|
||||
<insert id="save">
|
||||
insert into brand (id, name, logo, create_time, update_time, is_deleted)
|
||||
values (#{id}, #{name}, #{logo}, now(), now(), 0);
|
||||
</insert>
|
||||
|
||||
<!-- 修改品牌 -->
|
||||
<update id="updateById">
|
||||
update brand
|
||||
set
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="logo != null and logo != ''">
|
||||
logo = #{logo},
|
||||
</if>
|
||||
update_time = now()
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 根据id删除品牌 -->
|
||||
<update id="deleteById">
|
||||
update brand
|
||||
set is_deleted = 1,
|
||||
update_time = now()
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 查找分页品牌 -->
|
||||
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.Brand">
|
||||
select
|
||||
<include refid="columns"/>
|
||||
from brand
|
||||
where is_deleted = 0
|
||||
order by id desc
|
||||
</select>
|
||||
</mapper>
|
|
@ -2,9 +2,13 @@ package com.atguigu.spzx.model.entity.product;
|
|||
|
||||
import com.atguigu.spzx.model.entity.base.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "品牌实体类")
|
||||
public class Brand extends BaseEntity {
|
||||
|
||||
|
|
Loading…
Reference in New Issue