From fa259b84e162697313f66f9db9a98d4af3ea1865 Mon Sep 17 00:00:00 2001 From: antrain <2464210826@qq.com> Date: Mon, 21 Sep 2020 19:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9F=BA=E9=87=91=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=AB=AF=E6=8D=90=E8=B5=A0=E4=BA=BA=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++- .../controller/ConstantItemController.java | 8 ++++ .../neuedu/controller/DonorController.java | 37 +++++++++++-------- .../com/neuedu/mapper/ConstantItemMapper.java | 10 ++++- .../neuedu/service/IConstantItemService.java | 7 +++- .../service/impl/ConstantItemServiceImpl.java | 18 ++++++++- .../com/neuedu/mapper/ConstantItemMapper.xml | 6 ++- 7 files changed, 71 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 79f7a71..4159bf6 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,11 @@ + gateway: 网关配置 + mail: 邮箱服务 + pojo: 实体类 -+ utils: 一些工具类 \ No newline at end of file ++ utils: 一些工具类 + +### 方法请求参数 ++ restful风格 ++ get : 获取数据 ++ post : 增加数据 ++ put : 修改数据 ++ delete: 删除数据 \ No newline at end of file diff --git a/admin/src/main/java/com/neuedu/controller/ConstantItemController.java b/admin/src/main/java/com/neuedu/controller/ConstantItemController.java index 05fca0c..725a4dc 100644 --- a/admin/src/main/java/com/neuedu/controller/ConstantItemController.java +++ b/admin/src/main/java/com/neuedu/controller/ConstantItemController.java @@ -73,6 +73,14 @@ public class ConstantItemController { return CommonResult.success(); } + /** + * 通过主键id在表中查找信息 + */ + @GetMapping("/type/{id}") + public CommonResult getListByTypeId(@PathVariable int id) { + return CommonResult.success(iConstantItemService.getListByTypeId(id)); + } + /** * 向表中添加一条记录 */ diff --git a/admin/src/main/java/com/neuedu/controller/DonorController.java b/admin/src/main/java/com/neuedu/controller/DonorController.java index c017b4f..a1b3a46 100644 --- a/admin/src/main/java/com/neuedu/controller/DonorController.java +++ b/admin/src/main/java/com/neuedu/controller/DonorController.java @@ -1,23 +1,20 @@ package com.neuedu.controller; -import java.util.Map; -import javax.annotation.Resource; - -import com.neuedu.service.IDonorService; -import com.neuedu.pojo.Donor; - -import com.neuedu.util.CommonResult; -import com.neuedu.util.InitUtil; - import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; - -import org.springframework.web.bind.annotation.*; - - +import com.neuedu.pojo.Donor; +import com.neuedu.service.IDonorService; +import com.neuedu.util.CommonResult; +import com.neuedu.util.InitUtil; +import com.neuedu.util.ShaUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.Map; /** @@ -46,6 +43,7 @@ public class DonorController { int limit = Integer.parseInt(param.get("limit").toString()); QueryWrapper wrapper = new QueryWrapper<>(); InitUtil.initEq(param, wrapper, "active"); + InitUtil.initLike(param, wrapper, "username"); IPage page = new Page<>(num, limit); return CommonResult.success(iDonorService.page(page, wrapper)); } @@ -78,9 +76,14 @@ public class DonorController { /** * 向表中添加一条记录 - */ + */ @PostMapping() public CommonResult save(@RequestBody Donor iDonor) { + if (StringUtils.isEmpty(iDonor.getPassword())){ + iDonor.setPassword(ShaUtil.getSHA256("123456")); + } else { + iDonor.setPassword(ShaUtil.getSHA256(iDonor.getPassword())); + } if (iDonorService.save(iDonor)){ return CommonResult.successMsg("添加成功"); } @@ -89,16 +92,18 @@ public class DonorController { /** * 根据表中的主键修改 根据表中字段相应的修改,如果存在则修改 - */ + */ @PutMapping("/{id}") public CommonResult update(@RequestBody Donor iDonor, @PathVariable int id) { iDonor.setId(id); + if (!StringUtils.isEmpty(iDonor.getPassword())){ + iDonor.setPassword(ShaUtil.getSHA256(iDonor.getPassword())); + } if (iDonorService.updateById(iDonor)){ return CommonResult.successMsg("修改成功"); } return CommonResult.failed("修改失败"); } - /** * active 字段 相当于激活一样 设置字段的有效性 active=1 有效 */ diff --git a/admin/src/main/java/com/neuedu/mapper/ConstantItemMapper.java b/admin/src/main/java/com/neuedu/mapper/ConstantItemMapper.java index 661b8b6..081e7fc 100644 --- a/admin/src/main/java/com/neuedu/mapper/ConstantItemMapper.java +++ b/admin/src/main/java/com/neuedu/mapper/ConstantItemMapper.java @@ -1,7 +1,13 @@ package com.neuedu.mapper; -import com.neuedu.pojo.ConstantItem; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.neuedu.pojo.ConstantItem; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; /** *

@@ -12,5 +18,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @since 2020-09-17 */ public interface ConstantItemMapper extends BaseMapper { - + List> getListByTypeId(@Param(Constants.WRAPPER) Wrapper wrapper); } diff --git a/admin/src/main/java/com/neuedu/service/IConstantItemService.java b/admin/src/main/java/com/neuedu/service/IConstantItemService.java index ed77468..e002059 100644 --- a/admin/src/main/java/com/neuedu/service/IConstantItemService.java +++ b/admin/src/main/java/com/neuedu/service/IConstantItemService.java @@ -1,7 +1,10 @@ package com.neuedu.service; -import com.neuedu.pojo.ConstantItem; import com.baomidou.mybatisplus.extension.service.IService; +import com.neuedu.pojo.ConstantItem; + +import java.util.List; +import java.util.Map; /** *

@@ -12,5 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService; * @since 2020-09-17 */ public interface IConstantItemService extends IService { - + List> getListByTypeId(int id); } diff --git a/admin/src/main/java/com/neuedu/service/impl/ConstantItemServiceImpl.java b/admin/src/main/java/com/neuedu/service/impl/ConstantItemServiceImpl.java index d195ffe..976782a 100644 --- a/admin/src/main/java/com/neuedu/service/impl/ConstantItemServiceImpl.java +++ b/admin/src/main/java/com/neuedu/service/impl/ConstantItemServiceImpl.java @@ -1,11 +1,16 @@ package com.neuedu.service.impl; -import com.neuedu.pojo.ConstantItem; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.neuedu.mapper.ConstantItemMapper; +import com.neuedu.pojo.ConstantItem; import com.neuedu.service.IConstantItemService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + /** *

* 常数项 服务实现类 @@ -16,5 +21,14 @@ import org.springframework.stereotype.Service; */ @Service public class ConstantItemServiceImpl extends ServiceImpl implements IConstantItemService { + @Resource + private ConstantItemMapper constantItemMapper; + @Override + public List> getListByTypeId(int id) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("active", 1).eq("type_id",id); + wrapper.orderByAsc("sort"); + return constantItemMapper.getListByTypeId(wrapper) ; + } } diff --git a/admin/src/main/resources/com/neuedu/mapper/ConstantItemMapper.xml b/admin/src/main/resources/com/neuedu/mapper/ConstantItemMapper.xml index f43a938..319d40f 100644 --- a/admin/src/main/resources/com/neuedu/mapper/ConstantItemMapper.xml +++ b/admin/src/main/resources/com/neuedu/mapper/ConstantItemMapper.xml @@ -1,5 +1,9 @@ - + -- Gitee