添加和修改代码
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);
}
}
- 编写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,至此,简单的增删改查方法就建好了,下面来开始编写前端代码吧!