Open hyeonpark-5 opened 4 months ago
mysql 설정
#mysql setting spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:포트번호/스키마이름?serverTimeZone=Asia/Seoul spring.datasource.username=유저이름 spring.datasource.password=유저비번
mybatis 설정
mybatis.mapper-locations=classpath:/mapper/*.xml
------------------- ### 동작 확인 - postman ![postman_check](https://github.com/PJ-TEAM-Vitamin/Hospital_reservation_web_application/assets/67797025/1826e025-1f55-4441-aded-0f2a7820a4e0) - mysql (mysql workbench로 확인) ![mysql_check](https://github.com/PJ-TEAM-Vitamin/Hospital_reservation_web_application/assets/67797025/a26f8f8b-a997-44d1-b613-cae3ad069b38) ---------------------- - controller
@RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService;
@PostMapping("/signup") public void signUp(@RequestBody UserDto userDto){ userService.insertUser(userDto); }
}
- dto
@Data public class UserDto { private BigInteger user_id; private String password; private String nickname; private String email; }
- mapper
@Mapper public interface UserMapper { public void insertUser(UserDto userDto); }
- service
public interface UserService { public void insertUser(UserDto userDto); }
-serviceImpl
@Service public class UserServiceImpl implements UserService{ @Autowired private UserMapper userMapper;
@Override public void insertUser(UserDto userDto){ userMapper.insertUser(userDto); }
-mapper(xml)
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
mysql 연결 및 동작 test
파일구조
mysql 설정
mybatis 설정
@RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService;
}
@Data public class UserDto { private BigInteger user_id; private String password; private String nickname; private String email; }
@Mapper public interface UserMapper { public void insertUser(UserDto userDto); }
public interface UserService { public void insertUser(UserDto userDto); }
@Service public class UserServiceImpl implements UserService{ @Autowired private UserMapper userMapper;
}
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">