2025年5月

ChatGPT https://chatgpt.com
perplexity https://perplexity.ai
Genspark https://genspark.ai

Midjourney https://midjourney.com
Freepik https://freepik.com

Kling AI https://app.klingai.com
Hailuo https://hailuoai.video
Runway ML https://runwayml.com
SORA https://sora.chatgpt.com
Higgsfield https://higgsfield.ai
LumaLabs https://lumalabs.ai

ElevenLabs https://try.elevenlabs...

Hedra https://hedra.com
HeyGen https://heygen.com

SUNO https://suno.com
UDIO https://udio.com

React 17과 TypeScript 환경에서 클래스 컴포넌트를 사용하고, 입력 필드가 3개일 때:
1번 입력에서 Enter → 2번으로 포커스 이동
2번 입력에서 Enter → 3번으로 포커스 이동
3번 입력에서 Enter → 조회 함수 호출
하는 예제

import React, { Component, createRef } from 'react';

interface State {
condition1: string;
condition2: string;
condition3: string;
}

class SearchForm extends Component<{}, State> {
input1Ref = createRef();
input2Ref = createRef();
input3Ref = createRef();

state: State = {

condition1: '',
condition2: '',
condition3: '',

};

handleKeyDown = (e: React.KeyboardEvent, fieldIndex: number) => {

if (e.key === 'Enter') {
  e.preventDefault();

  switch (fieldIndex) {
    case 1:
      this.input2Ref.current?.focus();
      break;
    case 2:
      this.input3Ref.current?.focus();
      break;
    case 3:
      this.handleSearch();
      break;
    default:
      break;
  }
}

};

handleChange = (e: React.ChangeEvent) => {

const { name, value } = e.target;
this.setState({ [name]: value } as Pick<State, keyof State>);

};

handleSearch = () => {

const { condition1, condition2, condition3 } = this.state;
console.log('검색 조건:', condition1, condition2, condition3);
// 실제 검색 함수 로직 여기에 작성
alert(`조회 호출: ${condition1}, ${condition2}, ${condition3}`);

};

render() {

const { condition1, condition2, condition3 } = this.state;

return (
  <form>
    <input
      type="text"
      name="condition1"
      value={condition1}
      onChange={this.handleChange}
      onKeyDown={(e) => this.handleKeyDown(e, 1)}
      ref={this.input1Ref}
      placeholder="조건 1"
    />
    <br />
    <input
      type="text"
      name="condition2"
      value={condition2}
      onChange={this.handleChange}
      onKeyDown={(e) => this.handleKeyDown(e, 2)}
      ref={this.input2Ref}
      placeholder="조건 2"
    />
    <br />
    <input
      type="text"
      name="condition3"
      value={condition3}
      onChange={this.handleChange}
      onKeyDown={(e) => this.handleKeyDown(e, 3)}
      ref={this.input3Ref}
      placeholder="조건 3"
    />
    <br />
    <button type="button" onClick={this.handleSearch}>
      조회
    </button>
  </form>
);

}
}

export default SearchForm;

onKeyDown={(e) => handleKeyDown(e, 1)} 에서 오류가 발생하는 이유는 TypeScript가 e의 타입을 명확히 추론하지 못해 발생하는 타입 불일치입니다.

onKeyDown={(e: React.KeyboardEvent) => handleKeyDown(e, 1)}

import React, { Component } from 'react';
import { AgGridReact } from 'ag-grid-react';
import { ColDef } from 'ag-grid-community';
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';

const processTypeMap: Record<string, string> = {
PROCESS: 'Process',
VERIFY: 'Answer',
NOTFIY: 'Notify', // 'NOTIFY' 오타 여부 확인 필요
};

interface RowData {
id: number;
processType: string;
}

interface State {
columnDefs: ColDef[];
rowData: RowData[];
}

export class ProcessGrid extends Component<{}, State> {
constructor(props: {}) {

super(props);
this.state = {
  columnDefs: [
    { headerName: 'ID', field: 'id' },
    {
      headerName: '처리 유형',
      field: 'processType',
      valueFormatter: (params) => processTypeMap[params.value] || params.value,
    },
  ],
  rowData: [
    { id: 1, processType: 'PROCESS' },
    { id: 2, processType: 'VERIFY' },
    { id: 3, processType: 'NOTFIY' },
  ],
};

}

render() {

return (
  <div className="ag-theme-alpine" style={{ height: 300, width: '100%' }}>
    <AgGridReact
      columnDefs={this.state.columnDefs}
      rowData={this.state.rowData}
    />
  </div>
);

}
}

react, typescript에서 ag-grid field 중에 처리 유형이 있는데 항목은 PROCESS, VERIFY, NOTFIY 코드 인데 명칭은 PROCESS : 'Process', VERIFY: 'Answer', NOTFIY

const processTypeMap: Record<string, string> = {
PROCESS: 'Process',
VERIFY: 'Answer',
NOTFIY: 'Notify', // 오타가 아니라면 그대로 사용
};

import { ColDef } from 'ag-grid-community';

const columnDefs: ColDef[] = [
{

headerName: '처리 유형',
field: 'processType', // 해당 데이터 필드명
valueFormatter: (params) => processTypeMap[params.value] || params.value,

},
// 다른 컬럼들...
];

import React from 'react';
import { AgGridReact } from 'ag-grid-react';
import { ColDef } from 'ag-grid-community';
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';

const processTypeMap: Record<string, string> = {
PROCESS: 'Process',
VERIFY: 'Answer',
NOTFIY: 'Notify', // 확인 필요
};

const columnDefs: ColDef[] = [
{ headerName: 'ID', field: 'id' },
{

headerName: '처리 유형',
field: 'processType',
valueFormatter: (params) => processTypeMap[params.value] || params.value,

},
];

const rowData = [
{ id: 1, processType: 'PROCESS' },
{ id: 2, processType: 'VERIFY' },
{ id: 3, processType: 'NOTFIY' },
];

export const ProcessGrid: React.FC = () => {
return (

<div className="ag-theme-alpine" style={{ height: 300, width: '100%' }}>
  <AgGridReact rowData={rowData} columnDefs={columnDefs} />
</div>

);
};

public class ResultColumnChecker {

/**
 * 조회 결과에서 resultFlag와 resultMessage 컬럼이 SELECT 절에 포함되어 있는지 확인합니다.
 *
 * @param resultList iBatis 조회 결과 (List<LinkedHashMap<String, Object>>)
 * @return true: 두 컬럼 모두 존재, false: 둘 중 하나라도 없음
 */
public static boolean checkColumnsInSelect(List<LinkedHashMap<String, Object>> resultList) {
    if (resultList == null || resultList.isEmpty()) {
        return false;
    }

    // 첫 번째 row 기준으로 컬럼 존재 여부 판단
    LinkedHashMap<String, Object> firstRow = resultList.get(0);
    Set<String> columnNames = firstRow.keySet();

    return columnNames.contains("resultFlag") && columnNames.contains("resultMessage");
}

// 사용 예시
public static void main(String[] args) {
    List<LinkedHashMap<String, Object>> resultList = new ArrayList<>();

    LinkedHashMap<String, Object> row = new LinkedHashMap<>();
    row.put("id", 1);
    row.put("resultFlag", null);       // 값은 null이어도 컬럼이 존재하므로 OK
    row.put("resultMessage", "");      // 빈 문자열도 OK

    resultList.add(row);

    boolean hasColumns = checkColumnsInSelect(resultList);
    System.out.println("SELECT 절에 컬럼 존재 여부: " + hasColumns);  // true 출력
}

}