http://mayanze.com/(这里有我写的粗浅网站,欢迎留言)
GitHub地址:https://github.com/mayanze/mayanze-dcims
1.集成代码生成器:mybatis-plus-generator
2.封装公共 CRUD接口,设配jQuery MiniUI
package org.mayanze.dcims.base;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.mayanze.dcims.utils.BasePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* author: mayanze
* date: 2020/10/4 7:12 下午
*/
public class BaseController<T> {
@Autowired
private IService iService;
@GetMapping(value = "/queryPage",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public IPage<T> queryPage() {
BaseMapper<T> baseMapper = iService.getBaseMapper();
BasePage<T> basePage = new BasePage<>();
BasePage<T> TBasePage = baseMapper.selectPage(basePage, null);
return TBasePage;
}
@GetMapping(value = "/queryList",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public List<T> queryList() {
return iService.list();
}
@PostMapping(value = "/saveOrUpdateBatch")
public WebResponse saveOrUpdateBatch(String data,T t) {
List<?> ts = JSON.parseArray(data, t.getClass());
try {
iService.saveOrUpdateBatch(ts);
return new WebResponse().success();
} catch (Exception e) {
return new WebResponse().error(e.getMessage(),e.getStackTrace());
}
}
@DeleteMapping("/removeByIds")
public WebResponse removeByIds(String ids){
try {
iService.removeByIds(Arrays.asList(ids.split(",")));
return new WebResponse().success();
} catch (Exception e) {
return new WebResponse().error(e.getMessage(),e.getStackTrace());
}
}
}
三.使用公共CRUD接口
package org.mayanze.dcims.sys.controller;
import org.mayanze.dcims.base.BaseController;
import org.mayanze.dcims.sys.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 用户表 前端控制器
* </p>
*
* @author mayanze
* @since 2020-10-04
*/
@RestController
@RequestMapping("/sys/user")
public class UserController extends BaseController<User> {
}
四.页面调用
五.返回页面日期格式,有问题,配置
六.展示效果
版权声明:本文为weixin_40789566原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。