@mapper
MyBatis에서 인터페이스를 기반으로 SQL 매핑을 제공하는 어노테이션
XML 파일 없이 SQL 쿼리를 실행할 수 있다.
@Mapper
public interface UserMapper {
@Select("SELECT * FROM users WHERE id = #{id}")
User findById(Long id);
@Insert("INSERT INTO users(name, age) VALUES(#{name}, #{age})")
void save(User user);
@Update("UPDATE users SET name = #{name}, age = #{age} WHERE id = #{id}")
void update(User user);
@Delete("DELETE FROM users WHERE id = #{id}")
void deleteById(Long id);
}
필요에 따라서 XML 파일을 사용할 수도 있는데, 메소드를 id로 인식하여 찾아가 실행한다.
@Mapper
public interface UserMapper {
User findById(Long id);
}
<!-- UserMapper.xml -->
<mapper namespace="com.example.mapper.UserMapper">
<select id="findById" resultType="com.example.model.User">
SELECT * FROM users WHERE id = #{id}
</select>
</mapper>
https://standout.tistory.com/91
SQL이란?
SQL Structured Query Language 데이터 베이스를 이용하기 위한 특수 목적의 프로그래밍 언어 https://ko.wikipedia.org/wiki/SQL SQL - 위키백과, 우리 모두의 백과사전 위키백과, 우리 모두의 백과사전. 이 도표는
standout.tistory.com
https://standout.tistory.com/370
mybatis 3.1.0 이란?
SQL을 자바코드에서 분리해 XML등의 형태로 처리해 작성하도록 도움 pom.xml에 추가 org.mybatis mybatis 3.1.0 https://mvnrepository.com/artifact/org.mybatis/mybatis/3.1.0
standout.tistory.com
'JAVA > Spring' 카테고리의 다른 글
Annotation - @EqualsAndHashCode (0) | 2023.04.20 |
---|---|
Annotation - @Getter @Setter @ToString (0) | 2023.04.20 |
Annotation - @SpringBootConfiguration (0) | 2023.04.20 |
Annotation - @EnableAutoConfiguration (0) | 2023.04.20 |
Annotation - @SpringBootApplication (0) | 2023.04.20 |