diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..bd8b73b --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b568e91 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/excise-demo.iml b/.idea/excise-demo.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/excise-demo.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..be5f5c6 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..01af840 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a22ca1c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/demo/demo/.gitignore b/demo/demo/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/demo/demo/.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/demo/demo/pom.xml b/demo/demo/pom.xml new file mode 100644 index 0000000..e192665 --- /dev/null +++ b/demo/demo/pom.xml @@ -0,0 +1,121 @@ + + + 4.0.0 + com.example + demo + 0.0.1-SNAPSHOT + demo + demo + + 1.8 + UTF-8 + UTF-8 + 2.6.13 + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + + org.mybatis + mybatis + 3.5.7 + + + org.springframework.boot + spring-boot-starter-web + + + + com.mysql + mysql-connector-j + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.projectlombok + lombok + 1.18.22 + + + + + javax.validation + validation-api + 2.0.1.Final + + + + + org.hibernate.validator + hibernate-validator + 6.2.0.Final + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + demo.DemoApplication + true + + + + repackage + + repackage + + + + + + + + diff --git a/demo/demo/src/main/java/demo/Controller/RoleController.java b/demo/demo/src/main/java/demo/Controller/RoleController.java new file mode 100644 index 0000000..fdadd5f --- /dev/null +++ b/demo/demo/src/main/java/demo/Controller/RoleController.java @@ -0,0 +1,102 @@ +package demo.Controller; + +import demo.Entity.*; +import demo.Service.RoleService; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Date; +import java.util.List; + +@Slf4j +@RestController +@RequestMapping("/role") +@Validated +public class RoleController { + @Autowired + private RoleService roleService; + + //角色增删改查 + + /** + * @增 + * @param roleVO + * @return + */ + @PostMapping("/insert") + public Result insertRole(@RequestBody RoleVO roleVO) { + // 查询用户名是否被占用 + Role role = roleService.findByRoleName(roleVO.getRoleName()); + if (role==null){ + // 没有占用,新增 + // 创建一个LocalDateTime对象 + LocalDateTime localDateTime = LocalDateTime.now(); + // 将LocalDateTime转换为Instant + Instant instant = localDateTime.toInstant(ZoneOffset.UTC); + // 将Instant转换为Date + Date date = Date.from(instant); + roleService.insert(roleVO.getRoleName(), roleVO.getRoleCode(), date); + return Result.success("添加成功"); + }else { + return Result.error(401, "角色已有"); + } + } + + /** + * @删 + * @param roleName + * @return + */ + @DeleteMapping("/delete") + public Result deleteRole(@Valid String roleName) { + Role role = roleService.findByRoleName(roleName); + if (role==null){ + return Result.error(401, "角色不存在"); + }else { + roleService.deleteByRoleName(roleName); + return Result.success("删除成功"); + } + } + + @PutMapping("/update") + public Result updateRole(@Valid RoleVO roleVO) { + Role role = roleService.findByRoleName(roleVO.getRoleName()); + if (role==null){ + return Result.error(401, "角色不存在"); + }else { + // 创建一个LocalDateTime对象 + LocalDateTime localDateTime = LocalDateTime.now(); + // 将LocalDateTime转换为Instant + Instant instant = localDateTime.toInstant(ZoneOffset.UTC); + // 将Instant转换为Date + Date date = Date.from(instant); + roleService.update(roleVO, date); + return Result.success("修改成功"); + } + } + + @GetMapping("/query") + public Result> queryRole() { + List roleList = roleService.findAll(); + log.info("Retrieved roles: {}", roleList); + return Result.success(roleList); + } + + @PostMapping("/queryByRoleCode") + public Result queryByRoleCode(@Valid String roleCode) { + Role role = roleService.findByRoleCode(roleCode); + if (role==null){ + return Result.error(401, "角色不存在"); + } + return Result.success(role); + } +} diff --git a/demo/demo/src/main/java/demo/Controller/UserController.java b/demo/demo/src/main/java/demo/Controller/UserController.java new file mode 100644 index 0000000..5a4f498 --- /dev/null +++ b/demo/demo/src/main/java/demo/Controller/UserController.java @@ -0,0 +1,164 @@ +package demo.Controller; + +import demo.Entity.*; +import demo.Service.RoleService; +import demo.Service.UserService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import javax.validation.constraints.Pattern; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Date; +import java.util.List; +import java.util.Set; + +@Slf4j +@RestController +@RequestMapping("/user") +@Validated +public class UserController { + + @Autowired + private UserService userService; + + @Autowired + private StringRedisTemplate redisTemplate; + + private final int MAX_FAILED_ATTEMPTS = 5; + private static final Duration LOCK_TIME = Duration.ofMinutes(1); // 锁定时间1分钟 + private String LOGIN_ATTEMPTS_KEY = "login_attempts_"; + private static final String LOCKED_KEY = "locked_"; + + //用户增删改查 + /** + * @增 + * @param userVO + * @return + */ + @PostMapping("/register") + public Result register(@RequestBody UserVO userVO) { + // 查询用户名是否被占用 + User user = userService.findByUserName(userVO.getLoginName()); + if (user==null){ + // 没有占用,进行注册 + userService.register(userVO.getLoginName(), userVO.getUserChnName(), userVO.getPassword()); + return Result.success("注册成功"); + }else { + return Result.error(401, "用户名已被占用"); + } + } + + /** + * @删 + * @param loginName + * @return + */ + @DeleteMapping("/delete") + public Result delete(@Pattern(regexp = "^\\S{5,16}$") String loginName){ + // 查询用户名是否被占用 + User user = userService.findByUserName(loginName); + if (user!=null){ + // 存在,进行删除 + userService.deleteByUserName(loginName); + return Result.success("删除成功"); + }else { + return Result.error(401, "用户名不存在"); + } + } + + /** + * @改 + * @param userVo + * @return + */ + @PutMapping("/update") + public Result update(@Valid UserVO userVo){ + // 查询用户名是否被占用 + User user = userService.findByUserName(userVo.getLoginName()); + if (user!=null){ + // 存在,进行更新 + // 创建一个LocalDateTime对象 + LocalDateTime localDateTime = LocalDateTime.now(); + // 将LocalDateTime转换为Instant + Instant instant = localDateTime.toInstant(ZoneOffset.UTC); + // 将Instant转换为Date + Date date = Date.from(instant); + userService.updateByUserName(userVo.getLoginName(), userVo.getUserChnName(), date, userVo.getPassword()); + return Result.success("更新成功"); + }else { + return Result.error(401, "用户名不存在"); + } + } + + /** + * @查 + * @param loginName + * @param password + * @return + */ + @PostMapping("/login") + public Result login(@Pattern(regexp = "^\\S{5,16}$") String loginName, @Pattern(regexp = "^\\S{5,16}$") String password){ + // 检查用户是否已被锁定 + String lockedKey = LOCKED_KEY + loginName; + if (redisTemplate.hasKey(lockedKey)) { + return Result.error(403, "账户已被锁定,请稍后再试。"); + } + + // 获取当前用户登录尝试次数 + String attemptsKey = LOGIN_ATTEMPTS_KEY + loginName; + String attempts = redisTemplate.opsForValue().get(attemptsKey); + + int currentAttempts = attempts != null ? Integer.parseInt(attempts) : 0; + + // 根据用户名查询用户 + User loginUser = userService.findByUserName(loginName); + // 判断用户是否存在 + if(loginUser == null){ + return Result.error(401,"用户名不存在"); + } + + // 判断密码是否正确 + if (!loginUser.getPassword().equals(password)) { + // 增加登录失败次数 + redisTemplate.opsForValue().increment(attemptsKey, 1); + + // 如果登录失败次数达到上限,则设置锁定状态 + if (currentAttempts + 1 >= MAX_FAILED_ATTEMPTS) { + // 设置锁定状态 + redisTemplate.opsForValue().set(lockedKey, "true"); + // 设置过期时间 + redisTemplate.expire(lockedKey, LOCK_TIME); + // 删除登录失败次数 + redisTemplate.delete(attemptsKey); + } + + return Result.error(401, "密码错误,已尝试 " + (currentAttempts + 1) + " 次,还剩余 " + (MAX_FAILED_ATTEMPTS - 1 - currentAttempts) + " 次。"); + } else { + // 清除登录失败次数 + redisTemplate.delete(attemptsKey); + return Result.success("登录成功"); + } + } + + @GetMapping("/query") + public Result> query(){ + return Result.success(userService.query()); + } + + @PostMapping("/queryByUserName") + public Result queryByUserName(@Valid String loginName){ + User user = userService.queryByUserName(loginName); + if(user==null){ + return Result.error(401, "用户不存在"); + } + return Result.success(userService.queryByUserName(loginName)); + } +} diff --git a/demo/demo/src/main/java/demo/DemoApplication.java b/demo/demo/src/main/java/demo/DemoApplication.java new file mode 100644 index 0000000..e488b53 --- /dev/null +++ b/demo/demo/src/main/java/demo/DemoApplication.java @@ -0,0 +1,13 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +//@MapperScan("demo.Mapper") // 指定扫描的包路径 +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/demo/demo/src/main/java/demo/Entity/LoginRequest.java b/demo/demo/src/main/java/demo/Entity/LoginRequest.java new file mode 100644 index 0000000..848defd --- /dev/null +++ b/demo/demo/src/main/java/demo/Entity/LoginRequest.java @@ -0,0 +1,9 @@ +package demo.Entity; + +import lombok.Data; + +@Data +public class LoginRequest { + private String loginName; + private String password; +} \ No newline at end of file diff --git a/demo/demo/src/main/java/demo/Entity/Result.java b/demo/demo/src/main/java/demo/Entity/Result.java new file mode 100644 index 0000000..39fe2a3 --- /dev/null +++ b/demo/demo/src/main/java/demo/Entity/Result.java @@ -0,0 +1,64 @@ +package demo.Entity; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Result implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 结果状态码 + */ + private Integer code; + + /** + * 结果消息 + */ + private String message; + + /** + * 返回的数据 + */ + private T data; + + /** + * 成功的静态工厂方法 + * + * @param data 数据 + * @param 泛型类型 + * @return Result对象 + */ + public static Result success(T data) { + return Result.builder() + .code(200) + .message("Success") + .data(data) + .build(); + } + + /** + * 失败的静态工厂方法 + * + * @param code 状态码 + * @param message 错误消息 + * @param 泛型类型 + * @return Result对象 + */ + public static Result error(Integer code, String message) { + return Result.builder() + .code(code) + .message(message) + .build(); + } +} \ No newline at end of file diff --git a/demo/demo/src/main/java/demo/Entity/Role.java b/demo/demo/src/main/java/demo/Entity/Role.java new file mode 100644 index 0000000..8296304 --- /dev/null +++ b/demo/demo/src/main/java/demo/Entity/Role.java @@ -0,0 +1,29 @@ +package demo.Entity; + +import lombok.Data; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Data +@Table(name = "role") +public class Role { + @Id + @Column(length = 32, nullable = false) + private int id; + + @Column(length = 50) + private String roleName; + + @Column(length = 50) + private String roleCode; + + @Temporal(TemporalType.TIMESTAMP) + @Column() + private Date createTime; + + @Temporal(TemporalType.TIMESTAMP) + @Column() + private Date updateTime; +} diff --git a/demo/demo/src/main/java/demo/Entity/RoleVO.java b/demo/demo/src/main/java/demo/Entity/RoleVO.java new file mode 100644 index 0000000..cc5fcaa --- /dev/null +++ b/demo/demo/src/main/java/demo/Entity/RoleVO.java @@ -0,0 +1,9 @@ +package demo.Entity; + +import lombok.Data; + +@Data +public class RoleVO { + private String roleName; + private String roleCode; +} diff --git a/demo/demo/src/main/java/demo/Entity/User.java b/demo/demo/src/main/java/demo/Entity/User.java new file mode 100644 index 0000000..4546986 --- /dev/null +++ b/demo/demo/src/main/java/demo/Entity/User.java @@ -0,0 +1,32 @@ +package demo.Entity; + +import lombok.Data; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Data +@Table(name = "user") +public class User { + @Id + @Column(length = 32, nullable = false) + private int id; + + @Column(length = 50) + private String loginName; + + @Column(length = 50) + private String userChnName; + + @Temporal(TemporalType.TIMESTAMP) + @Column() + private Date createTime; + + @Temporal(TemporalType.TIMESTAMP) + @Column() + private Date updateTime; + + @Column(length = 16) + private String password; +} \ No newline at end of file diff --git a/demo/demo/src/main/java/demo/Entity/UserVO.java b/demo/demo/src/main/java/demo/Entity/UserVO.java new file mode 100644 index 0000000..b59afbb --- /dev/null +++ b/demo/demo/src/main/java/demo/Entity/UserVO.java @@ -0,0 +1,13 @@ +package demo.Entity; + +import lombok.Data; + +@Data +public class UserVO { + + private String loginName; + + private String userChnName; + + private String password; +} diff --git a/demo/demo/src/main/java/demo/Mapper/RoleMapper.java b/demo/demo/src/main/java/demo/Mapper/RoleMapper.java new file mode 100644 index 0000000..79cced6 --- /dev/null +++ b/demo/demo/src/main/java/demo/Mapper/RoleMapper.java @@ -0,0 +1,31 @@ +package demo.Mapper; + +import demo.Entity.Role; +import demo.Entity.RoleVO; +import demo.Entity.User; +import org.apache.ibatis.annotations.*; + +import java.util.Date; +import java.util.List; + +@Mapper +public interface RoleMapper { + + @Insert("insert into role(ROLE_NAME, ROLE_CODE, CREATE_TIME, UPDATE_TIME) values(#{roleName}, #{roleCode}, #{date}, #{date})") + void insert(@Param("roleName") String roleName, @Param("roleCode") String roleCode, @Param("date") Date date); + + @Select("select * from role where ROLE_NAME = #{roleName}") + Role findByRoleName(@Param("roleName") String roleName); + + @Delete("delete from role where ROLE_NAME = #{roleName}") + void deleteByRoleName(@Param("roleName") String roleName); + + @Update("update role set ROLE_NAME = #{roleName}, ROLE_CODE = #{roleCode}, UPDATE_TIME = #{date} where ROLE_NAME = #{roleName}") + void update(@Param("roleName") String roleName, @Param("roleCode") String roleCode, @Param("date") Date date); + + @Select("select * from role") + List findAll(); + + @Select("select * from role where ROLE_CODE = #{roleCode}") + Role findByRoleCode(@Param("roleCode") String roleCode); +} diff --git a/demo/demo/src/main/java/demo/Mapper/UserMapper.java b/demo/demo/src/main/java/demo/Mapper/UserMapper.java new file mode 100644 index 0000000..4601653 --- /dev/null +++ b/demo/demo/src/main/java/demo/Mapper/UserMapper.java @@ -0,0 +1,32 @@ +package demo.Mapper; + +import demo.Entity.User; +import org.apache.ibatis.annotations.*; + +import java.util.Date; +import java.util.List; + +@Mapper +public interface UserMapper { + + @Select("SELECT * FROM user WHERE LOGIN_NAME = #{loginName} and PASSWORD = #{password}") + User findByMessage(String loginName, String password); + + @Insert("INSERT INTO user (ID, LOGIN_NAME, USER_CHN_NAME, CREATE_TIME, UPDATE_TIME, PASSWORD) VALUES (NULL, #{loginName}, #{userChnName}, #{date}, #{date}, #{password})") + void register(@Param("loginName") String loginName, @Param("userChnName") String userChnName, @Param("date") Date date, @Param("password") String password); + + @Select("SELECT * FROM user WHERE LOGIN_NAME = #{loginName}") + User findByUsername(String loginName); + + @Delete("DELETE FROM user WHERE LOGIN_NAME = #{loginName}") + void deleteByUserName(String loginName); + + @Update("UPDATE user SET USER_CHN_NAME = #{userChnName}, UPDATE_TIME = #{updateTime}, PASSWORD = #{password} WHERE LOGIN_NAME = #{loginName}") + void updateByUserName(@Param("loginName") String loginName, @Param("userChnName") String userChnName, @Param("updateTime") Date updateTime, @Param("password") String password); + + @Select("SELECT * FROM user") + List findAll(); + + @Select("SELECT * FROM user WHERE LOGIN_NAME = #{loginName}") + User queryByUserName(@Param("loginName")String loginName); +} \ No newline at end of file diff --git a/demo/demo/src/main/java/demo/Service/RoleService.java b/demo/demo/src/main/java/demo/Service/RoleService.java new file mode 100644 index 0000000..37e69d6 --- /dev/null +++ b/demo/demo/src/main/java/demo/Service/RoleService.java @@ -0,0 +1,45 @@ +package demo.Service; + +import demo.Entity.Role; +import demo.Entity.RoleVO; +import demo.Entity.User; +import demo.Mapper.RoleMapper; +import demo.Mapper.UserMapper; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +@Slf4j +@Service +public class RoleService { + @Autowired + private RoleMapper roleMapper; + + public void insert(String roleName, String roleCode, Date date){ + roleMapper.insert(roleName, roleCode, date); + } + + public Role findByRoleName(String roleName){ + return roleMapper.findByRoleName(roleName); + } + + public void deleteByRoleName(String roleName){ + roleMapper.deleteByRoleName(roleName); + } + + public void update(RoleVO roleVO, Date date){ + roleMapper.update(roleVO.getRoleName(), roleVO.getRoleCode(), date); + } + + public List findAll(){ + return roleMapper.findAll(); + } + + public Role findByRoleCode(String roleCode){ + return roleMapper.findByRoleCode(roleCode); + } +} diff --git a/demo/demo/src/main/java/demo/Service/UserService.java b/demo/demo/src/main/java/demo/Service/UserService.java new file mode 100644 index 0000000..addea9b --- /dev/null +++ b/demo/demo/src/main/java/demo/Service/UserService.java @@ -0,0 +1,56 @@ +package demo.Service; + +import demo.Entity.Role; +import demo.Entity.User; +import demo.Mapper.UserMapper; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Date; +import java.util.List; + +@Slf4j +@Service +public class UserService { + @Autowired + private UserMapper userMapper; + + public User findByMessage(String loginName, String password){ + return userMapper.findByMessage(loginName, password); + } + + public void register(String loginName, String UserChnName, String password){ + // 创建一个LocalDateTime对象 + LocalDateTime localDateTime = LocalDateTime.now(); + // 将LocalDateTime转换为Instant + Instant instant = localDateTime.toInstant(ZoneOffset.UTC); + // 将Instant转换为Date + Date date = Date.from(instant); + userMapper.register(loginName, UserChnName, date, password); + } + + public User findByUserName(String loginName){ + return userMapper.findByUsername(loginName); + } + + public void deleteByUserName(String loginName){ + userMapper.deleteByUserName(loginName); + } + + public void updateByUserName(String loginName, String userChnName, Date updateTime, String password){ + userMapper.updateByUserName(loginName, userChnName, updateTime, password); + } + + public List query(){ + return userMapper.findAll(); + } + + public User queryByUserName(String loginName){ + return userMapper.queryByUserName(loginName); + } +} diff --git a/demo/demo/src/main/resources/application.yml b/demo/demo/src/main/resources/application.yml new file mode 100644 index 0000000..9ea702a --- /dev/null +++ b/demo/demo/src/main/resources/application.yml @@ -0,0 +1,21 @@ +server: + port: 8080 +spring: + datasource: + username: root + password: 123456 + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/test_repo + redis: + host: localhost + port: 6379 + password: 123456 # 如果没有密码,可以省略 + database: 0 # 默认数据库索引 + timeout: 5000ms # 连接超时时间 + +mybatis: + configuration: + #开启驼峰命名转换 + map-underscore-to-camel-case: true + mapper-locations: classpath:mapper/*.xml + type-aliases-package: com.example.demo.entity \ No newline at end of file diff --git a/demo/demo/src/main/resources/static/index.html b/demo/demo/src/main/resources/static/index.html new file mode 100644 index 0000000..e2d94a2 --- /dev/null +++ b/demo/demo/src/main/resources/static/index.html @@ -0,0 +1,6 @@ + + +

hello word!!!

+

this is a html page

+ + \ No newline at end of file diff --git a/demo/demo/src/test/java/demo/DemoApplicationTests.java b/demo/demo/src/test/java/demo/DemoApplicationTests.java new file mode 100644 index 0000000..aa65aae --- /dev/null +++ b/demo/demo/src/test/java/demo/DemoApplicationTests.java @@ -0,0 +1,23 @@ +package demo; + +import demo.Mapper.UserMapper; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.sql.DataSource; + +@SpringBootTest +class DemoApplicationTests { + @Autowired + private DataSource dataSource; + @Autowired + private UserMapper userMapper; + + @Test + void contextLoads() throws Exception { + + System.out.println(dataSource.getConnection()); + + } +}