我想优化到数据库行应用程序设置。像这样的东西10 - enabled option 1;12 - enabled option 2;13 - enabled option 3;并将整个数字作为 1073741823 存储到数据库中。我试图实现这一点:公共无效测试(){ // 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
提交
取消