我想優(yōu)化到數(shù)據(jù)庫行應(yīng)用程序設(shè)置。像這樣的東西10 - enabled option 1;12 - enabled option 2;13 - enabled option 3;并將整個數(shù)字作為 1073741823 存儲到數(shù)據(jù)庫中。我試圖實現(xiàn)這一點:公共無效測試(){ // Let's say you get a String representing your option from your database String optionFromDB= "132456"; // optionFromDB is a number like "132456" // We transform it to bigDecimal: BigDecimal myOptions=new BigDecimal(optionFromDB); // Then we can use it. // enable the option X (X is a number) myOptions.setBit(2); // Disable option X myOptions.clearBit(2); // Save the options to the db: String newValToSave=myOptions.toString(); // do something if option x enable: if (myOptions.testBit(123)){ System.out.println("test"); } }我該如何正確實施?
添加回答
舉報
0/150
提交
取消