From 2b371853036098f1ef429ba25430513e2b7166b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Wed, 8 Feb 2023 18:18:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springbootkwan/SpringBootKwanApplication.java | 2 ++ .../springbootkwan/controller/UserController.java | 11 +++++++++-- .../java/com/kwan/springbootkwan/entity/User.java | 8 ++++---- .../com/kwan/springbootkwan/mapper/UserMapper.java | 1 + .../kwan/springbootkwan/schedule/ScheduleTest.java | 2 +- .../springbootkwan/schedule/ScheduleTestTwo.java | 2 +- .../kwan/springbootkwan/service/IUserService.java | 7 +++++++ .../springbootkwan/service/impl/UserServiceImpl.java | 10 ++++++++++ .../mapper/AdsDimFinancialYearWeekInfoDao.xml | 2 +- src/main/resources/mapper/UserMapper.xml | 12 ++++++++++++ 10 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java b/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java index cc603b3..15bcf6e 100644 --- a/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java +++ b/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java @@ -1,4 +1,5 @@ package com.kwan.springbootkwan; + import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.boot.SpringApplication; @@ -12,6 +13,7 @@ public class SpringBootKwanApplication { public static void main(String[] args) { SpringApplication.run(SpringBootKwanApplication.class, args); + System.out.println("------------------SpringBootKwan应用启动成功--------------------"); } } diff --git a/src/main/java/com/kwan/springbootkwan/controller/UserController.java b/src/main/java/com/kwan/springbootkwan/controller/UserController.java index 158bb87..2de7df5 100644 --- a/src/main/java/com/kwan/springbootkwan/controller/UserController.java +++ b/src/main/java/com/kwan/springbootkwan/controller/UserController.java @@ -6,6 +6,7 @@ import com.kwan.springbootkwan.service.IUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpRequest; import org.springframework.validation.BindingResult; @@ -48,8 +49,8 @@ public class UserController { } - @PostMapping(value = "/student",produces = "application/json;charset=utf-8") - public List addUser(@RequestBody @Validated Student student, BindingResult result ) throws UnsupportedEncodingException { + @PostMapping(value = "/student", produces = "application/json;charset=utf-8") + public List addUser(@RequestBody @Validated Student student, BindingResult result) throws UnsupportedEncodingException { List errors = new ArrayList<>(); if (result.hasErrors()) { List allErrors = result.getAllErrors(); @@ -60,4 +61,10 @@ public class UserController { log.info("errors={}", errors); return errors; } + + @ApiOperation(value = "根据name获取用户信息", notes = "根据name获取用户信息") + @RequestMapping(value = "/getUserByName", method = RequestMethod.GET) + public User getUserByName(@RequestParam String sex) { + return userService.getUserByName(sex); + } } \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/User.java b/src/main/java/com/kwan/springbootkwan/entity/User.java index 20546ac..d33152b 100644 --- a/src/main/java/com/kwan/springbootkwan/entity/User.java +++ b/src/main/java/com/kwan/springbootkwan/entity/User.java @@ -5,13 +5,17 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data @Builder @TableName(value = "user") @ApiModel(value = "用户基本信息") +@AllArgsConstructor +@NoArgsConstructor public class User { @ApiModelProperty(value = "主键id") @TableId(value = "id", type = IdType.AUTO) @@ -20,8 +24,4 @@ public class User { private String name; @ApiModelProperty(value = "性别") private String sex; - @ApiModelProperty(value = "密码") - private String pwd; - @ApiModelProperty(value = "邮箱") - private String email; } diff --git a/src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java b/src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java index 4f210e9..908e069 100644 --- a/src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java +++ b/src/main/java/com/kwan/springbootkwan/mapper/UserMapper.java @@ -15,5 +15,6 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface UserMapper extends BaseMapper { + User getUserByName(String sex); } diff --git a/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java b/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java index 280c60c..059cf87 100644 --- a/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java +++ b/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTest.java @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; @Slf4j public class ScheduleTest { - @Scheduled(cron = "0/10 * * * * ?") +// @Scheduled(cron = "0/10 * * * * ?") public void execute() { log.info("Scheduled task is running ... ..."); } diff --git a/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java b/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java index 273ffcf..2bab388 100644 --- a/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java +++ b/src/main/java/com/kwan/springbootkwan/schedule/ScheduleTestTwo.java @@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit; @Component @Slf4j public class ScheduleTestTwo { - @Scheduled(cron = "0/10 * * * * *") + // @Scheduled(cron = "0/10 * * * * *") public void second() throws InterruptedException { log.info("Second scheduled task is running... ..."); TimeUnit.SECONDS.sleep(5); diff --git a/src/main/java/com/kwan/springbootkwan/service/IUserService.java b/src/main/java/com/kwan/springbootkwan/service/IUserService.java index cd6b240..1cdb87d 100644 --- a/src/main/java/com/kwan/springbootkwan/service/IUserService.java +++ b/src/main/java/com/kwan/springbootkwan/service/IUserService.java @@ -21,4 +21,11 @@ public interface IUserService extends IService { */ User getUserById(Integer id); + /** + * 根据姓名查询 + * + * @param sex + * @return + */ + User getUserByName(String sex); } diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/UserServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/UserServiceImpl.java index fc0b803..f72cbf8 100644 --- a/src/main/java/com/kwan/springbootkwan/service/impl/UserServiceImpl.java +++ b/src/main/java/com/kwan/springbootkwan/service/impl/UserServiceImpl.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Objects; @Service public class UserServiceImpl extends ServiceImpl implements IUserService { @@ -24,4 +25,13 @@ public class UserServiceImpl extends ServiceImpl implements IU public User getUserById(Integer id) { return userMapper.selectById(id); } + + @Override + public User getUserByName(String sex) { + User userByName = userMapper.getUserByName(sex); + if (Objects.isNull(userByName)) { + userByName = new User(); + } + return userByName; + } } \ No newline at end of file diff --git a/src/main/resources/mapper/AdsDimFinancialYearWeekInfoDao.xml b/src/main/resources/mapper/AdsDimFinancialYearWeekInfoDao.xml index ccd4001..9bcbab2 100644 --- a/src/main/resources/mapper/AdsDimFinancialYearWeekInfoDao.xml +++ b/src/main/resources/mapper/AdsDimFinancialYearWeekInfoDao.xml @@ -1,6 +1,6 @@ - + diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index 146a35d..228606a 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -1,5 +1,17 @@ + + + + + + + + -- GitLab