feat: add Coach CRUD - controller, mapper, service layer
This commit is contained in:
parent
527f9cf9c7
commit
ba5069a346
5 changed files with 105 additions and 1 deletions
|
|
@ -0,0 +1,26 @@
|
||||||
|
package edu.situ.stlserver.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import edu.situ.stlserver.dao.CoachMapper;
|
||||||
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
|
import edu.situ.stlserver.model.vo.HttpResult;
|
||||||
|
import edu.situ.stlserver.service.CoachService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/coach")
|
||||||
|
public class CoachController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CoachService coachService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public HttpResult getByPage(Integer page , Integer limit , Coach coach)
|
||||||
|
{
|
||||||
|
return HttpResult.success(coachService.getByPage( page,limit,coach));
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/java/edu/situ/stlserver/dao/CoachMapper.java
Normal file
33
src/main/java/edu/situ/stlserver/dao/CoachMapper.java
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package edu.situ.stlserver.dao;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CoachMapper {
|
||||||
|
// 查询全部
|
||||||
|
@Select(value = "SELECT * FROM coach")
|
||||||
|
List<Coach> selectAll();
|
||||||
|
|
||||||
|
@Select(value = {
|
||||||
|
"<script>",
|
||||||
|
"SELECT * FROM `coach`",
|
||||||
|
"<where>",
|
||||||
|
"<if test=\"name != null AND name != ''\"> AND `name` LIKE CONCAT('%', #{name}, '%')</if>",
|
||||||
|
"<if test=\"sex != null AND sex != 0\"> AND `sex` = #{sex}</if>",
|
||||||
|
"<if test=\"quitDate != null AND quitDate != 1\">",
|
||||||
|
"<choose>",
|
||||||
|
"<when test=\"quitDate == 2\"> AND quit_date IS NULL</when>",
|
||||||
|
"<when test=\"quitDate == 3\"> AND quit_date IS NOT NULL</when>",
|
||||||
|
"</choose>",
|
||||||
|
"</if>",
|
||||||
|
"</where>",
|
||||||
|
"</script>"
|
||||||
|
})
|
||||||
|
List<Coach> select(Coach coach);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package edu.situ.stlserver.model.vo;
|
package edu.situ.stlserver.model.vo;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
@ -52,6 +53,6 @@ public class HttpResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toJsonStr(){
|
public String toJsonStr(){
|
||||||
return JSONUtil.toJsonStr(this)
|
return JSONUtil.toJsonStr(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
src/main/java/edu/situ/stlserver/service/CoachService.java
Normal file
13
src/main/java/edu/situ/stlserver/service/CoachService.java
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
package edu.situ.stlserver.service;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface CoachService {
|
||||||
|
List<Coach> getAll();
|
||||||
|
PageInfo<Coach> getByPage(Integer page,Integer limit,Coach coach);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package edu.situ.stlserver.service.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import edu.situ.stlserver.dao.CoachMapper;
|
||||||
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
|
import edu.situ.stlserver.service.CoachService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CoachServiceImpl implements CoachService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CoachMapper coachMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Coach> getAll() {
|
||||||
|
return coachMapper.selectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageInfo<Coach> getByPage(Integer page, Integer limit, Coach coach) {
|
||||||
|
if(page == null) page=1;
|
||||||
|
if(limit == null) limit=10;
|
||||||
|
PageHelper.startPage(page,limit);
|
||||||
|
return new PageInfo<>(coachMapper.select(coach));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue