server:
port: 8080
spring:
datasource:
url: jdbc:oracle:thin:@localhost:1521:orcl
driver-class-name: oracle.jdbc.driver.OracleDriver
username: scott
password: bruce123
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath*:com/example/mybatis01/mapper/xml/*.xml
type-aliases-package: com.example.mybatis01.entity
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
package com.example.mybatis01.mapper;
import com.example.mybatis01.entity.Dept;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
//@Mapper
public interface DeptMapper {
public List<Dept> queryAllDepts();
@Select("select deptno,dname,loc from dept where deptno=#{deptno}")
Dept findOneDept(@Param("deptno") String deptno);
@Insert("insert into dept (deptno,dname,loc) values (#{deptno},#{dname},#{loc})")
void insertDept(String deptno,String dname,String loc);
}
<?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">
<mapper namespace="com.example.mybatis01.mapper.DeptMapper">
<resultMap id="dept" type="com.example.mybatis01.entity.Dept">
<result column="deptno" property="deptno"></result>
<result column="dname" property="dname"></result>
<result column="loc" property="loc"></result>
</resultMap>
<select id="queryAllDepts" resultMap="dept">
select deptno,dname,loc from dept
</select>
</mapper>