빅데이터 Java 개발자 교육 - 28일차 [미니프로젝트 - 3일차]

Jun_Gyu·2023년 3월 12일
0
post-thumbnail

📈 현재 진행상황

  • shelterMapper의 기능들이 JFrame UI를 통해 데이터값을 주고받는 기능이 정상적으로 작동됨을 확인하였다.

  • 보호 동물의 정보를 추가, 수정, 조회할 수 있는 기능들을 Mapper에 구성했다.

  • 원활한 소통과 더불어 효율적인 자료의 첨부를 위해서 Notion에 "수정항목 요청 게시판"을 만들어 수정하고자 하는 부분에 대해서 요청, 회의가 가능하도록 하였다.

📃 Mapper 항목 구성

오늘은 이전에 작성해둔 AnimalMapper 쿼리문들과 더불어 AdpbrdMapper의 쿼리문까지 작성을 완료한 후 Test까지 완료한 상태이다.

기본적인 기능인 '전체조회', '추가', '삭제'를 적용한 뒤, 부분적으로 UI를 체크하여 '한개 조회'의 기능을 각각의 Mapper에 추가시켰다. 이로써 우리가 이번 프로젝트에 구현하고자 하는 부분의 쿼리문은 모두 작성을 끝마친 상태이다.



📃 AnimalMapper의 구성 코드

package mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import dto.Animal;

@Mapper
public interface AnimalMapper {

	@Insert( value = {
	"  INSERT INTO animal (  ",
		  "  animal_no, animal_species, animal_gender,  ",
		  "  animal_age, animal_weight, animal_neutering,  ",
		  "  animal_rescue_spot, animal_content,  ",
		  "  animal_limit, SHELTER_ID, animal_rescuedate)  ",
	  "  VALUES ( ",
		  "  seq_animal_no.NEXTVAL,  ",
		  "  #{animalSpecies}, #{animalGender}, ",
		  "  #{animalAge}, #{animalWeight}, ",
		  "  #{animalNeutering}, #{animalRescueSpot},  ",
		  "  #{animalContent},  ",
		  "  #{animalLimit}, #{shelterId}, #{animalRescuedate} ) "
	} )
	public int insertOneAnimal(Animal animal); // 보호동물 정보 추가(O)

/*-----------------------------------------------------------------------------------*/
	@Results({
		   @Result( column = "ANIMAL_CONTENT", property = "animalContent",
		   javaType = String.class, jdbcType = JdbcType.CLOB)
		})
	@Update( value = {
	" <script> ",
		" UPDATE animal ",
			"SET animal_content = #{obj.animalContent} ",
		
		 	" <if test = 'obj.animalSpecies != null'> ",
		 		" , animal_species = #{obj.animalSpecies}  ",
			" </if> ",
			
			" <if test = 'obj.animalGender != null'> ",
				" , animal_gender = #{obj.animalGender} ",
			" </if> ",
			
			" <if test = 'obj.animalAge != null'> ",
				" , animal_age = #{obj.animalAge} ",
			" </if> ",
			
			" <if test = 'obj.animalWeight != null'> ",
				" , animal_weight = #{obj.animalWeight} ",
			" </if> ",
			
			" <if test = 'obj.animalNeutering != null'> ",
				" , animal_neutering = #{obj.animalNeutering} ",
			" </if> ",
			
			" <if test = 'obj.animalState != null'> ",
				" , animal_state = #{obj.animalState} ",
			" </if> ",
			
		" WHERE animal_no = #{obj.animalNo} AND shelter_id = #{obj.shelterId}",
	" </script> "
	} )
	public int updateOneAnimal(@Param("obj") Animal animal); // 보호동물 정보 업데이트
	
/*-----------------------------------------------------------------------------------*/

//	@Select( value = { 
//			"  SELECT *  ",
//			"  FROM  ",
//			   "  adp_all_view  ",
//			"  WHERE  ",
//			   "  shelter_id = #{id}  " 
//	} )
//	public List<Map<String, Object>> selectAllAnimal(String id); // 보호동물 전체 조회
//	// selectAllAnimal에서 ShelterId 추가하기 위해서 Service에 insert type으로 바꿔줘야함.
	
/*-----------------------------------------------------------------------------------*/

	@Select( value = { 
	        "  SELECT *  ",
	        "  FROM  ",
	           "  animal  ",
	        "  WHERE  ",
	           "  animal_no = #{no}  ",
 		    " ORDER BY animal_no DESC " 
	        } )
		public Animal selectOneAnimal(Long no); // 동물 한마리만 조회
	
	
	
	@Select( value = {
		"  SELECT *  ",
	    "  FROM  ",
		   "  animal  ",
	    "  WHERE  ",
	       "  shelter_id = #{shelterId}  ",
	    "  AND  ",
	       "  animal_No ||  ",
		   "  animal_Species ||  ",
		   "  animal_Gender ||  ",
		   "  animal_Rescue_Spot  ",
	    "  LIKE  ",
		   "  '%' || #{keyword} || '%'  ",
	    " ORDER BY animal_no DESC "                
		} )
	public List<Animal> searchAnimal(@Param("keyword") String keyword, @Param("shelterId") String shelterId); // 보호동물 검색(O)
	// String type 2개 추가해야함. 하나는 검색용, 하나는 shelterId 추가용으로. 
	
/*-----------------------------------------------------------------------------------*/
	
	@Select( value = {
		"  SELECT animal_no, ",
			"  ANIMAL_SPECIES, ANIMAL_GENDER,  ",
			"  ANIMAL_AGE, ANIMAL_WEIGHT,  ",
			"  ANIMAL_NEUTERING, ANIMAL_RESCUE_SPOT,  ",
			"  ANIMAL_RESCUEDATE, ANIMAL_CONTENT,  ",
			"  ANIMAL_LIMIT  ",
		"  FROM  ",
			"  ANIMAL  ",
		"  WHERE  ",
		   	"  shelter_id =#{shelterId} ",
		"  AND  ",
		   	"  animal_state =#{stateNo} ",
		"  ORDER BY  ",
			"  animal_no DESC "
	})
	public List<Animal> selectByState(@Param("stateNo") int stateNo, @Param("shelterId") String shelterId);	// 동물 조회 시 상태 별로 조회하기 기능

	


}



📃 AdpbrdMapper의 구성 코드

package mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import dto.Adpbrd;


@Mapper
public interface AdpbrdMapper {

	@Update ( value =  {
			" <script> ",
				"  UPDATE adpbrd SET brd_title = #{obj.brdTitle} ",
					
					"  <if test = 'obj.brdContent != null'>  ",
					" , brd_content =#{obj.brdContent}  ",
					"  </if>  ",
						
				"  WHERE brd_no =#{obj.brdNo}  ",
			" </script> "
			} )
			public int updateOneAdpbrd(@Param("obj") Adpbrd adpbrd);
	
	
/*--------------------------------------------------------------------*/

	@Update( value = {
			"  DELETE FROM waitadp  ",
			"  WHERE  ",
				"  brd_no = #{brdNo}  "
	} )
	public int deleteOneAdpbrd(Long brdNo); // 게시글 삭제 
	
/*--------------------------------------------------------------------*/
	
	@Select({" SELECT SEQ_ADPBRD_NO.NEXTVAL FROM DUAL "})
	public Long selectAdpbrdSeq();
	
/*--------------------------------------------------------------------*/
	
	@Select({
		" select * from adp_all_view where animal_no = #{no} "
	})
	public Map<String, Object> insertCheck(@Param("no") Long animal_no);
	
	
/*--------------------------------------------------------------------*/
	@Insert( value = { 
			"  INSERT INTO adpbrd(  ",
				"  brd_no, brd_title, brd_content )",
			"  VALUES (  ",
				"  #{obj.brdNo}, #{obj.brdTitle}, #{obj.brdContent})  "
	})
	public int insertOneAdpbrd(@Param("obj") Adpbrd adpbrd);

/*--------------------------------------------------------------------*/
	
	@Insert( value = {
			"  INSERT INTO waitadp (  ",
				"  animal_no, brd_no ) ",
			"  VALUES (  ",
				"  #{animalNo}, #{obj.brdNo}  )  "
			
	} )
	public int insertWaitadp(@Param("animalNo") Long animalNo, @Param("obj") Adpbrd adpbrd);
	


/*--------------------------------------------------------------------*/

	@Results({
		@Result( column = "BRD_CONTENT", property = "BRD_CONTENT",
				javaType = String.class, jdbcType = JdbcType.CLOB)
	})
	@Select(value = { " select brd_no, brd_title, brd_content, ",
					  " animal_no, animal_species, animal_gender, ",
					  " animal_rescue_spot, animal_limit, ",
					  " brd_hit, brd_sympathy, brd_regdate ",
			 		  " from adp_all_view ",
			 		  " where shelter_id = #{shelterId} ",
			 		  " order by brd_no desc "           
			 		  })
	 public List<Map<String, Object>> selectAllAdpbrd(String shelterId);

/*--------------------------------------------------------------------*/

	@Results({
		@Result( column = "ANIMAL_CONTENT", property = "ANIMAL_CONTENT",
				javaType = String.class, jdbcType = JdbcType.CLOB),
		@Result( column = "BRD_CONTENT", property = "BRD_CONTENT",
				javaType = String.class, jdbcType = JdbcType.CLOB)
		})
	@Select( value = {
	         "  SELECT *  ",
	         "  FROM  ",
	              "  adp_all_view a ",
	         "  WHERE  ", 
	              "  brd_no = #{brdNo}  ",
	 		  " order by brd_no desc "          
			} )
	  public Map<String, Object> selectOneAdpbrd(Long brdNo);
	
/*--------------------------------------------------------------------*/

}

기본적인 기능과 더불어 UI에서 사용 편의성을 높이고자
동물의 입양소개글 등록 여부를 확인해주는 "insertCheck", 동물 한마리당 소개 게시글 하나를 등록해주는 "insertWaitadp",
그리고 등록된 게시글의 삭제를 위해 게시글 시퀀스값을 조회하는 "selectAdpbrdSeq"까지 추가적으로 메소드를 구성해주었다.


profile
시작은 미약하지만, 그 끝은 창대하리라

0개의 댓글