[MyBatis] Console program(MVC) Exercise ๐Ÿ”ฅ

Joy๐ŸŒฑยท2023๋…„ 2์›” 2์ผ
0

๐Ÿค– Exercise

๋ชฉ๋ก ๋ณด๊ธฐ
3/6
post-thumbnail

๐Ÿงฉ MVC๊ตฌ์กฐ๋กœ ์ฝ˜์†” ํ”„๋กœ๊ทธ๋žจ ์ œ์ž‘ํ•˜๊ธฐ

๐Ÿ’โ€ ๋ธŒ๋Ÿฐ์น˜ ์นดํŽ˜๋ฅผ ์šด์˜์ค‘์ธ ๋‹น์‹ , ๋งค์ผ ์ƒˆ๋กœ์šด ์žฌ๋ฃŒ๋ฅผ ์—ฌ๋Ÿฌ ์—…์ฒด์—์„œ ๊ณต๊ธ‰๋ฐ›์•„ ์Œ์‹์„ ์กฐ๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ ์—…์ฒด์—์„œ ์žฌ๋ฃŒ๋ฅผ ์ฃผ๋ฌธํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด ๋”์šฑ ์†์‰ฝ๊ฒŒ ์žฌ๋ฃŒ๋ฅผ ์˜ค๋”ํ•ด์š”! :)


๐Ÿ“Œ ์ดˆ๊ธฐ Setting

โ—ผ connection-info.properties

driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:xe
username=C##FOOD_PRODUCTS
password=FOOD_PRODUCTS

โ—ผ mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

  <!--connection-info.properties๋ฅผ ์ฝ์–ด์˜ฌ ๊ฒƒ 
(์•„๋ž˜ value์— ์ง์ ‘ ์ž…๋ ฅํ•˜์ง€์•Š๊ณ  ${}๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž‘์„ฑ(๋ณด์•ˆ์„ ์œ„ํ•ด ๋ถ„๋ฆฌํ•˜์—ฌ ์‚ฌ์šฉ))-->
  <properties resource="connection-info.properties"/>
  
  <!-- ๋ณ„์นญ ์„ค์ • -->
  <typeAliases>
    <typeAlias type="com.joyhyonie.common.SearchCriteria" alias="SerchCriteria"/> 
    <!-- type="ํด๋ž˜์Šค๊ฒฝ๋กœ" alias="๋ณ„์นญ"-->
  </typeAliases>

  <environments default="dev">
    <environment id="dev">
      <transactionManager type="JDBC"/>
      <dataSource type="POOLED">
        <property name="driver" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
      </dataSource>
    </environment>
  </environments>
  
  <mappers>
  	<!-- package์˜ ๋ช…์นญ์„ ์ž‘์„ฑํ•˜์—ฌ ํ•ด๋‹น ํŒจํ‚ค์ง€ ํ•˜์œ„์— ์žˆ๋Š” ๋ชจ๋“  ํŒŒ์ผ์„ mapper๋กœ ์‚ฌ์šฉ -->
	  <package name="com.joyhyonie.foodProducts.mapper"/> 
	  
  </mappers>
</configuration>

โ—ผ SearchCriteria Class

public class SearchCriteria { // ๊ฒ€์ƒ‰ ๊ธฐ์ค€

	private String condition; 	// ๊ฒ€์ƒ‰ ์กฐ๊ฑด
	private String value; 		// ๊ฒ€์ƒ‰ํ•˜๋ ค๋Š” ๋‹จ์–ด
	
	public SearchCriteria() {}
	
	public SearchCriteria(String value) {
		super();
		this.value = value;
	}

	public SearchCriteria(String condition, String value) {
		super();
		this.condition = condition;
		this.value = value;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return "SearchCriteria [condition=" + condition + ", value=" + value + "]";
	}
}

โ—ผ Template Class

public class Template {

	private static SqlSessionFactory sqlSessionFactory; 
	
	public static SqlSession getSqlSession() {
		
		if(sqlSessionFactory == null) { 
			String resource = "mybatis-config.xml";
			
			try {
				InputStream inputStream = Resources.getResourceAsStream(resource);
				sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
				
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		return sqlSessionFactory.openSession(false);
	}
}

๐Ÿ‘‰ DB Script

โ—ผ FoodProducts.sql

-- ํ…Œ์ด๋ธ” ์ƒ์„ฑ
--[ TBL_FOOD_CATEGORY ]
CREATE TABLE TBL_FOOD_CATEGORY(
    CATEGORY_CODE NUMBER CONSTRAINT PK_CATEGORY_CODE PRIMARY KEY
,   CATEGORY VARCHAR2(30) NOT NULL
);

COMMENT ON COLUMN TBL_FOOD_CATEGORY.CATEGORY_CODE IS '์‹ํ’ˆ ์ข…๋ฅ˜ ์ฝ”๋“œ';
COMMENT ON COLUMN TBL_FOOD_CATEGORY.CATEGORY IS '์ข…๋ฅ˜๋ช…';

--[ TBL_SUPPLIER ]
CREATE TABLE TBL_SUPPLIER(
    CATEGORY_CODE NUMBER
,   SUPPLIER_CODE VARCHAR2(10) 
,   SUPPLIER_NAME VARCHAR2(30) UNIQUE
,   ADDRESS VARCHAR2(80)
,   CONTACT_NUMBER VARCHAR2(20) NOT NULL
,   ORDER_YN VARCHAR2(10) DEFAULT 'Y' CHECK (ORDER_YN IN('Y', 'N')) 
,   CONSTRAINT FK_CATEGORY_CODE FOREIGN KEY(CATEGORY_CODE) REFERENCES TBL_FOOD_CATEGORY(CATEGORY_CODE)
,   CONSTRAINT PK_SUPPLIER_CODE PRIMARY KEY(SUPPLIER_CODE)
);

COMMENT ON COLUMN TBL_SUPPLIER.CATEGORY_CODE IS '์‹ํ’ˆ ์ข…๋ฅ˜ ์ฝ”๋“œ';
COMMENT ON COLUMN TBL_SUPPLIER.SUPPLIER_CODE IS '์—…์ฒด ์ฝ”๋“œ';
COMMENT ON COLUMN TBL_SUPPLIER.SUPPLIER_NAME IS '์—…์ฒด๋ช…';
COMMENT ON COLUMN TBL_SUPPLIER.ADDRESS IS '์ฃผ์†Œ';
COMMENT ON COLUMN TBL_SUPPLIER.CONTACT_NUMBER IS '์—ฐ๋ฝ์ฒ˜';
COMMENT ON COLUMN TBL_SUPPLIER.ORDER_YN IS '๊ฑฐ๋ž˜ ๊ฐ€๋Šฅ ์—ฌ๋ถ€';

--[ TBL_PRODUCTS ]
CREATE TABLE TBL_PRODUCTS(
    PROD_CODE NUMBER
,   PROD_NAME VARCHAR2(30) NOT NULL
,   PRICE NUMBER
,   SUPPLIER_NAME VARCHAR2(30) NOT NULL
,   CONSTRAINT PK_PROD_CODE PRIMARY KEY(PROD_CODE)
);

COMMENT ON COLUMN TBL_PRODUCTS.PROD_CODE IS '์žฌ๋ฃŒ ์ฝ”๋“œ';
COMMENT ON COLUMN TBL_PRODUCTS.PROD_NAME IS '์žฌ๋ฃŒ๋ช…';
COMMENT ON COLUMN TBL_PRODUCTS.PRICE IS '์žฌ๋ฃŒ๊ฐ€๊ฒฉ';
COMMENT ON COLUMN TBL_PRODUCTS.SUPPLIER_NAME IS '์—…์ฒด๋ช…';

--[ TBL_STORAGE ]
CREATE TABLE TBL_STORAGE(
    PROD_CODE NUMBER NOT NULL
,   PROD_NAME VARCHAR2(30) NOT NULL
,   INCOMING_DATE VARCHAR2(10) NOT NULL
);

COMMENT ON COLUMN TBL_STORAGE.PROD_CODE IS '์žฌ๋ฃŒ ์ฝ”๋“œ';
COMMENT ON COLUMN TBL_STORAGE.PROD_NAME IS '์žฌ๋ฃŒ๋ช…';
COMMENT ON COLUMN TBL_STORAGE.INCOMING_DATE IS '์ž…๊ณ ๋‚ ์งœ';

--[ TBL_ORDER_HISTORY ]
CREATE TABLE TBL_ORDER_HISTORY(
    ORDER_CODE NUMBER
,   ORDER_DATE VARCHAR2(10) NOT NULL
,   ORDER_TIME VARCHAR2(10)
,   TOTAL_PRICE NUMBER NOT NULL
,   CONSTRAINT PK_ORDER_CODE PRIMARY KEY(ORDER_CODE)
);

COMMENT ON COLUMN TBL_ORDER_HISTORY.ORDER_CODE IS '์ฃผ๋ฌธ์ฝ”๋“œ';
COMMENT ON COLUMN TBL_ORDER_HISTORY.ORDER_DATE IS '์ฃผ๋ฌธ์ผ์ž';
COMMENT ON COLUMN TBL_ORDER_HISTORY.ORDER_TIME IS '์ฃผ๋ฌธ์‹œ๊ฐ';
COMMENT ON COLUMN TBL_ORDER_HISTORY.TOTAL_PRICE IS '์ฃผ๋ฌธ์ด์•ก';
--์‹œํ€€์Šค ์ƒ์„ฑ
--[ CATEGORY_CODE ]
CREATE SEQUENCE SEQ_CATEGORY_CODE
START WITH 1
INCREMENT BY 1
MAXVALUE 10
NOCYCLE
NOCACHE;
--[ PROD_CODE ]
CREATE SEQUENCE SEQ_PROD_CODE
START WITH 100
INCREMENT BY 1
MAXVALUE 999
NOCYCLE
NOCACHE;
--[ ORDER_CODE ]
CREATE SEQUENCE SEQ_ORDER_CODE
START WITH 1000
INCREMENT BY 1
MAXVALUE 9999
NOCYCLE
NOCACHE;
--์ปฌ๋Ÿผ ๊ฐ’ ์‚ฝ์ž…
--[ TBL_FOOD_CATEGORY ]
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '์œก๋ฅ˜');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '์–ด๋ฅ˜');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๊ณผ์ผ,์ฑ„์†Œ๋ฅ˜');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '์œ ์ œํ’ˆ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๋ƒ‰๋™์‹ํ’ˆ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๊ฑด์กฐ์‹ํ’ˆ');
INSERT INTO TBL_FOOD_CATEGORY VALUES(SEQ_CATEGORY_CODE.NEXTVAL, '๊ธฐํƒ€');

--[ TBL_SUPPLIER ]
INSERT INTO TBL_SUPPLIER VALUES(1, '1A', '๊ตฝ๋„ค์ •์œก', '์„œ์šธ์‹œ ์„ฑ๋™๊ตฌ ๋งˆ์žฅ๋™ ๊ณ ๊นƒ๊ธธ 79',	'02-6549-2341', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(2, '2A', '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘', '์„œ์šธ์‹œ ๋™์ž‘๊ตฌ ๋…ธ๋Ÿ‰์ง„์ˆ˜์‚ฐ๋ฌผ๋„๋งค์‹œ์žฅ 7-A', '02-4061-0605', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(3, '3A', 'SING์‹ฑ์ฑ„์†Œ'	, '์„œ์šธ์‹œ ๋™๋Œ€๋ฌธ๊ตฌ ์ œ๊ธฐ๋™ ์ฒญ๋Ÿ‰๋ฆฌ์ฒญ๊ณผ๋ฌผ์‹œ์žฅ 185ํ˜ธ', '070-3059-4953', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(3, '3B', '๋ฒ ์ง€์ƒํšŒ', '๊ฒฝ๊ธฐ๋„ ๋‚จ์–‘์ฃผ์‹œ ์•ผ์ฑ„๋กœ2๊ธธ 71', '031-3421-5800', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(4, '4A', '์น˜์ฆˆFARM', '๊ฒฝ๊ธฐ๋„ ํŒŒ์ฃผ์‹œ ์šฐ์œ ๋ฆฌ 921-12', '031-9372-0221', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(5, '5A', '์–ผ์Œ๋•กํ‘ธ๋“œ', '์„œ์šธ์‹œ ์ข…๋กœ๊ตฌ ๊ฝ๊ฝ3๊ฐ€ 2-38', '02-5068-4480', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(6, '6A', '์งฑ๊ตฌ๋Š”๋ง๋ ค', '๊ฒฝ๊ธฐ๋„ ํ•˜๋‚จ์‹œ ํฐ๋‘ฅ๋กœ 600', '070-3242-1666', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(7, '7A', '๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„', '๊ฒฝ๊ธฐ๋„ ์ด์ฒœ์‹œ ๋ฌด์ดŒ๋ฆฌ 52-7', '031-2221-5838', DEFAULT);
INSERT INTO TBL_SUPPLIER VALUES(7, '7B', 'EGG๋จธ๋‹ˆ๋‚˜',	 '์„œ์šธ์‹œ ๋„๋ด‰๊ตฌ ๋ณ‘์•„๋ฆฌ๊ธธ 92', '02-7483-8812', DEFAULT);

--[ TBL_PRODUCTS ]
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์†Œ ๋“ฑ์‹ฌ', 20000,	'๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์†Œ ์•ˆ์‹ฌ', 23000,	'๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์†Œ ๋‹ค์ง์œก', 15000, '๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ผ์ง€ ๋“ฑ์‹ฌ', 10000, '๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ผ์ง€ ์•ˆ์‹ฌ', 15000, '๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ผ์ง€ ๋‹ค์ง์œก',	8000, '๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋‹ญ ์•ˆ์‹ฌ',	 7000, '๊ตฝ๋„ค์ •์œก');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์—ฐ์–ด', 20000, '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ƒˆ์šฐ', 11000, '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์˜ค์ง•์–ด',	5000, '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฐ€์ž๋ฏธ',	10000, '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฐ”์ง€๋ฝ',	5000, '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ชจ์‹œ์กฐ๊ฐœ', 6000, '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋‹น๊ทผ', 3000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์–‘ํŒŒ', 4000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ƒ๋Ÿฌ๋ฆฌ',	3000, 'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์–‘๋ฐฐ์ถ”',	6000, 'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋น„ํŠธ', 3000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฐ์ž', 4000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ณ ๊ตฌ๋งˆ',	4000, 'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํ˜ธ๋ฐ•', 8000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋”ธ๊ธฐ', 7000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฐ”๋‚˜๋‚˜',	4000, 'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํ‚ค์œ„', 8000,	'SING์‹ฑ์ฑ„์†Œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋กœ์ฆˆ๋งˆ๋ฆฌ', 7000, '๋ฒ ์ง€์ƒํšŒ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ชฝํŒŒ', 4000,	'๋ฒ ์ง€์ƒํšŒ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊นป์žŽ', 2000,	'๋ฒ ์ง€์ƒํšŒ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฌด์ˆœ', 4000,	'๋ฒ ์ง€์ƒํšŒ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์–‘์†ก์ด๋ฒ„์„ฏ', 5000, '๋ฒ ์ง€์ƒํšŒ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋”œ',	 7000, '๋ฒ ์ง€์ƒํšŒ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์šฐ์œ ', 4000, '์น˜์ฆˆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ƒํฌ๋ฆผ',	7000, '์น˜์ฆˆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ฒด๋‹ค์น˜์ฆˆ', 5000, '์น˜์ฆˆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํฌ๋ฆผ์น˜์ฆˆ', 7000, '์น˜์ฆˆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ฆฌ์ฝ”ํƒ€์น˜์ฆˆ', 9000, '์น˜์ฆˆFARM');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ƒ‰๋™๊ฐ์žํŠ€๊น€',	 10000,	'์–ผ์Œ๋•กํ‘ธ๋“œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ƒ‰๋™๊ณ ๊ตฌ๋งˆํŠ€๊น€', 12000, '์–ผ์Œ๋•กํ‘ธ๋“œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ƒ‰๋™๋งŒ๋‘', 7000, '์–ผ์Œ๋•กํ‘ธ๋“œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋ƒ‰๋™๋ธ”๋ฃจ๋ฒ ๋ฆฌ', 15000, '์–ผ์Œ๋•กํ‘ธ๋“œ');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํ˜ธ๋ฐ•์”จ',	5000, '์งฑ๊ตฌ๋Š”๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํ•ด๋ฐ”๋ผ๊ธฐ์”จ', 4000, '์งฑ๊ตฌ๋Š”๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฑดํฌ๋„',	4000, '์งฑ๊ตฌ๋Š”๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ฑดํฌ๋žœ๋ฒ ๋ฆฌ', 6000, '์งฑ๊ตฌ๋Š”๋ง๋ ค');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๊ณฐํ‘œ๋ฐ€๊ฐ€๋ฃจ', 6000, '๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์Œ€๊ฐ€๋ฃจ',	8000, '๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '๋นต๊ฐ€๋ฃจ',	4000, '๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ฝฉ๊ฐ€๋ฃจ',	3000, '๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์œ ๊ธฐ๋† ๋‹ฌ๊ฑ€',	10000, 'EGG๋จธ๋‹ˆ๋‚˜');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํ•˜์–€ ๋‹ฌ๊ฑ€', 8000,	'EGG๋จธ๋‹ˆ๋‚˜');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, 'ํŠน๋Œ€ ๋‹ฌ๊ฑ€', 7000,	'EGG๋จธ๋‹ˆ๋‚˜');
INSERT INTO TBL_PRODUCTS VALUES(SEQ_PROD_CODE.NEXTVAL, '์ผ๋ฐ˜ ๋‹ฌ๊ฑ€', 5000,	'EGG๋จธ๋‹ˆ๋‚˜');

--[ TBL_STORAGE ]
INSERT INTO TBL_STORAGE VALUES(101, '์†Œ ์•ˆ์‹ฌ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(105, '๋ผ์ง€ ๋‹ค์ง์œก', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(108, '์ƒˆ์šฐ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(112, '๋ชจ์‹œ์กฐ๊ฐœ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(116, '์–‘๋ฐฐ์ถ”', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(122, '๋ฐ”๋‚˜๋‚˜', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(131, '์ƒํฌ๋ฆผ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(138, '๋ƒ‰๋™๋ธ”๋ฃจ๋ฒ ๋ฆฌ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(143, '๋ฐ€๊ฐ€๋ฃจ', SYSDATE);
INSERT INTO TBL_STORAGE VALUES(147, '์œ ๊ธฐ๋† ๋‹ฌ๊ฑ€', SYSDATE);

COMMIT;

๐Ÿ‘‰ DTO

โ—ผ FoodCategoryDTO Class

public class FoodCategoryDTO {

	private int categoryCode;
	private String category;
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    /* getter & setter */
    /* toStirng */
}

โ—ผ FoodProductsDTO Class

public class FoodProductsDTO {
	
	private int prodCode;
	private String prodName;
	private int price;
	private String supplierName;
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    /* getter & setter */
    
    @Override
	public String toString() {
		return "-----------------------\n" + "|" + prodCode + "| " + prodName + " | " + price
				+ "์› | [" + supplierName + "]";
	}
}

โ—ผ StorageDTO Class

public class StorageDTO {
	
	private int prodCode;
	private String prodName;
	private String incomingDate;
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    /* getter & setter */
    
    @Override
	public String toString() {
		return "[" + incomingDate + "์ž…๊ณ ] " + "|" + prodCode + "| " + prodName;
	}
}

โ—ผ SupplierDTO Class

public class SupplierDTO {
	
	private int categoryCode;
	private String supplierCode;
	private String supplierName;
	private String address;
	private String contactNumber;
	private String orderYn;
	private FoodCategoryDTO foodCategory; // TBL_FOOD_CATEGORY์˜ category๋ฅผ ํ•จ๊ป˜ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€ <association>
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    /* getter & setter */
    
    @Override
	public String toString() {
		return "[" + supplierName + "]-----------------------\n* " + foodCategory + "์—…์ฒด(" + categoryCode + ")\n* ์—…์ฒด์ฝ”๋“œ : " + supplierCode + "\n* ์ฃผ์†Œ : " + address +
				"\n* ์—ฐ๋ฝ์ฒ˜ : " + contactNumber + "\n* ๊ฑฐ๋ž˜๊ฐ€๋Šฅ์—ฌ๋ถ€ : " + orderYn + "\n";
	}
    
}

โ—ผ OrderHistoryDTO Class

public class OrderHistoryDTO {
	
	private int orderCode;
	private String orderDate;
	private String orderTime;
	private int totalPrice;
	private List<StorageDTO> storageDTO; 
    // ์ฃผ๋ฌธ๋‚ด์—ญ๊ณผ ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ๋ฅผ ํ•˜๋‚˜์˜ ํŠธ๋žœ์žญ์…˜ ์•ˆ์—์„œ INSERTํ•˜๊ธฐ ์œ„ํ•ด List<StorageDTO> ํ•„๋“œ ์ƒ์„ฑ
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    /* getter & setter */
    
    @Override
	public String toString() {
		return "|" + orderCode + "|์ฃผ๋ฌธ์ผ์ž " + orderDate + "|์ฃผ๋ฌธ์‹œ๊ฐ " + orderTime
				+ "|์ด์•ก " + totalPrice + "์›";
	}
}

โ—ผ OrderProductsDTO Class

/* ํ…Œ์ด๋ธ”์— ์˜ํ•œ DTO๊ฐ€ ์•„๋‹Œ ์˜ค๋”ํ•œ ๋ชฉ๋ก์„ ์ถœ๋ ฅ ๋ฐ ๋‹ด๊ธฐ ์œ„ํ•œ DTO */
public class OrderProductsDTO {

	private int prodCode;
	private String prodName;
	private int price;
	private String supplierName;
    
    /* ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, ๋ชจ๋“  ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์žˆ๋Š” ์ƒ์„ฑ์ž */
    /* getter & setter */
    
    @Override
	public String toString() {
		return "-----------------------\n" + "|" + prodCode + "| " + prodName + " | " + price
				+ "์› | [" + supplierName + "]";
	}
}

๐Ÿ‘‰ View

โ—ผ MainView Class

public class MainView {
	
	private static Scanner sc = new Scanner(System.in);
	private static FoodProductsController fpController = new FoodProductsController();

	public void displayView() {

		do {
			System.out.println("");
			System.out.println("=====[ ์žฌ๋ฃŒ ์ฃผ๋ฌธ ๋ฐ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ ]=====");
			System.out.println("[A] ์žฌ๋ฃŒ ์ฃผ๋ฌธํ•˜๊ธฐ");
			System.out.println("[B] ์žฌ๋ฃŒ ๊ด€๋ฆฌํ•˜๊ธฐ");
			System.out.println("[C] ์›ํ•˜๋Š” ์žฌ๋ฃŒ ํŒ๋งค ์ œ์•ˆํ•˜๊ธฐ");
			System.out.println("[D] ์—…์ฒด ๊ด€๋ฆฌํ•˜๊ธฐ");
			System.out.println("[E] ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒํ•˜๊ธฐ");
			System.out.println("[Z] ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒํ•˜๊ธฐ");
			System.out.print("๋ฉ”๋‰ด ์„ ํƒ : ");
			char ch = sc.nextLine().toUpperCase().charAt(0);
			
			switch(ch) {
			case 'A': orderNewProduct(); break;
			case 'B': manageStorage(); break; 
			case 'C': suggestNewProduct(); break;
			case 'D': manageSupplier(); break;
			case 'E': fpController.selectOrderHistory(manageOrderHistory()); break;
			case 'Z': System.out.println("ํ”„๋กœ๊ทธ๋žจ์ด ์ข…๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค :D"); return;
			default : System.out.println("์ž˜๋ชป ๋œ ๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค! ๋‹ค์‹œ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” :(");
			}
			
		} while(true);	
	}
	/* [1] ์žฌ๋ฃŒ ์ฃผ๋ฌธํ•˜๊ธฐ */
	private static void orderNewProduct() {
		
		do {
			System.out.println("");
			System.out.println("=====[ ์žฌ๋ฃŒ ์ฃผ๋ฌธํ•˜๊ธฐ ]=====");
			System.out.println("[A] ์˜ค๋Š˜์˜ ์žฌ๋ฃŒ ๋จผ์ € ์ถ”์ฒœ๋ฐ›๊ธฐ");
			System.out.println("[B] ๊ฐ ์—…์ฒด๋งˆ๋‹ค์˜ ์žฌ๋ฃŒ ์กฐํšŒํ•˜๊ธฐ");
			System.out.println("[C] ์ฃผ๋ฌธ ์‹œ์ž‘ํ•˜๊ธฐ");
			System.out.println("[Z] โ—€ ๋Œ์•„๊ฐ€๊ธฐ");
			System.out.print("๋ฉ”๋‰ด ์„ ํƒ : ");
			char ch = sc.nextLine().toUpperCase().charAt(0);
			System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
			
			switch(ch) {
			case 'A' : fpController.selectRandomProducts(pickRandomProducts()); break;
			case 'B' : fpController.selectProductsBySupplier(pickSupplier()); break;
			case 'C' : fpController.insertOrderedProducts(OrderedProducts()); break;
			case 'Z' : return;
			}
			
		} while(true);
	}
	/* [1-1] ์˜ค๋Š˜์˜ ์žฌ๋ฃŒ ์ถ”์ฒœ๋ฐ›๊ธฐ */
	private static List<Integer> pickRandomProducts() {
		
		Set<Integer> set = new HashSet<>();
		while(set.size() < 3) {
			int temp = ((int) (Math.random() * 50)) + 100;
			set.add(temp);
		}
		
		List<Integer> list = new ArrayList<>(set); 
		
		return list;
	}
	/* [1-2] ๊ฐ ์—…์ฒด๋งˆ๋‹ค์˜ ์žฌ๋ฃŒ ์กฐํšŒํ•˜๊ธฐ */
	private static SearchCriteria pickSupplier() {
		
		System.out.println("");
		System.out.println("=====[ ์—…์ฒด ์„ ํƒํ•˜๊ธฐ ]=====");
		System.out.println("[A] ๊ตฝ๋„ค์ •์œก");
		System.out.println("[B] ๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘");
		System.out.println("[C] SING์‹ฑ์ฑ„์†Œ");
		System.out.println("[D] ๋ฒ ์ง€์ƒํšŒ");
		System.out.println("[E] ์น˜์ฆˆFARM");
		System.out.println("[F] ์–ผ์Œ๋•กํ‘ธ๋“œ");
		System.out.println("[G] ์งฑ๊ตฌ๋Š”๋ง๋ ค");
		System.out.println("[H] ๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„");
		System.out.println("[I] EGG๋จธ๋‹ˆ๋‚˜");
		System.out.print("๋ฉ”๋‰ด ์„ ํƒ : ");
		String value = sc.nextLine().toUpperCase();

		return new SearchCriteria(value);
	}
	/* [1-3] ์ฃผ๋ฌธ ์‹œ์ž‘ํ•˜๊ธฐ */
	private static OrderHistoryDTO OrderedProducts() {
		
		/* [1-3A] ์ „์ฒด ์žฌ๋ฃŒ ์กฐํšŒํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธฐ */
		List<FoodProductsDTO> allProductsList = fpController.selectAllProducts();
		
		/* ์ฃผ๋ฌธ๋“ค์„ ๋‹ด๊ธฐ ์œ„ํ•œ ๋ฆฌ์ŠคํŠธ */
		List<OrderProductsDTO> orderProductsList = new ArrayList<>(); 
		int totalPrice = 0; 
		
		/* ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ๋“ค ๋‹ด๊ธฐ์šฉ */
		List<StorageDTO> productsToStorageList = new ArrayList<>();
		
		do {
			System.out.println("");
			System.out.println("=====[ ์ฃผ๋ฌธ์ค‘... ]=====");
			System.out.print("์ฃผ๋ฌธํ•  ์žฌ๋ฃŒ๋ช… ์ž…๋ ฅ : ");
			
			String prodName = sc.nextLine();
			
			int prodCode = 0;
			int prodPrice = 0;
			String suppName = null;
			for(FoodProductsDTO prod : allProductsList) {
				if(prod.getProdName().equals(prodName)) {
					prodCode = prod.getProdCode();
					prodPrice = prod.getPrice();
					suppName = prod.getSupplierName();
				} 
			}

			/* ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ(๋“ค) ์ €์žฅ */
			OrderProductsDTO orderProducts = new OrderProductsDTO();
			orderProducts.setProdName(prodName);
			orderProducts.setProdCode(prodCode);
			orderProducts.setPrice(prodPrice);
			orderProducts.setSupplierName(suppName);
			
			orderProductsList.add(orderProducts); // orderProductsList์— ์ฃผ๋ฌธํ•œ ๊ฒƒ๋“ค ์ถ”๊ฐ€
			totalPrice += prodPrice; // ์ด์•ก ๊ณ„์‚ฐ
			
			System.out.print("๊ณ„์† ์ฃผ๋ฌธํ•˜์‹œ๊ฒ ์–ด์š”? :)\n(Y/N) : ");
			boolean isContinue = sc.nextLine().toUpperCase().equals("Y");
			
			/* [1-3C] ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
			java.util.Date orderDate = new java.util.Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd");
			String incomingDate = dateFormat.format(orderDate);
			
			StorageDTO storage = new StorageDTO();
			storage.setProdCode(prodCode);
			storage.setProdName(prodName);
			storage.setIncomingDate(incomingDate);
			productsToStorageList.add(storage);
			
			if(!isContinue) break;
			
		} while(true);
		
//		fpController.insertProductsToStorage(productsToStorageList);
//		์žฌ๋ฃŒ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์€ ์ฃผ๋ฌธ๋‚ด์—ญ๊ณผ ํ•จ๊ป˜ INSERT ๋˜์–ด์•ผํ•จ
		
		for(OrderProductsDTO orderMenu : orderProductsList) {
			System.out.println(orderMenu);
			
		}
		System.out.println("-----------------------\n์ด์•ก : " + totalPrice + "์›");
		
		/* [1-3B] ์ฃผ๋ฌธํ•œ ๋‚ด์—ญ ์ €์žฅํ•˜๊ธฐ */
		java.util.Date orderTime = new java.util.Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd"); 
		SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
		String date = dateFormat.format(orderTime);
		String time = timeFormat.format(orderTime);
		
		OrderHistoryDTO order = new OrderHistoryDTO();
		order.setOrderDate(date);
		order.setOrderTime(time);
		order.setTotalPrice(totalPrice);
		order.setStorageDTO(productsToStorageList); 
		/* ์ฃผ๋ฌธ๋‚ด์—ญ๊ณผ ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ๋ฅผ ํ•˜๋‚˜์˜ ํŠธ๋žœ์žญ์…˜ ์•ˆ์—์„œ INSERTํ•˜๊ธฐ ์œ„ํ•ด 
        	(๋‘˜ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋‚˜๋จธ์ง€ ํ•˜๋‚˜๋„ ์ž‘๋™๋˜์–ด์„  ์•ˆ๋จ)
		 * StorageDTO๋ฅผ OrderHistoryDTO์˜ ํ•„๋“œ์— ์„ ์–ธํ•œ ๋’ค,
		 * productsToStorageList๋ฅผ StorageDTO์— setํ•˜์—ฌ ํ•จ๊ป˜ ์ธ์ž๋กœ ์ „๋‹ฌ */
		
		return order;
	}
	/* [2] ์žฌ๋ฃŒ ๊ด€๋ฆฌํ•˜๊ธฐ */
	private static void manageStorage() {
		
		do {
			System.out.println("");
			System.out.println("=====[ ์žฌ๋ฃŒ ๊ด€๋ฆฌํ•˜๊ธฐ ]=====");
			System.out.println("[A] ์žฌ๋ฃŒ ํŒŒ์•…ํ•˜๊ธฐ");
			System.out.println("[B] ์žฌ๋ฃŒ ์‚ฌ์šฉํ•˜๊ธฐ");
			System.out.println("[C] ์ƒํ•œ ์žฌ๋ฃŒ ๊ตํ™˜๋ฐ›๊ธฐ");
			System.out.println("[D] ์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ๋ชจ๋‘ ํ๊ธฐํ•˜๊ธฐ");			
			System.out.println("[Z] โ—€ ๋Œ์•„๊ฐ€๊ธฐ");
			System.out.print("๋ฉ”๋‰ด ์„ ํƒ : ");
			char ch = sc.nextLine().toUpperCase().charAt(0);
			System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
			
			switch(ch) {
			case 'A' : fpController.selectProductsBySomething(inputSearchCriteria()); break;
			case 'B' : fpController.deletePickedProduct(useProduct()); break;
			case 'C' : fpController.updatePickedProduct(changeProduct()); break;
			case 'D' : fpController.deleteOldProducts(throwAwayOldProducts()); break;
			case 'Z' : return;
			}
			
		} while(true);
	}
	/* [2-1] ์žฌ๋ฃŒ ํŒŒ์•…ํ•˜๊ธฐ */
	private static SearchCriteria inputSearchCriteria() {
		
		System.out.println("");
		System.out.println("=====[ ์žฌ๋ฃŒ ํŒŒ์•…ํ•˜๊ธฐ ]=====");
		System.out.println("|   ์ „์ฒด   |   ์žฌ๋ฃŒ๋ช…๋ณ„   |");
		System.out.print("์žฌ๋ฃŒ ๋ชฉ๋ก ๊ธฐ์ค€ ์„ ํƒ : ");
		String condition = sc.nextLine();
		
		String value = null;
		if(condition.equals("์žฌ๋ฃŒ๋ช…๋ณ„")) {
			System.out.print("์žฌ๋ฃŒ๋ช… ์ž…๋ ฅ : ");
			value = sc.nextLine();
		}
		
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
		
		return new SearchCriteria(condition, value);
	}
	/* [2-2] ์žฌ๋ฃŒ ์‚ฌ์šฉํ•˜๊ธฐ */
	private static Map<String, String> useProduct() {
		
		System.out.println("");
		System.out.println("=====[ ์žฌ๋ฃŒ ์‚ฌ์šฉํ•˜๊ธฐ ]====="); 
		System.out.print("์‚ฌ์šฉํ•  ์žฌ๋ฃŒ๋ช… ์ž…๋ ฅ : ");
		String prodName = sc.nextLine();
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
		
		Map<String, String> param = new HashMap<>();
		param.put("prodName", prodName);
		
		return param;
	}
	/* [2-3] ์ƒํ•œ ์žฌ๋ฃŒ ๊ตํ™˜๋ฐ›๊ธฐ */
	private static Map<String, String> changeProduct() {
		
		System.out.println("");
		System.out.println("=====[ ์ƒํ•œ ์žฌ๋ฃŒ ๊ตํ™˜๋ฐ›๊ธฐ ]====="); 
		System.out.print("์ƒํ•œ ์žฌ๋ฃŒ๋ช… ์ž…๋ ฅ : ");
		String prodName = sc.nextLine();
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
		
		Map<String, String> param = new HashMap<>();
		param.put("prodName", prodName);
		
		return param;
	}
	/* [2-4] ์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ๋ชจ๋‘ ํ๊ธฐํ•˜๊ธฐ */
	private static Map<String, String> throwAwayOldProducts() {
		
		System.out.println("");
		System.out.println("=====[ ์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ๋ชจ๋‘ ํ๊ธฐํ•˜๊ธฐ ]====="); 
		System.out.println("๋ฉฐ์น  ์ด์ƒ ์ง€๋‚œ ์žฌ๋ฃŒ๋ฅผ ํ๊ธฐํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?");
		System.out.print("์ผ์ˆ˜ ์ž…๋ ฅ : ");
		String days = sc.nextLine();
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
		
		Map<String, String> param = new HashMap<>();
		param.put("days", days);
		
		return param;
	}
	/* [3] ์›ํ•˜๋Š” ์žฌ๋ฃŒ ํŒ๋งค ์ œ์•ˆํ•˜๊ธฐ */
	private static void suggestNewProduct() {
		
		System.out.println("");
		System.out.println("=====[ ์›ํ•˜๋Š” ์žฌ๋ฃŒ ํŒ๋งค ์ œ์•ˆํ•˜๊ธฐ ]=====");
		System.out.print("ํŒ๋งค๋ฅผ ์ œ์•ˆํ•  ์—…์ฒด๋ช…์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” :)\n : ");
		String supplier = sc.nextLine();
		System.out.print("์›ํ•˜๋Š” ์žฌ๋ฃŒ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” :)\n : ");
		String product = sc.nextLine();
		System.out.print("์›ํ•˜๋Š” ๊ฐ€๊ฒฉ์„ ์ œ์‹œํ•ด์ฃผ์„ธ์š” :)\n : ");
		String price = sc.nextLine();
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
			
		int intPrice = Integer.parseInt(price);
		if(intPrice > 5000) {
			Map<String, String> param = new HashMap<>();
			param.put("supplier", supplier);
			param.put("product", product);
			param.put("price", price);
				
			fpController.insertNewProduct(param);
				
		} else {
			System.out.println("์ œ์‹œํ•˜์‹  ๊ธˆ์•ก์ด ๋„ˆ๋ฌด ์ ์–ด ์—…์ฒด๊ฐ€ ๊ฑฐ์ ˆํ–ˆ์Šต๋‹ˆ๋‹ค :(");
		}
	}
	/* [4] ์—…์ฒด ๊ด€๋ฆฌํ•˜๊ธฐ */
	private static void manageSupplier() {

		do {
			System.out.println("");
			System.out.println("=====[ ์—…์ฒด ๊ด€๋ฆฌํ•˜๊ธฐ ]=====");
			System.out.println("[A] ๋ชจ๋“  ์—…์ฒด ์กฐํšŒํ•˜๊ธฐ");
			System.out.println("[B] ์ •๋ณด ๋ณ€๊ฒฝํ•˜๊ธฐ"); 
			System.out.println("[C] ๊ณ„์•ฝ ํ•ด์ง€ํ•˜๊ธฐ");		
			System.out.println("[Z] โ—€ ๋Œ์•„๊ฐ€๊ธฐ");
			System.out.print("๋ฉ”๋‰ด ์„ ํƒ : ");
			char ch = sc.nextLine().toUpperCase().charAt(0);
			System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
			
			switch(ch) {
			case 'A' : fpController.selectAllSupplier(); break;
			case 'B' : fpController.updateSupplierInfo(modifySupplier()); break;
			case 'C' : System.out.println("------------[WARNING]------------\n๊ณ„์•ฝ์„ ํ•ด์ง€ํ•  ์‹œ, ์žฌ๊ณ„์•ฝ์€ ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๊ณ„์† ์ง„ํ–‰ํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?\n(ํ•ด๋‹น ์—…์ฒด์˜ ์žฌ๋ฃŒ ๋˜ํ•œ ์ฃผ๋ฌธ๋ถˆ๊ฐ€)");
					   System.out.print("(Y/N) : ");
					   char yn = sc.nextLine().toUpperCase().charAt(0);
					   if(yn == 'N') {
						   return;
					   } else
					   System.out.println("์•ˆ์ „ํ•œ ๊ณ„์•ฝ ํ•ด์ง€๋ฅผ ์œ„ํ•ด ์•„๋ž˜์˜ ๋ฌธ์ž๋ฅผ ์•Œ๋งž์€ ์ˆœ์„œ๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” :)");
					   System.out.print("[ ofdo ]\n : ");
					   String word = sc.nextLine();
					   if(word.equals("food")) {
						   fpController.deleteSupplier(cancelSupplier()); break;
					   } else {
						   System.out.println("๋ฌธ์ž์˜ ์ˆœ์„œ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์•„์š” :( ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค !"); return;
					   }
			case 'Z' : return;
			}
			
		} while(true);
		
	}
	/* [4-2] ์ •๋ณด ๋ณ€๊ฒฝํ•˜๊ธฐ */
	private static Map<String, String> modifySupplier() {
		
		System.out.println("");
		System.out.println("=====[ ์ •๋ณด ๋ณ€๊ฒฝํ•˜๊ธฐ ]====="); 
		System.out.print("๋ณ€๊ฒฝํ•  ์—…์ฒด๋ช… ์ž…๋ ฅ : ");
		String suppName = sc.nextLine();
		System.out.println("*๋ณ€๊ฒฝํ•˜๊ณ ์ž ํ•˜๋Š” ์ •๋ณด๋งŒ ์ž…๋ ฅํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค !* โ–ถ ENTER");
		sc.nextLine();
		System.out.print("์ƒˆ๋กœ์šด ์ฃผ์†Œ ์ž…๋ ฅ : ");
		String newAddress = sc.nextLine();
		System.out.print("์ƒˆ๋กœ์šด ์—ฐ๋ฝ์ฒ˜ ์ž…๋ ฅ : ");
		String newContactNumber = sc.nextLine();
		System.out.print("๊ฑฐ๋ž˜๊ฐ€๋Šฅ์—ฌ๋ถ€ ์ž…๋ ฅ : ");
		String newOrderYn = sc.nextLine();
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
		
		Map<String, String> param = new HashMap<>();
		param.put("suppName", suppName);
		param.put("newAddress", newAddress);
		param.put("newContactNumber", newContactNumber);
		param.put("newOrderYn", newOrderYn);
		
		return param;
	}
	/* [4-3] ๊ณ„์•ฝ ํ•ด์ง€ํ•˜๊ธฐ */
	private static Map<String, String> cancelSupplier() {
		
		System.out.println("");
		System.out.println("=====[ ๊ณ„์•ฝ ํ•ด์ง€ํ•˜๊ธฐ ]====="); 
		System.out.print("์—…์ฒด๋ช… ์ž…๋ ฅ : ");
		String suppName = sc.nextLine();
		System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
		
		Map<String, String> param = new HashMap<>();
		param.put("suppName", suppName);
		
		return param;
	}
	/* [5] ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒํ•˜๊ธฐ */
	private static Map<String, String> manageOrderHistory() {

			System.out.println("");
			System.out.println("=====[ ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒํ•˜๊ธฐ ]=====");
			System.out.println("|    ์ตœ์‹ ์ˆœ    |    ๊ณผ๊ฑฐ์ˆœ    |");
			System.out.print(" : ");
			String range = sc.nextLine();
			System.out.println("์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ฃผ์„ธ์š” :)");
			
			Map<String, String> param = new HashMap<>();
			param.put("range", range);
			
			return param;
	}
}

โ—ผ ResultView Class

public class ResultView {

	/* ์žฌ๋ฃŒ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅ */
	public void printProductsList(List<FoodProductsDTO> ProductsList) {
		
		for(FoodProductsDTO o : ProductsList) {
			System.out.println(o);
		}	
	}
	
	/* ์—…์ฒด ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅ */
	public void printSupplierList(List<SupplierDTO> allSupplierList) {
		
		for(SupplierDTO o : allSupplierList) {
			System.out.println(o);
		}	
	}
	
	/* ์ฃผ๋ฌธ๋‚ด์—ญ ๋ฆฌ์ŠคํŠธ ์ถœ๋ ฅ */
	public void printOrderHistoryList(List<OrderHistoryDTO> orderHistoryList) {
		
		for(OrderHistoryDTO o : orderHistoryList) {
			System.out.println(o);
		}	
	}
	/* CompleteMessage */
	public void printCompleteMessage(String completeCode) {
		
		String completeMessage = "";
		switch(completeCode) {
		case "successInsertOrderedProducts" : completeMessage = "์„ฑ๊ณต์ ์œผ๋กœ ์ฃผ๋ฌธ์ด ์™„๋ฃŒ๋˜์–ด ์žฌ๋ฃŒ๊ฐ€ ์ฆ‰์‹œ ์ž…๊ณ ๋˜์—ˆ์–ด์š” :D"; break;
		case "successDeletePickedProduct" : completeMessage = "์žฌ๋ฃŒ๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค :D"; break;
		case "successUpdatePickedProduct" : completeMessage ="์‹ฑ์‹ฑํ•œ ์žฌ๋ฃŒ๋กœ ๊ตํ™˜ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค :D"; break;
		case "successDeleteOldProducts" : completeMessage = "์˜ค๋ž˜๋œ ์žฌ๋ฃŒ๋ฅผ ๋ชจ๋‘ ํ๊ธฐ ์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค :D"; break;
		case "successInsertNewProduct" : completeMessage = "์—…์ฒด๊ฐ€ ํŒ๋งค ์ œ์•ˆ์„ ๋ฐ›์•„๋“ค์—ฌ ์ด์ œ๋ถ€ํ„ฐ ์ฃผ๋ฌธ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค :D"; break;
		case "successUpdateSupplierInfo" : completeMessage = "์—…์ฒด ์ •๋ณด๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค :D"; break;
		case "successDeleteSupplier" : completeMessage = "๊ณ„์•ฝ์ด ์ •์ƒ์ ์œผ๋กœ ํ•ด์ง€๋˜์—ˆ์Šต๋‹ˆ๋‹ค :D"; break;
		}
		
		System.out.println(completeMessage);
	}
	/* ErrorMessages */
	public void printErrorMessage(String errorCode) {
		
		String errorMessage = "";
		switch(errorCode) {
		case "failSelectRandomProducts" : errorMessage = "์˜ค๋Š˜์˜ ์žฌ๋ฃŒ๋ฅผ ์ฐพ์ง€ ๋ชป ํ–ˆ์–ด์š” :("; break;
		case "failSelectProductsBySupplier" : errorMessage = "์žฌ๋ฃŒ๋“ค์„ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชป ํ–ˆ์–ด์š” :("; break;
		case "failInsetOrderedProducts" : errorMessage = "์ฃผ๋ฌธํ•˜์‹  ๋‚ด์—ญ์ด ์ „๋‹ฌ๋˜์ง€ ๋ชป ํ–ˆ์–ด์š” :("; break;
		case "failInsertProductsToStorage" : errorMessage = "์ž…๊ณ  ๋˜ํ•œ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค :( "; break;
		case "failSelectProductsBySomething" : errorMessage = "์žฌ๋ฃŒ ํŒŒ์•…์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failDeletePickedProduct" : errorMessage = "์žฌ๋ฃŒ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failUpdatePickedProduct" : errorMessage = "์žฌ๋ฃŒ๋ฅผ ๊ตํ™˜๋ฐ›์ง€ ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failDeleteOldProducts" : errorMessage = "ํ•ด๋‹น ์ผ์ˆ˜๊ฐ€ ์ง€๋‚œ ์žฌ๋ฃŒ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค :("; break;
		case "failInsertNewProduct" : errorMessage = "๋๋‚ด ์ œ์•ˆ์ด ๊ฑฐ์ ˆ ๋‹นํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failSelectAllSupplier" : errorMessage = "์—…์ฒด ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failUpdateSupplierInfo" : errorMessage = "์—…์ฒด๋ช…์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์•„ ์ •๋ณด ๋ณ€๊ฒฝ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failDeleteSupplier" : errorMessage = "์—…์ฒด๋ช…์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์•„ ๊ณ„์•ฝ ํ•ด์ง€์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		case "failSelectOrderHistory" : errorMessage = "์ฃผ๋ฌธ๋‚ด์—ญ์„ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค :("; break;
		}
		
		System.out.println(errorMessage);
	}
}

๐Ÿ‘‰ Controller

โ—ผ FoodProductsController Class

public class FoodProductsController {

	private final FoodProductsService fpService;
	private final ResultView rView;
	
	// ์œ„์˜ ํ•„๋“œ๋“ค์„ ์ƒ์„ฑ์ž์—์„œ ์ดˆ๊ธฐํ™”
	public FoodProductsController() {
		fpService = new FoodProductsService();
		rView = new ResultView();
	}
	/* [1-1] ์˜ค๋Š˜์˜ ์žฌ๋ฃŒ ์ถ”์ฒœ๋ฐ›๊ธฐ */
	public void selectRandomProducts(List<Integer> list) {

		List<FoodProductsDTO> RandomProductsList = fpService.selectRandomProducts(list);
		
		/* ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค„ Result View */
		if(RandomProductsList != null) {
			rView.printProductsList(RandomProductsList);
		} else {
			rView.printErrorMessage("failSelectRandomProducts");
		}
	}
	/* [1-2] ์œ ํ†ต์—…์ฒด ์„ ํƒํ•˜๊ธฐ */
	public void selectProductsBySupplier(SearchCriteria searchCriteria) {
		
		List<FoodProductsDTO> ProductsListBySupplier = fpService.selectProductsBySupplier(searchCriteria);
		
		if(ProductsListBySupplier != null) {
			rView.printProductsList(ProductsListBySupplier);
		} else {
			rView.printErrorMessage("failSelectProductsBySupplier");
		}
	}
	/* [1-3A] ์ „์ฒด ์žฌ๋ฃŒ ์กฐํšŒํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธฐ */
	public List<FoodProductsDTO> selectAllProducts() {
		
		List<FoodProductsDTO> allProductsList = fpService.selectAllProducts();
		
		return allProductsList;
	}
	/* [1-3B] ์ฃผ๋ฌธํ•œ ๋‚ด์—ญ ์ €์žฅํ•˜๊ธฐ / [1-3C] ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
	public void insertOrderedProducts(OrderHistoryDTO order) {
		
		if(fpService.insertOrderedProducts(order)) {
			rView.printCompleteMessage("successInsertOrderedProducts");
		} else {
			rView.printErrorMessage("failInsetOrderedProducts");
		}
	}
	/* [1-3C] ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
//	public void insertProductsToStorage(List<StorageDTO> productsToStorageList) {
//	
//		if(!fpService.insertProductsToStorage(productsToStorageList))
//			rView.printErrorMessage("failInsertProductsToStorage");
//	}
	/* [2-1] ์žฌ๋ฃŒ ํŒŒ์•…ํ•˜๊ธฐ */
	public void selectProductsBySomething(SearchCriteria searchCriteria) {
		
		List<StorageDTO> myProductsList = fpService.selectProductsBySomething(searchCriteria);
		
		if(myProductsList != null && !myProductsList.isEmpty()) {
			for(StorageDTO products : myProductsList) {
				System.out.println(products);
			}
		} else {
			rView.printErrorMessage("failSelectProductsBySomething");
		}
		
	}
	/* [2-2] ์žฌ๋ฃŒ ์‚ฌ์šฉํ•˜๊ธฐ */
	public void deletePickedProduct(Map<String, String> param) {
		
		String prodName = param.get("prodName");
		
		if(fpService.deletePickedProduct(prodName)) {
			rView.printCompleteMessage("successDeletePickedProduct");
		} else {
			rView.printErrorMessage("failDeletePickedProduct");
		}
		
	}
	/* [2-3] ์ƒํ•œ ์žฌ๋ฃŒ ๊ตํ™˜๋ฐ›๊ธฐ */
	public void updatePickedProduct(Map<String, String> param) {

		String prodName = param.get("prodName");
		
		if(fpService.updatePickedProduct(prodName)) {
			rView.printCompleteMessage("successUpdatePickedProduct");
		} else {
			rView.printErrorMessage("failUpdatePickedProduct");
		}
		
	}
	/* [2-4] ์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ๋ชจ๋‘ ํ๊ธฐํ•˜๊ธฐ */
	public void deleteOldProducts(Map<String, String> param) {
		
		int days = Integer.parseInt(param.get("days"));
		
		if(fpService.deleteOldProducts(days)) {
			rView.printCompleteMessage("successDeleteOldProducts");
		} else {
			rView.printErrorMessage("failDeleteOldProducts");
		}
		
	}
	/* [3] ์›ํ•˜๋Š” ์žฌ๋ฃŒ ํŒ๋งค ์ œ์•ˆํ•˜๊ธฐ */
	public void insertNewProduct(Map<String, String> param) {
		
		FoodProductsDTO foodProducts = new FoodProductsDTO();
		foodProducts.setProdName(param.get("product"));
		foodProducts.setPrice(Integer.parseInt(param.get("price")));
		foodProducts.setSupplierName(param.get("supplier"));
		
		if(fpService.insertNewProduct(foodProducts)) { 
			rView.printCompleteMessage("successInsertNewProduct");
		} else {
			rView.printErrorMessage("failInsertNewProduct");
		}
	}
	/* [4-1] ๋ชจ๋“  ์—…์ฒด ์กฐํšŒํ•˜๊ธฐ */
	public void selectAllSupplier() {
	
		List<SupplierDTO> allSupplierList = fpService.selectAllSupplier();
		
		if(allSupplierList != null) {
			rView.printSupplierList(allSupplierList);
		} else {
			rView.printErrorMessage("failSelectAllSupplier");
		}
	}
	/* [4-2] ์ •๋ณด ๋ณ€๊ฒฝํ•˜๊ธฐ */
	public void updateSupplierInfo(Map<String, String> param) {
		
		SupplierDTO supplier = new SupplierDTO();
		supplier.setSupplierName(param.get("suppName"));
		supplier.setAddress(param.get("newAddress"));
		supplier.setContactNumber(param.get("newContactNumber"));
		supplier.setOrderYn(param.get("newOrderYn"));
		
		if(fpService.updateSupplierInfo(supplier)) {
			rView.printCompleteMessage("successUpdateSupplierInfo");
		} else {
			rView.printErrorMessage("failUpdateSupplierInfo");
		}
	}
	/* [4-3] ๊ณ„์•ฝ ํ•ด์ง€ํ•˜๊ธฐ */
	public void deleteSupplier(Map<String, String> param) {
		
		String suppName = param.get("suppName");
		
		if(fpService.deleteSupplier(suppName)) {
			rView.printCompleteMessage("successDeleteSupplier");
		} else {
			rView.printErrorMessage("failDeleteSupplier");
		}
		
	}
	/* [5] ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒํ•˜๊ธฐ */
	public void selectOrderHistory(Map<String, String> param) {
		
		String range = param.get("range");
		
		List<OrderHistoryDTO> orderHistoryList = fpService.selectOrderHistory(range);
		
		if(orderHistoryList != null) {
			rView.printOrderHistoryList(orderHistoryList);
		} else {
			rView.printErrorMessage("failSelectOrderHistory");
		}
	}
}

๐Ÿ‘‰ Service

โ—ผ FoodProductsService Class

public class FoodProductsService {
	
	private FoodProductsMapper mapper;
	/* [1-1] ์˜ค๋Š˜์˜ ์žฌ๋ฃŒ ์ถ”์ฒœ๋ฐ›๊ธฐ */
	public List<FoodProductsDTO> selectRandomProducts(List<Integer> randomProductsList) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* Map์— ์ง‘์–ด๋„ฃ๊ธฐ */
		Map<String, List<Integer>> criteria = new HashMap<>();
		criteria.put("randomProductsList", randomProductsList);
		
		List<FoodProductsDTO> productsList = mapper.selectRandomProducts(criteria);
		
		sqls.close();
		
		return productsList;
	}
	/* [1-2] ์œ ํ†ต์—…์ฒด ์„ ํƒํ•˜๊ธฐ */
	public List<FoodProductsDTO> selectProductsBySupplier(SearchCriteria searchCriteria) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		List<FoodProductsDTO> productsList = mapper.selectProductsBySupplier(searchCriteria);
		
		sqls.close();
		
		return productsList;
	}
	/* [1-3A] ์ „์ฒด ํŒ๋งค ์žฌ๋ฃŒ ์กฐํšŒํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธฐ */
	public List<FoodProductsDTO> selectAllProducts() {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		List<FoodProductsDTO> allproductsList = mapper.selectAllProducts();

		sqls.close();
		
		return allproductsList;
	}
	/* [1-3B] ์ฃผ๋ฌธํ•œ ๋‚ด์—ญ ์ €์žฅํ•˜๊ธฐ / [1-3C] ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
	public boolean insertOrderedProducts(OrderHistoryDTO order) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* ์ฃผ๋ฌธํ•œ ๋‚ด์—ญ ์ €์žฅํ•˜๊ธฐ */
		int result1 = mapper.insertOrderedProducts(order);
		
		/* ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
		int result2 = 0;
		for(StorageDTO storage : order.getStorageDTO()) {
			result2 += mapper.insertProductsToStorage(storage);			
		}
		
		if(result1 > 0 && result2 > 0) { 
        // ์ฃผ๋ฌธ ๋‚ด์—ญ๊ณผ ์žฌ๋ฃŒ๋“ค์ด ๋ชจ๋‘ ์ •์ƒ์ ์œผ๋กœ INSERT๋˜์—ˆ์„ ๋•Œ, commit (ํ•˜๋‚˜์˜ ํŠธ๋žœ์žญ์…˜ ์•ˆ์—์„œ ์ˆ˜ํ–‰)
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result1 > 0 && result2 > 0 ? true : false;
	}
	/* [1-3C] ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
	public boolean insertProductsToStorage(List<StorageDTO> productsToStorageList) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* INSERT์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = 0;
		for(StorageDTO storage : productsToStorageList) {
			result += mapper.insertProductsToStorage(storage);
		}
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	}
	/* [2-1] ์žฌ๋ฃŒ ํŒŒ์•…ํ•˜๊ธฐ */
	public List<StorageDTO> selectProductsBySomething(SearchCriteria searchCriteria) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		List<StorageDTO> myProductsList = mapper.selectProductsBySomething(searchCriteria);

		sqls.close();
		
		return myProductsList;
	}
	/* [2-2] ์žฌ๋ฃŒ ์‚ฌ์šฉํ•˜๊ธฐ */
	public boolean deletePickedProduct(String prodName) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* DELETE์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = mapper.deletePickedProduct(prodName);
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	}
	/* [2-3] ์ƒํ•œ ์žฌ๋ฃŒ ๊ตํ™˜๋ฐ›๊ธฐ */
	public boolean updatePickedProduct(String prodName) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* UPDATE์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = mapper.updatePickedProduct(prodName);
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	}
	/* [2-4] ์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ๋ชจ๋‘ ํ๊ธฐํ•˜๊ธฐ */
	public boolean deleteOldProducts(int days) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* DELETE์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = mapper.deleteOldProducts(days);
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	
	}
	/* [3] ์›ํ•˜๋Š” ์žฌ๋ฃŒ ํŒ๋งค ์ œ์•ˆํ•˜๊ธฐ */
	public boolean insertNewProduct(FoodProductsDTO foodProducts) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* INSERT์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = mapper.insertNewProduct(foodProducts);
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	}
	/* [4-1] ๋ชจ๋“  ์—…์ฒด ์กฐํšŒํ•˜๊ธฐ */
	public List<SupplierDTO> selectAllSupplier() {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		List<SupplierDTO> allSupplierList = mapper.selectAllSupplier();
		
		sqls.close();
		
		return allSupplierList;
	}
	/* [4-2] ์ •๋ณด ๋ณ€๊ฒฝํ•˜๊ธฐ */
	public boolean updateSupplierInfo(SupplierDTO supplier) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* UPDATE์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = mapper.updateSupplierInfo(supplier);
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	}
	/* [4-3] ๊ณ„์•ฝ ํ•ด์ง€ํ•˜๊ธฐ */
	public boolean deleteSupplier(String suppName) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		
		/* DELETE์ด๋ฏ€๋กœ int๋กœ ๋ฐ˜ํ™˜๋ฐ›๊ธฐ */
		int result = mapper.deleteSupplier(suppName);
		
		if(result > 0) {
			sqls.commit();
		} else {
			sqls.rollback();
		}
		
		sqls.close();
		
		return result > 0 ? true : false;
	}
	/* [5] ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒํ•˜๊ธฐ */
	public List<OrderHistoryDTO> selectOrderHistory(String range) {
		
		SqlSession sqls = getSqlSession();
		mapper = sqls.getMapper(FoodProductsMapper.class);
		List<OrderHistoryDTO> orderHistoryList = mapper.selectOrderHistory(range);
		
		sqls.close();
		
		return orderHistoryList;
	}
}

๐Ÿ‘‰ Mapper

โ—ผ FoodProductsMapper Interface

public interface FoodProductsMapper {

	/* [1-1] ์˜ค๋Š˜์˜ ์žฌ๋ฃŒ ์ถ”์ฒœ๋ฐ›๊ธฐ */
	List<FoodProductsDTO> selectRandomProducts(Map<String, List<Integer>> criteria);

	/* [1-2] ์œ ํ†ต์—…์ฒด ์„ ํƒํ•˜๊ธฐ */
	List<FoodProductsDTO> selectProductsBySupplier(SearchCriteria searchCriteria);

	/* [1-3A] ์ „์ฒด ๋ฉ”๋‰ด ์กฐํšŒํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธฐ */
	List<FoodProductsDTO> selectAllProducts();

	/* [1-3B] ์ฃผ๋ฌธํ•œ ๋‚ด์—ญ ์ €์žฅํ•˜๊ธฐ */
	int insertOrderedProducts(OrderHistoryDTO order);

	/* [1-3C] ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ ์ €์žฅ๊ณ ์— ์ถ”๊ฐ€ํ•˜๊ธฐ */
	int insertProductsToStorage(StorageDTO storageDTO);

	/* [2-1] ์žฌ๋ฃŒ ํŒŒ์•…ํ•˜๊ธฐ */
	List<StorageDTO> selectProductsBySomething(SearchCriteria searchCriteria);

	/* [2-2] ์žฌ๋ฃŒ ์‚ฌ์šฉํ•˜๊ธฐ */
	int deletePickedProduct(String prodName);

	/* [2-3] ์ƒํ•œ ์žฌ๋ฃŒ ๊ตํ™˜๋ฐ›๊ธฐ */
	int updatePickedProduct(String prodName);

	/* [2-4] ์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ๋ชจ๋‘ ํ๊ธฐํ•˜๊ธฐ */
	int deleteOldProducts(int days);

	/* [3] ์›ํ•˜๋Š” ์žฌ๋ฃŒ ํŒ๋งค ์ œ์•ˆํ•˜๊ธฐ */
	int insertNewProduct(FoodProductsDTO foodProducts);

	/* [4-1] ๋ชจ๋“  ์—…์ฒด ์กฐํšŒํ•˜๊ธฐ */
	List<SupplierDTO> selectAllSupplier();

	/* [4-2] ์ •๋ณด ๋ณ€๊ฒฝํ•˜๊ธฐ */
	int updateSupplierInfo(SupplierDTO supplier);

	/* [4-3] ๊ณ„์•ฝ ํ•ด์ง€ํ•˜๊ธฐ */
	int deleteSupplier(String suppName);

	/* [5] ์ฃผ๋ฌธ๋‚ด์—ญ ์กฐํšŒํ•˜๊ธฐ */
	List<OrderHistoryDTO> selectOrderHistory(String range);
}

โ—ผ FoodProductsMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.joyhyonie.foodProducts.mapper.FoodProductsMapper">

	<resultMap type="com.joyhyonie.foodProducts.model.dto.FoodProductsDTO" id="foodProductsResultMap">
		<id property="prodCode" column="PROD_CODE"/>
		<result property="prodName" column="PROD_NAME"/>
		<result property="price" column="PRICE"/>
		<result property="supplierName" column="SUPPLIER_NAME"/>
	</resultMap>
	
	<resultMap type="com.joyhyonie.foodProducts.model.dto.OrderHistoryDTO" id="orderHistoryResultMap">
		<id property="orderCode" column="ORDER_CODE"/>
		<result property="orderDate" column="ORDER_DATE"/>
		<result property="orderTime" column="ORDER_TIME"/>
		<result property="totalPrice" column="TOTAL_PRICE"/>
	</resultMap>
	
	<resultMap type="com.joyhyonie.foodProducts.model.dto.StorageDTO" id="storageResultMap">
		<id property="prodCode" column="PROD_CODE"/>
		<result property="prodName" column="PROD_NAME"/>
		<result property="incomingDate" column="INCOMING_DATE"/>
	</resultMap>
	
	<resultMap type="com.joyhyonie.foodProducts.model.dto.SupplierDTO" id="supplierResultMap">
		<id property="supplierCode" column="SUPPLIER_CODE"/>
		<result property="categoryCode" column="CATEGORY_CODE"/>
		<result property="supplierName" column="SUPPLIER_NAME"/>
		<result property="address" column="ADDRESS"/>
		<result property="contactNumber" column="CONTACT_NUMBER"/>
		<result property="orderYn" column="ORDER_YN"/>
      	<!-- JOIN ํ•˜๊ธฐ ์œ„ํ•ด <association> ์‚ฌ์šฉ -->
		<association property="foodCategory" javaType="com.joyhyonie.foodProducts.model.dto.FoodCategoryDTO">
			<id property="categoryCode" column="CATEGORY_CODE"/>
			<result property="category" column="CATEGORY"/>
		</association>
	</resultMap>
  <select id="selectRandomProducts" parameterType="hashmap" resultMap="foodProductsResultMap">
  SELECT
    		PROD_CODE
    	,	PROD_NAME
    	,	PRICE
    	,	SUPPLIER_NAME
    	FROM TBL_PRODUCTS
    	JOIN TBL_SUPPLIER USING(SUPPLIER_NAME)
    	WHERE ORDER_YN = 'Y'
    	AND PROD_CODE IN
    	<foreach collection="randomProductsList" item="prodCode" open="(" separator="," close=")"> 
    		#{ prodCode }
    	</foreach>
    	ORDER BY PROD_CODE
  </select>
  <select id="selectProductsBySupplier" parameterType="SerchCriteria" resultMap="foodProductsResultMap"> 
  SELECT
    		PROD_CODE
    	,	PROD_NAME
    	,	PRICE
    	,	SUPPLIER_NAME
  		FROM TBL_PRODUCTS
  		JOIN TBL_SUPPLIER USING(SUPPLIER_NAME)
  		WHERE ORDER_YN = 'Y'
  		<choose>
  			<when test='value == "A"'>
  			AND SUPPLIER_NAME = '๊ตฝ๋„ค์ •์œก'</when>
  			<when test='value == "B"'>
  			AND SUPPLIER_NAME = '๋ฐ”๋‹คํšŒ์‚ฌ๋ž‘'</when>
  			<when test='value == "C"'>
  			AND SUPPLIER_NAME = 'SING์‹ฑ์ฑ„์†Œ'</when>
  			<when test='value == "D"'>
  			AND SUPPLIER_NAME = '๋ฒ ์ง€์ƒํšŒ'</when>
  			<when test='value == "E"'>
  			AND SUPPLIER_NAME = '์น˜์ฆˆFARM'</when>
  			<when test='value == "F"'>
  			AND SUPPLIER_NAME = '์–ผ์Œ๋•กํ‘ธ๋“œ'</when>
  			<when test='value == "G"'>
  			AND SUPPLIER_NAME = '์งฑ๊ตฌ๋Š”๋ง๋ ค'</when>
  			<when test='value == "H"'>
  			AND SUPPLIER_NAME = '๊ผฌ์ˆœ๋‚ด๋ฐฉ์•—๊ฐ„'</when>
  			<when test='value == "I"'>
  			AND SUPPLIER_NAME = 'EGG๋จธ๋‹ˆ๋‚˜'</when>
  		</choose>
  		ORDER BY PROD_CODE
  </select>
  <select id="selectAllProducts" resultMap="foodProductsResultMap">
  	SELECT
    		PROD_CODE
    	,	PROD_NAME
    	,	PRICE
    	,	SUPPLIER_NAME
  		FROM TBL_PRODUCTS
  </select>
  <insert id="insertOrderedProducts" parameterType="com.joyhyonie.foodProducts.model.dto.OrderHistoryDTO">
  	INSERT
  		INTO TBL_ORDER_HISTORY
  	(
  		ORDER_CODE
	,	ORDER_DATE
	,	ORDER_TIME
	,	TOTAL_PRICE
	)
	VALUES
	(
		SEQ_ORDER_CODE.NEXTVAL
	,	#{ orderDate }
	,	#{ orderTime }
	,	#{ totalPrice }
  	)
  </insert>
  <insert id="insertProductsToStorage" parameterType="com.joyhyonie.foodProducts.model.dto.StorageDTO">
  	INSERT
  		INTO TBL_STORAGE
  	(
  		PROD_CODE
  	,	PROD_NAME
  	,	INCOMING_DATE
  	)
  	VALUES
  	(
  		#{ prodCode }
  	,	#{ prodName }
  	,	#{ incomingDate	}
  	)
  </insert>
  <select id="selectProductsBySomething" parameterType="SerchCriteria" resultMap="storageResultMap">
  	SELECT
  			PROD_CODE
  		,	PROD_NAME
  		,	INCOMING_DATE
  		FROM TBL_STORAGE
  		<if test="condition == '์žฌ๋ฃŒ๋ช…๋ณ„'">
  		WHERE PROD_NAME LIKE '%' || #{ value } || '%'
  		</if>
  		ORDER BY INCOMING_DATE
  </select>
  <delete id="deletePickedProduct" parameterType="string">
  	DELETE
  		FROM TBL_STORAGE
  		WHERE PROD_NAME = #{ prodName }
  </delete>
  
  <update id="updatePickedProduct" parameterType="string">
  	UPDATE
  			TBL_STORAGE
  		SET INCOMING_DATE = SYSDATE
  		WHERE PROD_NAME = #{ prodName }
  </update>
  <delete id="deleteOldProducts" parameterType="_int">
  	DELETE
  		FROM TBL_STORAGE
  	 WHERE ROUND(MONTHS_BETWEEN(SYSDATE, INCOMING_DATE) * 24) >= #{ days } 
  </delete>
  <insert id="insertNewProduct" parameterType="com.joyhyonie.foodProducts.model.dto.FoodProductsDTO">
  	INSERT
  		INTO TBL_PRODUCTS
  	(
  		PROD_CODE
  	,	PROD_NAME
  	,	PRICE
  	,	SUPPLIER_NAME	
  	)
  	VALUES
  	(
  		SEQ_PROD_CODE.NEXTVAL
  	,	#{ prodName }
  	,	#{ price }
 	,	#{ supplierName }
 	)
  </insert>
  <select id="selectAllSupplier" resultMap="supplierResultMap"> <!-- <association> ์‚ฌ์šฉ -->
  	SELECT
  			A.CATEGORY_CODE
  		,	A.SUPPLIER_CODE
  		,	A.SUPPLIER_NAME
  		,	A.ADDRESS
  		,	A.CONTACT_NUMBER
  		,	A.ORDER_YN
  		,	B.CATEGORY
  		FROM TBL_SUPPLIER A
  		JOIN TBL_FOOD_CATEGORY B ON (A.CATEGORY_CODE = B.CATEGORY_CODE)
  		ORDER BY CATEGORY_CODE
  </select>
  <update id="updateSupplierInfo" parameterType="com.joyhyonie.foodProducts.model.dto.SupplierDTO">
  	UPDATE
  		TBL_SUPPLIER
  	<trim prefix="SET" prefixOverrides=",">
  		<if test="address != null and address !=''">
  		ADDRESS = #{ address } </if>
  		<if test="contactNumber != null and contactNumber !=''">
  	,	CONTACT_NUMBER = #{ contactNumber } </if>
  		<if test="orderYn != null and orderYn !=''">
  	,	ORDER_YN = #{ orderYn } </if>
  	</trim>
  	WHERE SUPPLIER_NAME = #{ supplierName }
  </update>
  <delete id="deleteSupplier" parameterType="string">
  	DELETE
  		FROM TBL_SUPPLIER
  		WHERE SUPPLIER_NAME = #{ supplierName }
  </delete>
  <select id="selectOrderHistory" resultMap="orderHistoryResultMap">
  	SELECT
  		ORDER_CODE
	,	ORDER_DATE
	,	ORDER_TIME
	,	TOTAL_PRICE
	FROM TBL_ORDER_HISTORY
	ORDER BY ORDER_DATE <if test="range == '์ตœ์‹ ์ˆœ'">DESC</if>, ORDER_TIME <if test="range == '์ตœ์‹ ์ˆœ'">DESC</if>
  </select>

</mapper>

๐Ÿ‘‰ Run

โ—ผ Application Class

public class Application {

	public static void main(String[] args) {
		
		new MainView().displayView();
	}
}

๐Ÿ’ฌ Overall Comment

์ฒ˜์Œ์œผ๋กœ Mybatis๋ฅผ ํ™œ์šฉํ•ด์„œ MVC ๊ตฌ์กฐ๋กœ ์ฝ˜์†” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด๋ณด์•˜๋‹ค. ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ์ฃผ์ œ๋ฅผ ์„ ํƒํ•˜์—ฌ ์ œ์ž‘ํ•  ์ˆ˜ ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฒซ ์ œ์ž‘๊ณผ์ •๋ถ€ํ„ฐ ์„ค๋ ˆ๊ณ  ์ •๋ง ์žฌ๋ฏธ์žˆ์—ˆ๋‹ค. DB๋ถ€ํ„ฐ ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑํ•˜๋ฉด ํšจ์œจ์ ์ผ์ง€ ๊ณ ๋ฏผ์„ ๊ต‰์žฅํžˆ ๋งŽ์ด ํ–ˆ๊ณ  ์—‘์…€์— ์ง์ ‘ ์™„์„ฑ๋œ ํ…Œ์ด๋ธ”์ด ์–ด๋–ป๊ฒŒ ๋ณด์ด๋Š”์ง€ ๋งŒ๋“ค์–ด ๋ณด๊ธฐ๋„ ํ–ˆ๋‹ค. ๊ฒฐ๊ณผ์ ์œผ๋กœ ์•ฝ๊ฐ„ ์ˆ˜์ •๋˜๊ณ  ์‚ญ์ œ๋˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์—ˆ์œผ๋‚˜, DB๋ชจ๋ธ๋ง์„ ๋ฐฐ์šฐ๊ธฐ ์ „์ด์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์—‘์…€์„ ํ™œ์šฉํ•œ DB๊ตฌ์กฐ ์ž‘์—…์€ ํ™•์‹คํžˆ ํฐ ๋„์›€์ด ๋˜์—ˆ๋‹ค.

๋ช‡ ์‹œ๊ฐ„๋™์•ˆ ๊ตฌ์„ฑ์„ ํ•˜๊ณ  ํ…Œ์ด๋ธ”์„ ์™„์„ฑํ•˜๊ณ ๋‚˜๋‹ˆ, ์ด์ œ ์ดํด๋ฆฝ์Šค์—์„œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผํ–ˆ๋‹ค. ์ฐจ๊ทผ์ฐจ๊ทผ ํด๋”๋ฅผ ์ƒ์„ธํžˆ ๋‚˜๋ˆ„๊ณ  ์˜คํƒ€๋Š” ์—†๋Š”์ง€ ์ •๋ง ์ˆ˜์—†์ด ํ™•์ธ์„ ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ์ด์ œ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•˜๋‚˜ํ•˜๋‚˜ ๋„ฃ์–ด๊ฐ€๋ฉด ๋˜์—ˆ๋Š”๋ฐ, ์ด๋ฏธ ํ•œ๋ฒˆ MVC๊ตฌ์กฐ๋ฅผ ์—ฐ์Šตํ•ด๋ณธ ๊ฒฝํ—˜์ด ์žˆ์—ˆ์œผ๋‚˜ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์‹œ๋„ํ•ด๋ณด๊ณ ์ž ํ•˜๋Š” ์š•์‹ฌ๋•์— ์ดˆ๋ฐ˜๋ถ€ํ„ฐ ๊ฝค ์• ๋ฅผ ๋จน์—ˆ๋‹ค.

์™„์ „ํ•œ ์ฒซ ๊ธฐ๋Šฅ์ด์—ˆ๋˜ '์˜ค๋Š˜์˜ ์žฌ๋ฃŒ ์ถ”์ฒœ๋ฐ›๊ธฐ'๋ฅผ ๋งŒ๋“ค๊ณ  ๋‹คํ–‰์Šค๋Ÿฝ๊ฒŒ๋„ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™์€ ๋˜์—ˆ์œผ๋‚˜, ์ด๊ฒŒ ์™ ๊ฑธ ์žฌ๋ฃŒ 3๊ฐœ๊ฐ€ ๊ณ ์ •์ ์œผ๋กœ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ 0๊ฐœ, 1๊ฐœ, 2๊ฐœ, 3๊ฐœ ๋“ฑ๋“ฑ ๊ฐฏ์ˆ˜ ๋˜ํ•œ ๋žœ๋ค์œผ๋กœ ์ถœ๋ ฅ๋˜์–ด ์ ์ž–์ด ๋‹นํ™ฉํ–ˆ๋‹ค. ์›์ธ์ด ๋„๋ฌด์ง€ ๋ญ”์ง€ ๋„ํ†ต ๋ชจ๋ฅด๊ฒ ์–ด์„œ ์„ ์ƒ๋‹˜๊ป˜ ์ž๋ฌธ์„ ๊ตฌํ–ˆ๋Š”๋ฐ, ์ •๋ง ์—ฌ์ญค๋ณด๊ธฐ๋„ ๋ฏผ๋งํ• ๋งŒํผ ์‚ฌ์†Œํ–ˆ๋‹ค. 100๋ฒˆ๋ถ€ํ„ฐ 150๋ฒˆ์˜ ์žฌ๋ฃŒ๋ฅผ ๋žœ๋ค์œผ๋กœ 3๊ฐœ ๋ฝ‘์œผ๋ ค๋ฉด, (int) (Math.random() * 50)) + 100์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผํ–ˆ๋Š”๋ฐ, (int) (Math.random() * 150)) + 100์œผ๋กœ ์ž‘์„ฑํ•˜๋‹ˆ ๋‹น์—ฐํžˆ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ์žฌ๋ฃŒ๋“ค์€ ์ถœ๋ ฅ๋˜์ง€ ์•Š์€ ๊ฒƒ์ด์—ˆ๋‹ค. ์ •์‹ ์ฐจ๋ฆฌ๊ณ  ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผ๊ฒ ๋‹ค๊ณ  ๋‹ค์งํ•œ ํ•œ ๋ถ€๋ถ„์ด์—ˆ๋‹ค..!

๊ทธ๋ฆฌ๊ณ  ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋™์ ์ฟผ๋ฆฌ์™€ ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์ตœ๋Œ€ํ•œ ํ™œ์šฉํ•˜๊ณ ์ž, <association>, <foreach>, <choose>&<when>, <if>, <trim>๋“ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฟผ๋ฆฌ๋ฌธ์„ ์ž‘์„ฑํ–ˆ๊ณ  ํŠนํžˆ '์˜ค๋ž˜๋œ ์žฌ๋ฃŒ ํ๊ธฐํ•˜๊ธฐ'๊ธฐ๋Šฅ์„ ์œ„ํ•ด ์‚ฌ์šฉํ–ˆ๋˜ MONTHS_BETWEEN์ด ๊ธฐ์–ต์— ๋‚จ๋Š”๋‹ค! ์ฟผ๋ฆฌ๋ฌธ์„ ์š”๋ฆฌ์กฐ๋ฆฌ ์ž‘์„ฑํ•ด๋ณด๋Š”๊ฒŒ ๋„ˆ๋ฌด ์žฌ๋ฏธ์žˆ์–ด์„œ ๊ผญ ํ”„๋กœ๊ทธ๋žจ์„ ์ œ์ž‘ํ•  ๋•Œ ์—ฌ๋Ÿฌ๊ฐ€์ง€๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ, ์ƒ๊ฐ์ฒ˜๋Ÿผ ์ž˜ ๊ตฌํ˜„๋˜์–ด ๊ธฐ๋ถ„์ด ์ข‹์•˜๋‹ค :)
์ˆ˜์—…์—์„œ ๊ทธ๋ƒฅ ๋ฐฐ์šด ๊ฒƒ๊ณผ ํ•œ๋ฒˆ์ด๋ผ๋„ ๋‚ด ๊ฒƒ์œผ๋กœ ์‚ฌ์šฉํ•ด๋ณด๋Š” ๊ฒƒ์€ ์ •๋ง ์ฒœ์ง€์ฐจ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์•ž์œผ๋กœ๋„ ๊ณ„์† ๊พธ์ค€ํžˆ ํ™œ์šฉํ•  ์˜ˆ์ •์ด๋‹ค.

๋˜ํ•œ, ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰๊นŒ์ง€ ์• ๋ฅผ ๋จน์—ˆ๋˜ ๋ถ€๋ถ„์ธ '์ฃผ๋ฌธ ์‹œ์ž‘ํ•˜๊ธฐ'... ์ •๋ง ์ •๋ง ๊นŒ๋‹ค๋กœ์› ์œผ๋‚˜ ๋‚ด๊ฐ€ ๊ตฌํ˜„ํ•œ ๊ธฐ๋Šฅ ์ค‘ ์ •๋ง ์ž์‹ ์žˆ๊ฒŒ ๋จผ์ € ์„ ๋ณด์ด๊ณ  ์‹ถ์€ ๊ธฐ๋Šฅ์ด์—ˆ๋‹ค. ํ›—๋‚  ์ด ๋ชจ์Šต์„ ๋‚ด๊ฐ€ ๋ณด๊ฒŒ ๋œ๋‹ค๋ฉด ๊ฒจ์šฐ ์ด๊ฑฐ ๊ฐ€์ง€๊ณ  ์ฉ”์ฉ” ๋งค์—ˆ๋˜๊ฒŒ ๊ท€์—ฌ์›Œ ๋ณด์ผ ๋“ฏ ํ•˜์ง€๋งŒ ๊ตฌํ˜„ํ•˜๊ณ ๋‚˜์„œ ๋„ˆ๋ฌด ๋ฟŒ๋“ฏํ–ˆ๋‹ค. ๋‚ด๊ฐ€ ์›ํ–ˆ๋˜ ๋ถ€๋ถ„์€ ์‚ฌ์šฉ์ž๊ฐ€ ์—ฌ๋Ÿฌ ์žฌ๋ฃŒ๋ฅผ ๊ณ„์† ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ ๋’ค, ์ฃผ๋ฌธ์ด ๋๋‚˜๋ฉด ์ด์•ก ๋ฐ ์ฃผ๋ฌธํ•œ ์žฌ๋ฃŒ๋“ค์„ ์ถœ๋ ฅํ•ด์ฃผ๊ณ  ๊ทธ์— ๋”ฐ๋ผ Storage, OrderHistory ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ž๋™์œผ๋กœ ์ €์žฅ๋˜๊ฒŒ ๋งŒ๋“ค๋„๋ก ํ•˜๊ณ ์‹ถ์—ˆ๋‹ค. ์ƒ๊ฐ๋งŒํผ ์ˆ˜์›”ํ•œ ๊ณผ์ •์€ ์•„๋‹ˆ์—ˆ๊ณ  ์—ฌ๋Ÿฌ ์žฌ๋ฃŒ๋ฅผ Insertํ•˜๊ธฐ ์œ„ํ•ด List๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์ด ํ’€์–ด๋‚ด์•ผํ•  ์ˆ™์ œ์˜€๋‹ค. ํ•˜์ง€๋งŒ ์ •๋ง ๋ง์ฒ˜๋Ÿผ ์‰ฝ์ง€ ์•Š์•˜๊ณ  ๊ณ„์† ํ•œ ๊ฐ€์ง€ ์žฌ๋ฃŒ๋งŒ ์‚ฝ์ž…๋˜์—ˆ๋‹ค... :(
๊ณ„์† ๋ถ™์žก๊ณ  ์žˆ๋‹ค๊ฐ€ ์•ˆ๋  ๊ฒƒ ๊ฐ™์•„์„œ ์„ ์ƒ๋‹˜๊ป˜ ์ž๋ฌธ์„ ๊ตฌํ–ˆ๊ณ  Service์—์„œ for๋ฌธ์„ ์ด์šฉํ•˜์—ฌ ๊ฐ’์„ ํ•˜๋‚˜ํ•˜๋‚˜ ๋ฝ‘์•„๋‚ด์–ด ๋„˜๊ธฐ๋ฉด ๋œ๋‹ค๋Š” ๊ฒฐ์ •์ ์ธ ํžŒํŠธ๋ฅผ ์–ป๊ฒŒ ๋˜์—ˆ๋‹ค. ๋“œ๋””์–ด ๊ตฌํ˜„์ด ๋˜์—ˆ๊ณ  ๋›ธ ๋“ฏ์ด ๊ธฐ๋ปค๋‹ค.

ํ•˜์ง€๋งŒ, ๋‚ด๊ฐ€ ์งˆ๋ฌธํ–ˆ์„ ๋•Œ ์ „์ฒด์ ์ธ ์ฝ”๋“œ๋ฅผ ์„ ์ƒ๋‹˜์ด ๋ด์ฃผ์‹œ๋‹ค๊ฐ€ Storage์™€ OrderHistory์— insert๋  ๋•Œ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์—์„œ ์ˆ˜ํ–‰๋˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•ด ์ฃผ์…จ๊ณ  ์ด ๋‘˜์„ ํ•˜๋‚˜์˜ ํŠธ๋žœ์žญ์…˜์—์„œ ์ˆ˜ํ–‰ํ•˜๋„๋ก ์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ๊ณ ์ณ์•ผ๋งŒํ–ˆ๋‹ค. (์ ˆ๋ง) ์ด ๋˜ํ•œ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ๊ณ ์ณ์•ผํ•˜๋Š”์ง€ ๊ทธ ์‹œ์ ์— ๋ฐฐ์šฐ๊ฒŒ ๋˜์—ˆ๊ณ  ๋๋‚ด ์™„์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์–ด ์ •๋ง ๋งŽ์ด ๋ฟŒ๋“ฏํ–ˆ๋‹ค.

ํ•œ ๊ฐ€์ง€ ๋”, ์‹œ๊ฐ„์ด ๋” ์žˆ์—ˆ๋‹ค๋ฉด ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์€ ์š•์‹ฌ ๋‚˜๋Š” ๊ธฐ๋Šฅ์ด ์žˆ๋Š”๋ฐ Storage์— ์ด๋ฏธ ์žˆ๋Š” ์žฌ๋ฃŒ๋“ค์€ ์ฃผ๋ฌธํ•˜์ง€ ๋ชป ํ•˜๋„๋ก ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ณ ์‹ถ๋‹ค. ์ด๊ฑด ์•„๋งˆ๋„ Storage๋ฅผ ์ „์ฒด ์กฐํšŒํ•œ ๋’ค, !@@.equals()๋ฅผ ์ด์šฉํ•˜์—ฌ ์ด ๋•Œ๋งŒ ์ฃผ๋ฌธ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•˜๊ฒŒ ๋งŒ๋“ค๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค.

๊ฒฐ๊ณผ์ ์œผ๋กœ ๋‚ด๊ฐ€ ์›ํ–ˆ๋˜ ์ž‘์ง€๋งŒ ๋‚˜๋ฆ„ ์•Œ์ฐฌ ์ฝ˜์†” ํ”„๋กœ๊ทธ๋žจ์ด ์™„์„ฑ๋˜์–ด ๊ฐํšŒ๊ฐ€ ์ƒˆ๋กญ๊ณ  ๊ธฐ๋ถ„์ด ์ข‹๋‹ค :)
๋” ์œ ์šฉํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ๊ณ„์† ํ•ด์„œ ๋งŒ๋“ค์–ด ๋‚˜๊ฐ€๊ณ  ์‹ถ๋‹ค!

profile
Tiny little habits make me

0๊ฐœ์˜ ๋Œ“๊ธ€