效果展示:LayUI Table 数据加载功能
LayUI Table 数据检索功能:
LayUI Table 新增
LayUI Table 编辑
LayUI Table 删除
LayUI 前端代码:
图书管理系统 - Layui
后端代码:
SpringBoot程序入口:
package com.zzg.teach;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
@MapperScan("com.zzg.teach.mapper")
public class Application{
public static void main(String[] args) {
// TODO Auto-generated method stub
SpringApplication.run(Application.class, args);
System.out.println("============= SpringBoot activiti Service Start Success =============");
}
}
domain:
package com.zzg.teach.domain;
public class BookCatrgory {
private String categoryId;
private String categoryName;
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId == null ? null : categoryId.trim();
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName == null ? null : categoryName.trim();
}
}
mapper:
package com.zzg.teach.mapper;
import java.util.List;
import java.util.Map;
import com.zzg.teach.domain.BookCatrgory;
public interface BookCatrgoryMapper {
int deleteByPrimaryKey(String categoryId);
int insert(BookCatrgory record);
int insertSelective(BookCatrgory record);
BookCatrgory selectByPrimaryKey(String categoryId);
int updateByPrimaryKeySelective(BookCatrgory record);
int updateByPrimaryKey(BookCatrgory record);
// 方法添加
List selectAll(Map paramter);
}
service:
package com.zzg.teach.service;
import java.util.List;
import java.util.Map;
import com.zzg.jreport.common.BaseService;
import com.zzg.jreport.common.page.PageData;
import com.zzg.jreport.common.page.PageParam;
import com.zzg.teach.domain.BookCatrgory;
public interface BookCatrgoryService extends BaseService{
// 方法梳理
List selectAll(Map paramter);
PageData selectAllPage(Map parame, PageParam rb);
}
seviceImpl:
package com.zzg.teach.service.impl;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzg.jreport.common.page.PageData;
import com.zzg.jreport.common.page.PageParam;
import com.zzg.teach.domain.BookCatrgory;
import com.zzg.teach.mapper.BookCatrgoryMapper;
import com.zzg.teach.service.BookCatrgoryService;
@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
public class BookCatrgoryServiceImpl implements BookCatrgoryService {
@Autowired
private BookCatrgoryMapper mapper;
@Override
public Long insert(BookCatrgory entity) {
// TODO Auto-generated method stub
if(StringUtils.isEmpty(entity.getCategoryId())) {
String uuid = UUID.randomUUID().toString();
entity.setCategoryId(StringUtils.remove(uuid, '-'));
}
Integer num = mapper.insertSelective(entity);
return Long.valueOf(num);
}
@Override
public void updateByPrimaryKeySelective(BookCatrgory entity) {
// TODO Auto-generated method stub
mapper.updateByPrimaryKeySelective(entity);
}
@Override
public BookCatrgory selectByPrimaryKey(String sid) {
// TODO Auto-generated method stub
return mapper.selectByPrimaryKey(sid);
}
@Override
public void deleteByPrimaryKey(String sid) {
// TODO Auto-generated method stub
mapper.deleteByPrimaryKey(sid);
}
@Override
public List selectAll(Map paramter) {
// TODO Auto-generated method stub
return mapper.selectAll(paramter);
}
@Override
public PageData selectAllPage(Map parame, PageParam rb) {
// TODO Auto-generated method stub
PageData pageData = new PageData();
PageHelper.startPage(rb.getPageNo(), rb.getLimit());
List rs = mapper.selectAll(parame);
PageInfo pageInfo = new PageInfo(rs);
pageData.setData(pageInfo.getList());
pageData.setPageNum(pageInfo.getPageNum());
pageData.setPageSize(pageInfo.getPageSize());
pageData.setTotalCount(pageInfo.getTotal());
return pageData;
}
}
controller:
package com.zzg.teach.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.zzg.jreport.common.controller.AbstractController;
import com.zzg.jreport.common.page.PageData;
import com.zzg.jreport.common.page.PageParam;
import com.zzg.jreport.response.JreportResponse;
import com.zzg.teach.domain.Book;
import com.zzg.teach.domain.BookCatrgory;
import com.zzg.teach.service.BookCatrgoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@Controller
@RequestMapping("/api/book/category")
@Api(value = "书籍类别Controlle", tags = "书籍类别操作服务")
public class BookCatrgoryController extends AbstractController {
@Autowired
private BookCatrgoryService service;
@ApiOperation(httpMethod = "POST", value = "用户对象保存")
@RequestMapping(value = "/insert", method = { RequestMethod.POST }, produces = "application/json;charset=UTF-8")
@ResponseBody
public JreportResponse insert(
@RequestBody @ApiParam(name = "用户对象", value = "json格式对象", required = true) BookCatrgory entity) {
Long engSid = service.insert(entity);
return JreportResponse.ok(engSid);
}
@ApiOperation(httpMethod = "POST", value = "用户对象删除")
@RequestMapping(value = "/delete/{categoryId}", method = { RequestMethod.DELETE }, produces = "application/json;charset=UTF-8")
@ResponseBody
public JreportResponse delete(
@PathVariable String categoryId) {
service.deleteByPrimaryKey(categoryId);
return JreportResponse.ok();
}
@ApiOperation(httpMethod = "POST", value = "用户对象更新")
@RequestMapping(value = "/update", method = { RequestMethod.POST }, produces = "application/json;charset=UTF-8")
@ResponseBody
public JreportResponse update(
@RequestBody @ApiParam(name = "用户对象", value = "json格式对象", required = true) BookCatrgory entity) {
service.updateByPrimaryKeySelective(entity);
return JreportResponse.ok();
}
@RequestMapping(value="/find", method={RequestMethod.GET}, produces = "application/json;charset=UTF-8")
@ResponseBody
@ApiOperation(httpMethod = "GET", value = "新宿分类查询")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryId", value = "主键", required = false, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "categoryName", value = "分类名称", required = false, dataType = "String", paramType = "query")
})
public String find(@RequestParam String categoryId, @RequestParam String categoryName) {
JSONObject obj = new JSONObject();
Map param = new HashMap();
if(!StringUtils.isEmpty(categoryId)) {
param.put("categoryId", categoryId);
}
if(!StringUtils.isEmpty(categoryName)) {
param.put("categoryName", categoryName);
}
List< BookCatrgory> list = service.selectAll(param);
obj.put("code", 0);
obj.put("data", list);
return obj.toJSONString();
}
@RequestMapping(value="/findByPage", method={RequestMethod.POST}, produces = "application/json;charset=UTF-8")
@ResponseBody
@ApiOperation(httpMethod = "POST", value = "用户分页查询")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "主键", required = false, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "username", value = "用户名称", required = false, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "email", value = "用户邮箱", required = false, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "isStaff", value = "是否在职:1 在职、2:离职", required = false, dataType = "Integer", paramType = "query"),
@ApiImplicitParam(name = "isActive", value = "激活状态:1 已激活、2:未激活", required = false, dataType = "Integer", paramType = "query")
})
public JreportResponse findByPage(@RequestBody @ApiParam(name = "用户对象", value = "json格式对象", required = true) JSONObject entity) {
Map param = JSONObject.toJavaObject(entity, Map.class);
PageParam rb = super.initPageBounds(param);
PageData< BookCatrgory> pageList = service.selectAllPage(param, rb);
return JreportResponse.ok(pageList);
}
}
mapper.xml 配置文件:
category_id, category_name
and category_id = #{categoryId}
and category_name LIKE CONCAT('%',#{categoryName},'%')
delete from book_catrgory
where category_id = #{categoryId,jdbcType=VARCHAR}
insert into book_catrgory (category_id, category_name)
values (#{categoryId,jdbcType=VARCHAR}, #{categoryName,jdbcType=VARCHAR})
insert into book_catrgory
category_id,
category_name,
#{categoryId,jdbcType=VARCHAR},
#{categoryName,jdbcType=VARCHAR},
update book_catrgory
category_name = #{categoryName,jdbcType=VARCHAR},
where category_id = #{categoryId,jdbcType=VARCHAR}
update book_catrgory
set category_name = #{categoryName,jdbcType=VARCHAR}
where category_id = #{categoryId,jdbcType=VARCHAR}
整体项目代码会在最近几天完整发布,并提供源码下载地址