|
|
@@ -1,16 +1,21 @@
|
|
|
package com.example.demo.controllers;
|
|
|
|
|
|
-import com.example.demo.mapper.PoiMapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.example.demo.pojo.Poi;
|
|
|
+import com.example.demo.service.IPoiService;
|
|
|
+import com.example.demo.service.Impl.PoiServiceImpI;
|
|
|
import com.example.demo.vo.PoiVo;
|
|
|
import com.example.demo.vo.Result;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import lombok.var;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@Slf4j
|
|
|
@@ -18,37 +23,30 @@ import java.util.List;
|
|
|
public class PoiController {
|
|
|
|
|
|
@Autowired
|
|
|
- private PoiMapper poiMapper;
|
|
|
+ private PoiServiceImpI poiService;
|
|
|
|
|
|
@GetMapping("/list")
|
|
|
public Result list(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "1") int pageSize){
|
|
|
- var poi1 = new PoiVo();
|
|
|
- poi1.name = "张三";
|
|
|
- poi1.description = "123";
|
|
|
-
|
|
|
- var poi2 = new PoiVo();
|
|
|
- poi2.name = "李四";
|
|
|
- poi2.description = "1234";
|
|
|
- List<PoiVo> poiList = new ArrayList<>();
|
|
|
- poiList.add(poi1);
|
|
|
- poiList.add(poi2);
|
|
|
- return Result.success(poiList);
|
|
|
+ Page<Poi> page = new Page<>(1, 2);
|
|
|
+ IPage<Poi> pageres = poiService.page(page);
|
|
|
+
|
|
|
+ List<PoiVo> poiVoList = pageres.getRecords().stream().map(poi-> {
|
|
|
+ PoiVo poiVo = new PoiVo();
|
|
|
+ BeanUtils.copyProperties(poi, poiVo);
|
|
|
+ return poiVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return Result.success(poiVoList);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/detail/{id}")
|
|
|
public Result detail(@PathVariable int id){
|
|
|
-// var poi1 = new PoiVo();
|
|
|
-// poi1.name = "张三";
|
|
|
-// poi1.description = "123";
|
|
|
-// List<PoiVo> poiList = new ArrayList<>();
|
|
|
-// poiList.add(poi1);
|
|
|
-
|
|
|
- Poi poi = poiMapper.selectById(id);
|
|
|
+ Poi poi = poiService.getById(id);
|
|
|
return Result.success(poi);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/add")
|
|
|
public Result add(@RequestBody Poi info){
|
|
|
+ poiService.save(info);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|