2016-03-01 27 views
0

在這裏,我爲catname得到值從參數作爲movie但在它的數據庫具有對應的值作爲1,對相同音樂 - >圖2,遊戲 - > 3 ....根據爪哇彈簧數據庫轉換參數

 "WHERE (\n" + 
          "\t\t(`Post`.`status` = 1)\n" + 

          "\t\tAND (`Post`.`postto_id` =\"+catname+\" \")\n" + 
          "\t\t)" + 
          "ORDER BY `Post`.`id` desc LIMIT 5", new CrelistMapper()); 
       } catch (Exception e) { 
        throw e; 
       } 
      } 

private class CrelistMapper implements ResultSetExtractor<List<Creativity>> { 
     public List<Creativity> extractData(ResultSet resultSet) throws SQLException { 


      List<Creativity> crelistList = new ArrayList<Creativity>(); 

      while (resultSet.next()) { 


       Creativity userObject = new Creativity(resultSet.getString("**postto_id**"), 

在這裏我得到了價值作爲電影在「postto_id」我怎麼能將它轉換成1而不是參數電影?

回答

0

我相信你正在尋找從Integer類中解析int。

import java.lang.Integer; 

public class test{ 
    public static void main(String[] args){ 
     String stringId = "1"; 

     int intFromString = Integer.parseInt(stringId); 

     System.out.println(intFromString); 
    } 
} 

here一個版本的重載方法,以滿足你的目的