Til210707

less than 1 minute read

TIL

전자정부프레임워크 mapper 설정

  • 전자정부프레임워크의 mapper 설정은 context-sqlMap.xml과 context-mapper.xml에서 이루어진다.
  • ibatis의 경우 context-sqlMap.xml을 사용하고 mybatis의 경우에는 context-mapper.xml을 사용한다.
	<!-- SqlSession setup for MyBatis Database Layer -->
	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:/egovframework/sqlmap/config/sql-mapper-config.xml" />
		<property name="mapperLocations" value="classpath:/egovframework/sqlmap/mappers/mapper_*.xml" />
	</bean>
  • mapper 파일의 장소는 mapperLocations에서 정하며 이름 역시 지정할 수 있다.
  • 위 코드를 봤을 때 mapper 파일이 존재하는 곳은 egovframework의 sqlmap의 mappers 파일 안이다.
  • 또한 mapper 파일의 이름을 지을 때 mapper_ 로 시작해야 인식이 된다.

No bean name

  • @Service를 지정하지 않았을 경우 발생하는 에러

mysql 검색

		select *
		from TB_COMM_USER
		<where>
		1 = 1
		and USER_GB = 'M'
			<if test="userId != null and !userId.equals('') ">
				and
				USER_ID like concat('%', #{userId}, '%')
			</if>
      <if test="hpNum != null and !hpNum.equals('') ">
			and
			HP_NUM like concat('%', #{hpNum}, '%')
			</if>
      <if test="apprYn != null and !apprYn.equals('') ">
			and
			APPR_YN like concat('%',
			#{apprYn}, '%')
			</if>
			<if test="startDate != null and !startDate.equals('')">
			and
      REG_DTM >= date(#{startDate})
			</if> 
			<if test ="endDate != null and !endDate.equals('') ">
			and
			<![CDATA[REG_DTM <= date(#{endDate})+1 ]]>
			</if>
		</where>
		group by
		USER_SEQ;

Updated: