diff --git a/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java b/src/main/java/com/kwan/springbootkwan/SpringBootKwanApplication.java index cc603b3be2e283bcabbbb228cb0a7494e9207a3d..15bcf6e6f224beb2ae9a64e8b980cb918a52235a 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 158bb87917bf23b2871818a1b4e4624a35c2d00d..2de7df596c7428e59c5b01dd2243355b3a2c557d 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 20546ac70f2c1930d6fa6c1267e8f08d07ae17b9..d33152bc67e7fa0fc0f6ff109e54587ca6233a15 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 4f210e9963ed54bf7cd16f67bde2c40014887978..908e0695fa42ab5e1bdfdf2e9494100b5d26384b 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 280c60c50a931a3314246310fb8f2740f881936e..059cf87230ed3a8deb267515d592ad92e11e932a 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 273ffcf5e635c7535bcc69422b3a1202b5db15c8..2bab388f84f5d07b66ed656c30bf15178cf392e5 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 cd6b2403888b23cb579c5879eb8498c435ce4844..1cdb87d2ed49beaef9b57b6da7a9026c8c015c08 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 fc0b8038629a15565240f12590f25bfc3e598554..f72cbf85afa96b1e3495b9f8235bccea78d184a0 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 ccd4001d872f6e97140d67c6cdeceb1e35bfe74c..9bcbab2b1b6490c3268cee9ce8dc40f574a38978 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 146a35d58c9b6ce5bb52820d81e429fc4d31d042..228606a16535914d1f77622224cdf6a6535bef39 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -1,5 +1,17 @@ + + + + + + + +