编写后台代码

添加和修改代码

1.编写controller

@Controller
@RequestMapping("/platfProduct")
public class PlatfProductController {
	
	@Autowired
	private  PlatfProductService  platfProductService;



    /**
     * @gen_192_lwl
     * 获取产品列表
     * 获取产品列表
     * @param platfProductVo
    **/
    @Title("获取产品列表")
    @ResponseBody
    @RequestMapping(value="/list", method=RequestMethod.POST)   //value 为接口地址   method为请求方法
    public BaseRes<PageWrapper<List<PlatfProductVo>>> list(@RequestBody PlatfProductVo platfProductVo, BindingResult bindingResult) {
       
    	return platfProductService.list(platfProductVo);
    }

    /**
     * @gen_189_lwl
     * 删除产品列表
     * 删除产品列表
     * @param id
    **/
  //通过ID删除
    @Title("删除产品列表")
    @ResponseBody
    @RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
    public BaseRes<String> delete(@PathVariable("id") Integer id) {
         
    	return platfProductService.delete(id);
    }

    /**
     * @gen_190_lwl
     * 更新产品列表
     * 更新产品列表
     * @param platfProductVo
    **/
    @Title("更新产品列表")
    @ResponseBody
    @RequestMapping(value="/update", method=RequestMethod.POST)
    public BaseRes<String> update(@RequestBody PlatfProductVo platfProductVo, BindingResult bindingResult) {
       
        return platfProductService.update(platfProductVo);
    }

    /**
     * @gen_191_lwl
     * 添加产品列表
     * 添加产品列表
     * @param platfProductVo
    **/
    @Title("添加产品列表")
    @ResponseBody
    @RequestMapping(value="/add", method=RequestMethod.POST)
    public BaseRes<String> add(@RequestBody PlatfProductVo platfProductVo, BindingResult bindingResult) {
        
        return platfProductService.add(platfProductVo);
    }


    /**
     * @gen_201_lwl
     * 产品详情
     * 产品详情
     * @param platfProductid
    **/
    @Title("产品详情")
    @ResponseBody
    @RequestMapping(value="/detail", method=RequestMethod.POST)
    public BaseRes<PlatfProductVo> detail(@RequestBody @Validated(PlatfProductController_detail.class) PlatfProductVo platfProductid, BindingResult bindingResult) {
         
    	return platfProductService.detail(platfProductid);
    }
}
  1. 编写Service
public interface PlatfProductService {

	BaseRes<PageWrapper<List<PlatfProductVo>>> list(PlatfProductVo platfProductVo);

	BaseRes<String> delete(Integer id);

	BaseRes<String> update(PlatfProductVo platfProductVo);

	BaseRes<String> add(PlatfProductVo platfProductVo);

	BaseRes<PlatfProductVo> detail(PlatfProductVo platfProductid);

}

3.创建ServiceImpl 继承于 Service

@Component
public class PlatfProductServiceImpl implements PlatfProductService {

	@Autowired
	private PlatfSettingMapper platfProductMapper;
	


  /**获取数据库列表*/
	@Override
	public BaseRes<PageWrapper<List<PlatfProductVo>>> list(PlatfProductVo platfProductVo) {
		
		BaseRes<PageWrapper<List<PlatfProductVo>>> res = new BaseRes<>();
		PageWrapper<List<PlatfProductVo>> data = new PageWrapper<>();
		res.setData(data);

		//分页
		Integer current = platfProductVo.getCurrent();
		current = current == null ? 1 : current;
		Integer pageSize = platfProductVo.getPageSize();
		pageSize = pageSize == null ? 10 : pageSize;
		
		int mysqlOffset = (current - 1) * pageSize;
		int mysqlLength = pageSize;
		
		PlatfSettingCriteria platfCriteria = new PlatfSettingCriteria();
		Criteria criteria =PlatfSettingCriteria.createCriteria();
		//设置 显示顺序
		platfCriteria.setOrderByClause(" id desc ");
		// 设置分页
		platfCriteria.setMysqlOffset(mysqlOffset);
		platfCriteria.setMysqlLength(mysqlLength);
		long total = platfProductMapper.countByExample(platfCriteria);
		data.setTotal(total);
		data.setPageSize(pageSize);
		data.setCurrent(current);
		
		if (total > 0) {
			List<PlatfSetting>  platfSetting = platfProductMapper.selectByExample(platfCriteria);
			List<PlatfProductVo> pus = BeanUtil.voConvertList(platfSetting, PlatfProductVo.class);
			data.setData(pus);
		}
		res.setServiceCode(ServiceCode.SUCCESS);
		return res;
	}
	

/**单独查询*/
	@Override
	public BaseRes<PlatfProductVo> detail(PlatfProductVo platfProductid) {
		BaseRes<PlatfProductVo> res = new BaseRes<>();
       //通过id查询某一条数据
		PlatfProduct  temp = platfProductMapper.selectByPrimaryKey(platfProductid.getId());
	
		if (temp != null) {
			res.setData(BeanUtil.voConvert(temp, PlatfProductVo.class));
			res.setServiceCode(ServiceCode.SUCCESS);
		} else {
			res.setServiceCode(ServiceCode.FAILED);
		}
		return res;
	}


/**删除某条数据*/
	@Override
	public BaseRes<String> delete(Integer id) {
		platfProductMapper.deleteByPrimaryKey(id);    //通过主键删除数据
		return new BaseRes<>(ServiceCode.SUCCESS);;
	}

/**更新某条数据*/

	@Override
	public BaseRes<String> update(PlatfProductVo platfProductVo) {
		platfProductVo.setUpdateDate(new Date());  //设置更新时间
		platfProductMapper.updateByPrimaryKeySelective(platfProductVo);
		
		return new BaseRes<>(ServiceCode.SUCCESS);
	}


/**添加某条数据*/
	@Override
	public BaseRes<String> add(PlatfProductVo platfProductVo) {
		platfProductVo.setCreateDate(new Date());     //设置创建时间
		platfProductMapper.insertSelective(platfProductVo);
		return new BaseRes<>(ServiceCode.SUCCESS);
	}

}

4.OK,至此,简单的增删改查方法就建好了,下面来开始编写前端代码吧!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿小张丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值