eclipse如何关闭java代码中某些部分/片段代码不被格式化
编程教程
>
Java
(2957)
2024-11-26 14:39:04
eclipse如何关闭java代码中某些部分/片段代码不被格式化,eclipse,代码部分不被格式化,
How to turn off the Eclipse code formatter for certain sections of Java code?
1.设置eclipse开启Off/On tags
依次点击菜单
preferences->Java->Code Style->Formatter
点击Edit
找到tag,点击enable Off/On tags
在不想被格式化的代码之间添加以下注释标签即可
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.cqax.axschoolweb2.common.pojo.Result;
/**
* 验证码公用处理类
*
* @author xq
*
*/
@RestController
public class ValidationCodeController {
//@formatter:off
/**
*
* @api {get} /apis/validation/getcode.json 获取验证码
*
* @apiName GetValidateCode
*
* @apiGroup Validation
*
* @apiParam {String} [timeStamp] 时间戳
*
* @apiSuccessExample {String} 返回值:
* {
"id": "1be34f4a324c4123b0325ecf0593d70e",
"data": {
"image": "iVBORwCCAAAAAAAAAAAAAAAAA=="
},
"code": "00000",
"dateTime": "2017-05-23 14:00:23",
"msg": null
}
*
*/
//@formatter:on
@GetMapping("/apis/validation/getcode.json")
public Result getCode() {
try {
InputStream is = new FileInputStream(new File("e:/2.png"));
ByteArrayOutputStream bao = new ByteArrayOutputStream();
byte[] cache = new byte[4096];
while (is.read(cache) != -1) {
bao.write(cache);
}
String rs = Base64Utils.encodeToString(bao.toByteArray());
JSONObject obj = new JSONObject();
obj.put("image", rs);
is.close();
return Result.success(obj);
} catch (Exception e) {
return Result.fail("eeeee", "错误,异常," + e.getMessage());
}
}
//@formatter:off
/**
* @api {get} /apis/validation/compare.json 对比验证码
*
* @apiName CompareValidateCode
*
* @apiGroup Validation
*
* @apiParam {String} vcode 验证码
*
* @apiSuccessExample {json} 返回值:
* {
"id":"f47611a1a7ee4d4c8c0420a4f7e4b228",
"data":{
"result":true
},
"code":"00000",
"dateTime":"2017-05-23 14:41:36",
"msg":null
}
*/
//@formatter:on
@GetMapping("/apis/validation/compare.json")
public Result compare(String vcode) {
JSONObject obj = new JSONObject();
obj.put("result", true);// 对比结果
return Result.success(obj);
}
public Result getPhoneCode(){
JSONObject obj=new JSONObject();
return null;
}
}
http://blog.xqlee.com/article/172.html