From eeac34f266572ceffdc651658777f9bb9f21de2f Mon Sep 17 00:00:00 2001 From: yangmengchuan Date: Tue, 7 Jan 2025 14:26:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 + .gitignore | 33 +++++ pom.xml | 140 ++++++++++++++++++ .../com/keyware/htey/HteyApplication.java | 13 ++ .../htey/config/MybatisPlusConfig.java | 18 +++ .../htey/controller/user/UserController.java | 97 ++++++++++++ .../java/com/keyware/htey/entity/User.java | 15 ++ .../com/keyware/htey/mapper/UserMapper.java | 14 ++ .../htey/service/impl/UserServiceImpl.java | 15 ++ .../keyware/htey/service/itf/UserService.java | 7 + src/main/resources/application.yml | 30 ++++ 11 files changed, 384 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/keyware/htey/HteyApplication.java create mode 100644 src/main/java/com/keyware/htey/config/MybatisPlusConfig.java create mode 100644 src/main/java/com/keyware/htey/controller/user/UserController.java create mode 100644 src/main/java/com/keyware/htey/entity/User.java create mode 100644 src/main/java/com/keyware/htey/mapper/UserMapper.java create mode 100644 src/main/java/com/keyware/htey/service/impl/UserServiceImpl.java create mode 100644 src/main/java/com/keyware/htey/service/itf/UserService.java create mode 100644 src/main/resources/application.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c7ab514 --- /dev/null +++ b/pom.xml @@ -0,0 +1,140 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + com.keyware + HTEY + 0.0.1-SNAPSHOT + HTEY + HTEY + + + + + + + + + + + + + + + 8 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-web-services + + + org.springframework.session + spring-session-core + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-actuator + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.3.1 + + + + org.springdoc + springdoc-openapi-ui + 1.6.14 + + + + + + com.oracle.database.jdbc + ojdbc8 + 19.8.0.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + diff --git a/src/main/java/com/keyware/htey/HteyApplication.java b/src/main/java/com/keyware/htey/HteyApplication.java new file mode 100644 index 0000000..ae7f2c8 --- /dev/null +++ b/src/main/java/com/keyware/htey/HteyApplication.java @@ -0,0 +1,13 @@ +package com.keyware.htey; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HteyApplication { + + public static void main(String[] args) { + SpringApplication.run(HteyApplication.class, args); + } + +} diff --git a/src/main/java/com/keyware/htey/config/MybatisPlusConfig.java b/src/main/java/com/keyware/htey/config/MybatisPlusConfig.java new file mode 100644 index 0000000..da679c3 --- /dev/null +++ b/src/main/java/com/keyware/htey/config/MybatisPlusConfig.java @@ -0,0 +1,18 @@ +package com.keyware.htey.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MybatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.ORACLE)); // 数据库类型 + return interceptor; + } +} \ No newline at end of file diff --git a/src/main/java/com/keyware/htey/controller/user/UserController.java b/src/main/java/com/keyware/htey/controller/user/UserController.java new file mode 100644 index 0000000..969fb90 --- /dev/null +++ b/src/main/java/com/keyware/htey/controller/user/UserController.java @@ -0,0 +1,97 @@ +package com.keyware.htey.controller.user; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.keyware.htey.entity.User; +import com.keyware.htey.service.itf.UserService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +/** + * @author yangmengchuan + * @date 2025/1/7 + * @description 用户接口 + */ +@Controller +@RequestMapping("/user") +@Tag(name = "User API", description = "用户管理接口") +public class UserController { + @Autowired + private UserService userService; + /** + * @author yangmengchuan + * @date 2025/1/7 + * @description 分页获取所有用户 + */ + @GetMapping("/selectAll") + @ResponseBody + @Operation(summary = "分页查询用户", description = "返回查询用户信息") + @ApiResponse(responseCode = "200", description = "成功获取用户信息") + public Page selectAll(@RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int pageSize){ + // 创建分页对象 + Page pageParam = new Page<>(pageNum, pageSize); + + // 创建查询条件 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.notLike("USER_NAME","安全保密员") + .notLike("USER_NAME","系统管理员") + .notLike("USER_NAME","安全审计员") + .notLike("USER_NAME","超级管理员"); // 模糊查询 + // 执行分页查询 + return userService.page(pageParam, queryWrapper); + } + /** + * @author yangmengchuan + * @date 2025/1/7 + * @description 根据id获取用户信息 + */ + @GetMapping("/selectById") + @ResponseBody + @Operation(summary = "根据id查询用户", description = "返回查询用户信息") + @ApiResponse(responseCode = "200", description = "成功获取用户信息") + public User selectById(@RequestParam String id){ + return userService.getById(id); + } + /** + * @author yangmengchuan + * @date 2025/1/7 + * @description 新增用户 + */ + @GetMapping("/addUser") + @ResponseBody + @Operation(summary = "新增用户", description = "返回新增用户信息") + @ApiResponse(responseCode = "200", description = "成功新增用户信息") + public boolean addUser(@RequestParam User user){ + return userService.save(user); + } + /** + * @author yangmengchuan + * @date 2025/1/7 + * @description 修改用户 + */ + @GetMapping("/updateUser") + @ResponseBody + @Operation(summary = "修改用户", description = "返回修改用户信息") + @ApiResponse(responseCode = "200", description = "成功修改用户信息") + public boolean updateUser(@RequestParam User user){ + return userService.updateById(user); + } + /** + * @author yangmengchuan + * @date 2025/1/7 + * @description 根据id进行删除 + */ + @GetMapping("/deleteUser") + @ResponseBody + @Operation(summary = "根据id删除用户", description = "返回删除用户信息") + @ApiResponse(responseCode = "200", description = "成功删除用户信息") + public boolean deleteUser(@RequestParam String id){ + return userService.removeById(id); + } +} diff --git a/src/main/java/com/keyware/htey/entity/User.java b/src/main/java/com/keyware/htey/entity/User.java new file mode 100644 index 0000000..54d5520 --- /dev/null +++ b/src/main/java/com/keyware/htey/entity/User.java @@ -0,0 +1,15 @@ +package com.keyware.htey.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +@Data +@TableName("K_USER") +public class User implements Serializable { + private String id; + private String userId; + private String userName; + private String password; + private String departId; +} diff --git a/src/main/java/com/keyware/htey/mapper/UserMapper.java b/src/main/java/com/keyware/htey/mapper/UserMapper.java new file mode 100644 index 0000000..93d4c31 --- /dev/null +++ b/src/main/java/com/keyware/htey/mapper/UserMapper.java @@ -0,0 +1,14 @@ +package com.keyware.htey.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.keyware.htey.entity.User; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author yangmengchuan + * @date 2025/1/7 + * @description 用户与数据库交互 + */ +@Mapper +public interface UserMapper extends BaseMapper { +} diff --git a/src/main/java/com/keyware/htey/service/impl/UserServiceImpl.java b/src/main/java/com/keyware/htey/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..5597e44 --- /dev/null +++ b/src/main/java/com/keyware/htey/service/impl/UserServiceImpl.java @@ -0,0 +1,15 @@ +package com.keyware.htey.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.keyware.htey.entity.User; +import com.keyware.htey.mapper.UserMapper; +import com.keyware.htey.service.itf.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service("userService") +public class UserServiceImpl extends ServiceImpl implements UserService{ + @Autowired + private UserMapper userMapper; + +} diff --git a/src/main/java/com/keyware/htey/service/itf/UserService.java b/src/main/java/com/keyware/htey/service/itf/UserService.java new file mode 100644 index 0000000..5aa6f28 --- /dev/null +++ b/src/main/java/com/keyware/htey/service/itf/UserService.java @@ -0,0 +1,7 @@ +package com.keyware.htey.service.itf; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.keyware.htey.entity.User; + +public interface UserService extends IService { +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..d9cc9d4 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,30 @@ +spring: + application: + name: HTEY + datasource: + url: jdbc:oracle:thin:@172.16.36.140:1521:orcl + username: kdhtey + password: 123456 + driver-class-name: oracle.jdbc.OracleDriver +# secondary: +# url: jdbc:oscar://172.16.36.232:2003/OSRDB +# username: tykd +# password: 123456 +# driver-class-name: com.oscar.Driver +#mybatis日志打印 +mybatis: + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +#日志级别及打印 +logging: + level: + com.baomidou.mybatisplus: DEBUG + com.keyware.htey.mapper: DEBUG # 替换为您的 Mapper 接口所在的包名 +#swagger +springdoc: + swagger-ui: + path: /swagger-ui.html # Swagger UI 的访问路径 + enabled: true # 是否启用 Swagger UI + api-docs: + path: /v3/api-docs # OpenAPI JSON 的访问路径 + enabled: true # 是否启用 OpenAPI JSON \ No newline at end of file