当前位置: 首页 > wzjs >正文

网站如何报备礼品定制

网站如何报备,礼品定制,南宁房地产最新消息,网站 制作 技术过时基于SpringBoot和MybatisPlus实现通用Controller,只需要创建实体类和mapper接口,单表增删改查接口就已经实现,提升开发效率 1.定义通用controller package com.xian.controller;import cn.hutool.core.map.MapUtil; import com.baomidou.my…

基于SpringBoot和MybatisPlus实现通用Controller,只需要创建实体类和mapper接口,单表增删改查接口就已经实现,提升开发效率

1.定义通用controller

package com.xian.controller;import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xian.common.alias.*;
import com.xian.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;@RestController
@RequestMapping("/api/v1/data")
public class BaseController<T extends Serializable> {@Autowiredprivate ApplicationContext applicationContext;private T entity;// 使用泛型和IService来处理通用CRUD操作protected <S extends BaseMapper<T>> S getMapper(String entityName) throws Exception {String serviceName = entityName + "Mapper"; // 假设服务名与实体名相同return (S) applicationContext.getBean(serviceName);}@GetMapping("/{entityName}/get/{id}")public Result get(@PathVariable String entityName, @PathVariable Long id) throws Exception {BaseMapper<T> mapper = getMapper(entityName);return Result.success(mapper.selectById(id));}@GetMapping("/{entityName}/all")public Result get(@PathVariable String entityName) throws Exception {BaseMapper<T> mapper = getMapper(entityName);return Result.success(mapper.selectList(new QueryWrapper<>()));}@PostMapping("/{entityName}/insert")public Result insert(@PathVariable String entityName,@RequestBody T entity) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);ValidateService<T> validateService = new ValidateServiceImpl<>();validateService.validate(entity,baseMapper);baseMapper.insert(entity);return Result.success();}@PutMapping("/{entityName}/update")public Result update(@PathVariable String entityName,@RequestBody T entity) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);// 使用Spring注入验证服务// 验证数据ValidateService<T> validateService = new ValidateServiceImpl<>();validateService.validate(entity, baseMapper);baseMapper.updateById(entity);return Result.success();}@PutMapping("/{entityName}/delete/{id}")public Result update(@PathVariable String entityName,@PathVariable Long id) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);baseMapper.deleteById(id);return Result.success();}@PutMapping("/{entityName}/deleteByIds")public Result update(@PathVariable String entityName,@RequestBody Collection<Long> ids) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);baseMapper.deleteBatchIds(ids);return Result.success();}// 可以添加其他通用的增删改查方法...@PostMapping("/{entityName}/list")public Result update(@PathVariable String entityName, @RequestBody PageRequestVo pageRequest) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);System.out.println("pageRequest = " + pageRequest);PageHelper.startPage(pageRequest.getPage(), pageRequest.getSize());QueryWrapper<T> queryWrapper = new QueryWrapper<>();List<String> sort = pageRequest.getSorts();if (sort!=null&& !sort.isEmpty()) {sort.forEach(o -> {if (o.endsWith("Asc")) {queryWrapper.orderByAsc(o.replace("Asc", ""));}else if (o.endsWith("Desc")) {queryWrapper.orderByDesc(o.replace("Desc", ""));}else {queryWrapper.orderByAsc(o);}});}if (!MapUtil.isEmpty(pageRequest.getParams())){// 处理查询参数pageRequest.getParams().forEach((field, values) -> {if (values != null && !values.isEmpty()) {if (field.endsWith("Like")) {for (Object value : values) {queryWrapper.like(field.replace("Like",""), value);}}else if (field.endsWith("Is")){for (Object value : values) {queryWrapper.eq(field.replace("Like",""), value);}}else if (field.endsWith("Between")){queryWrapper.between(field.replace("Between",""), values.get(0), values.get(1));}else if (field.endsWith("IsNull")){queryWrapper.isNull(field.replace("IsNull",""));}else if (field.endsWith("IsNotNull")){queryWrapper.isNotNull(field.replace("IsNotNull",""));}else if (field.endsWith("NotIn")){queryWrapper.notIn(field.replace("NotIn",""), values);}else if (field.endsWith("In")){queryWrapper.in(field.replace("In",""), values);}else if (field.endsWith("Gt")){queryWrapper.gt(field.replace("Gt",""), values.get(0));}else if (field.endsWith("Ge")){queryWrapper.ge(field.replace("Ge",""), values.get(0));}else if (field.endsWith("Lt")){queryWrapper.lt(field.replace("Lt",""), values.get(0));}else if (field.endsWith("Le")){queryWrapper.le(field.replace("Le",""), values.get(0));}else if (field.endsWith("Eq")){for (Object value : values) {queryWrapper.eq(field.replace("Eq",""), value);}}else if (field.endsWith("Ne")){queryWrapper.ne(field.replace("Ne",""), values.get(0));}else if (field.endsWith("NotBetween")){queryWrapper.notBetween(field.replace("NotBetween",""), values.get(0), values.get(1));}else {for (Object value : values) {queryWrapper.eq(field, value);}}}});}return Result.success(PageInfo.of(baseMapper.selectList(queryWrapper)));}}

2.创建业务实体和mapper接口,

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class User extends Account {@TableId(type = IdType.AUTO)private Integer id;private String username;private String password;private String name;private String avatar;private String role;private String sex;private String phone;private String email;private String info;private String birth;@TableField(exist = false)private Integer blogCount;@TableField(exist = false)private Integer likesCount;@TableField(exist = false)private Integer collectCount;}

mapper接口:

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

postman测试

http://www.dtcms.com/wzjs/548023.html

相关文章:

  • 怎么做网站设购物网站排行
  • wordpress 欲思西安seo服务公司
  • 郑州红酒网站建设网络公司官网
  • 建功能网站学校网站网站建设
  • 有什么网站做微商网站转为移动网站
  • 阿里巴巴网站建设规划电商平台推广公司
  • 网站建设创业计划书网易企业邮箱服务
  • 微信网站 手机网站大连模板建站定制
  • 西宁市建设网站公司电话西安做网站app
  • 公司网站改版方案盛世网站历史频道怎么做
  • 免费空间asp网站wordpress是瀑布流吗
  • 各类东莞微信网站建设如何把自己电脑做网站服务器
  • 升腾d9116 做网站定制系统开发平台
  • 有专业做网站的吗gre考wordpress镜像系统
  • 建设项目环保验收公示网站seo专员岗位职责
  • 专注高密网站建设开放大学门户网站建设
  • 合肥制作网站的公司简介新闻资讯专业翻译公司
  • 在线音乐网站开发数据库完全菜鸟七天学会建网站
  • 邢台市桥西住房建设局网站哈市那里网站做的好
  • 莆田网站设计wordpress搭建单机版
  • 化妆品网站开发步骤品牌推广计划书怎么写
  • 清远企业网站排名求大神帮忙做网站
  • 网站商城是用什么框架做的市场营销策划公司
  • 广州网站关键排名做特卖的网站
  • 什么是传统网站深圳网站建设公司那家好
  • 宣城网站建设个人备案的网站可以做商城吗
  • 无忧网站建设报价什么好的设计网站
  • 网站上做百度广告赚钱么安装wordpress时出现空白
  • 南京网站建设的公司潮州东莞网站建设
  • 网站建设理由中山百度网站排名