πŸ“˜ Programming/❌ ERR

java.lang.NumberFormatException: For input string μ—λŸ¬ ν•΄κ²° 방법

ν•œμ½”λ”© 2023. 11. 10. 13:10
728x90
728x90

상황

Spring + Mybatis ν™˜κ²½μ—μ„œ λ°œμƒν•˜λŠ” μ—λŸ¬

λ¬Έμžμ—΄μ„ λΉ„κ΅ν•˜λŠ” λΆ€λΆ„μ—μ„œ μ—λŸ¬κ°€ λ°œμƒν•˜κ³  있음

λ¬Έμžμ—΄λΌλ¦¬μ˜ λΉ„κ΅μž„μ—λ„ NFEκ°€ λ°œμƒν•˜κ³  있음


원인

Mybatisμ—μ„œ <if>, <when> νƒœκ·Έμ˜ test μ†μ„±μ—μ„œ λ¬Έμžμ—΄μ„ λΉ„κ΅ν•˜λŠ” κ³Όμ •μ—μ„œ λ°œμƒν•˜λŠ” μ—λŸ¬μž…λ‹ˆλ‹€.

<if test="storeCd != null and storeCd != '0'">

 

μž…λ ₯된 값을 λ¬Έμžμ—΄κ³Ό 비ꡐ할 λ•Œ storeCd != '0'μ—μ„œ storeCdλŠ” String인데 '0'은 char둜 μΈμ‹ν•΄μ„œ 같은 μžλ£Œν˜•μ΄ μ•„λ‹ˆλΌμ„œ λ°œμƒν•˜λŠ” μ—λŸ¬μž…λ‹ˆλ‹€.

 

Mybatis λ¬Έμ œλŠ” μ•„λ‹ˆκ³  OGNL(Object Graph Navigation Language)의 λ¬Έμ œμž…λ‹ˆλ‹€. OGNL μΈν„°ν”„λ¦¬ν„°μ—μ„œλŠ” λ”°μ˜΄ν‘œμ™€ 문자의 κ°―μˆ˜μ— 따라 μΈμ‹ν•˜λŠ” μžλ£Œν˜•μ΄ μ•„λž˜μ™€ 같이 λ‹€λ¦…λ‹ˆλ‹€.

  • '1', 'A' → char ν˜•
  • 'AAA', "A" → String

ν•΄κ²°

1. μŒλ”°μ˜΄ν‘œμ™€ ν™‘λ”°μ˜΄ν‘œμ˜ μœ„μΉ˜λ₯Ό λ³€κ²½

<if test='storeCd != null and storeCd != "0"'>

 

2. μŒλ”°μ˜΄ν‘œλ₯Ό HTML μ½”λ“œλ‘œ λ³€κ²½

<if test=”storeCd != null and storeCd != "0"”>

 

3. toString() ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•΄ String ν˜•μœΌλ‘œ λ³€ν™˜

<if test="storeCd != null and storeCd != '0'.toString()">

 

728x90
λ°˜μ‘ν˜•