本帖最后由 小石姐姐 于 2019-7-25 18:17 编辑
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>品牌管理</title>
<!--页面样式-->
<link rel="stylesheet" href="../css/elementui.css">
</head>
<body>
<div id="app">
</div>
</body>
<script src="../js/vue(1).js"></script>
<script src="../js/elementui(1).js"></script>
<script src="../js/axios.js"></script>
<script>
new Vue({
el: "#app",
data() {
return {
tableData: []
}
},
created() {
axios.get("/brand/findAll").then(response=> {
alert(JSON.stringify(response))
});
}
})
</script>
</html>
package com.qingcheng.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qingcheng.dao.BrandMapper;
import com.qingcheng.entity.PageResult;
import com.qingcheng.pojo.Brand;
import com.qingcheng.service.goods.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
import java.util.Map;
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private BrandMapper brandMapper;
/**
* 查询所有
*
* @return List<Brand>
*/
@Override
public List<Brand> findAll() {
return brandMapper.selectAll();
}
/**
* @param page 页码
* @param size 每一页的记录数
* @return 分页结果
*/
@Override
public PageResult<Brand> findPage(int page, int size) {
PageHelper.startPage(page, size);
Page<Brand> brands = (Page<Brand>) brandMapper.selectAll();
return new PageResult<Brand>(brands.getTotal(), brands.getResult());
}
/**
* an条件查询
*
* @param searchMap
* @return List<Brand>
*/
@Override
public List<Brand> findList(Map<String, Object> searchMap) {
Example example = createExample(searchMap);
return brandMapper.selectByExample(example);
}
/**
* 条件查询 分页
*
* @param searchMap
* @param page
* @param size
* @return PageResult<Brand>
*/
@Override
public PageResult<Brand> findPage(Map<String, Object> searchMap, int page, int size) {
PageHelper.startPage(page, size);
Example example = createExample(searchMap);
Page<Brand> brands = (Page<Brand>) brandMapper.selectByExample(example);
return new PageResult<Brand>(brands.getTotal(), brands.getResult());
}
/**
* 按id查询
*
* @param id
* @return Brand
*/
@Override
public Brand findById(Integer id) {
return brandMapper.selectByPrimaryKey(id);
}
/**
* 新增
*
* @param brand
*/
@Override
public void add(Brand brand) {
brandMapper.insertSelective(brand);
}
/**
* 修改数据
*
* @param brand
*/
@Override
public void update(Brand brand) {
brandMapper.updateByPrimaryKeySelective(brand);
}
/**
* 删除数据
*
* @param id
*/
@Override
public void delete(Integer id) {
brandMapper.deleteByPrimaryKey(id);
}
/**
* 条件查询抽取为私有方法
*/
private Example createExample(Map<String, Object> searchMap) {
Example example = new Example(Brand.class);//需要查询的具体类
Example.Criteria criteria = example.createCriteria();
//需要对searchMap进行!null判断
if (searchMap != null) {
// 名称查询 模糊查询 判断值不能为空 且不是空字符串
if (searchMap.get("name") != null && !"".equals(searchMap.get("name"))) {
//模糊查询方法参数是属性 String 值Object 需要强转
criteria.andLike("name", "%" + (String) searchMap.get("name") + "%");
}
// 首字母查询 判断值不能为空 且不是空字符串
if (searchMap.get("letter") != null && !"".equals(searchMap.get("letter"))) {
//匹配查询
criteria.andEqualTo("letter", (String) searchMap.get("letter"));
}
}
return example;
}
}
|
|