品牌管理增删改查
This commit is contained in:
parent
5b2c6bf1a8
commit
0b4fe3df34
|
@ -1,6 +1,9 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,com.github.pagehelper.page.PageMethod,startPage" />
|
||||||
|
</inspection_tool>
|
||||||
<inspection_tool class="RawUseOfParameterizedType" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="RawUseOfParameterizedType" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="SqlWithoutWhereInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="SqlWithoutWhereInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="ThrowablePrintStackTrace" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="ThrowablePrintStackTrace" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package cn.bunny.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.bunny.common.spzx.model.entity.product.Brand;
|
||||||
|
import cn.bunny.common.spzx.model.vo.common.Result;
|
||||||
|
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||||
|
import cn.bunny.service.BrandService;
|
||||||
|
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 = "商品分类")
|
||||||
|
@RequestMapping("/admin/product/brand")
|
||||||
|
@RestController
|
||||||
|
public class BranController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BrandService brandService;
|
||||||
|
|
||||||
|
@Operation(summary = "获取品牌列表", description = "获取品牌全部列表")
|
||||||
|
@GetMapping("{page}/{limit}")
|
||||||
|
public Result list(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit) {
|
||||||
|
PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
|
||||||
|
|
||||||
|
return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加品牌", description = "添加品牌")
|
||||||
|
@PostMapping("save")
|
||||||
|
public Result save(@RequestBody Brand brand) {
|
||||||
|
brandService.save(brand);
|
||||||
|
|
||||||
|
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改品牌", description = "修改品牌")
|
||||||
|
@PutMapping("updateById")
|
||||||
|
public Result updateById(@RequestBody Brand brand) {
|
||||||
|
brandService.updateById(brand);
|
||||||
|
|
||||||
|
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除品牌", description = "删除品牌")
|
||||||
|
@DeleteMapping("deleteById/{id}")
|
||||||
|
public Result deleteById(@PathVariable("id") Integer id) {
|
||||||
|
brandService.deleteById(id);
|
||||||
|
|
||||||
|
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.bunny.mapper;
|
||||||
|
|
||||||
|
import cn.bunny.common.spzx.model.entity.product.Brand;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface BrandMapper {
|
||||||
|
// 分页查询品牌列表
|
||||||
|
public List<Brand> findByPage();
|
||||||
|
|
||||||
|
public void save(Brand brand);
|
||||||
|
|
||||||
|
// 修改品牌
|
||||||
|
void updateById(Brand brand);
|
||||||
|
|
||||||
|
// 删除品牌
|
||||||
|
void deleteById(Integer id);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package cn.bunny.service;
|
||||||
|
|
||||||
|
import cn.bunny.common.spzx.model.entity.product.Brand;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
public interface BrandService {
|
||||||
|
PageInfo<Brand> findByPage(Integer page, Integer limit);
|
||||||
|
|
||||||
|
// 添加
|
||||||
|
void save(Brand brand);
|
||||||
|
|
||||||
|
// 修改品牌
|
||||||
|
void updateById(Brand brand);
|
||||||
|
|
||||||
|
// 删除品牌
|
||||||
|
void deleteById(Integer id);
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package cn.bunny.service.impl;
|
||||||
|
|
||||||
|
import cn.bunny.common.spzx.model.entity.product.Brand;
|
||||||
|
import cn.bunny.mapper.BrandMapper;
|
||||||
|
import cn.bunny.service.BrandService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 查询
|
||||||
|
@Override
|
||||||
|
public PageInfo<Brand> findByPage(Integer page, Integer limit) {
|
||||||
|
PageHelper.startPage(page, limit);
|
||||||
|
List<Brand> brandList = brandMapper.findByPage();
|
||||||
|
return new PageInfo<>(brandList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加
|
||||||
|
@Override
|
||||||
|
public void save(Brand brand) {
|
||||||
|
brandMapper.save(brand);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改品牌
|
||||||
|
@Override
|
||||||
|
public void updateById(Brand brand) {
|
||||||
|
brandMapper.updateById(brand);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除品牌
|
||||||
|
@Override
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
brandMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?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="cn.bunny.mapper.BrandMapper">
|
||||||
|
<resultMap id="brandMap" type="cn.bunny.common.spzx.model.entity.product.Brand" autoMapping="true"/>
|
||||||
|
|
||||||
|
<!-- 用于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>
|
||||||
|
|
||||||
|
<!-- 删除品牌 -->
|
||||||
|
<delete id="deleteById">
|
||||||
|
update brand
|
||||||
|
set is_deleted=1
|
||||||
|
where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!-- 品牌列表 -->
|
||||||
|
<select id="findByPage" resultMap="brandMap">
|
||||||
|
select
|
||||||
|
<include refid="columns"/>
|
||||||
|
from brand where is_deleted=0 order by id
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue