小编yel*_*g99的帖子

Java枚举类可以设置默认值吗

我的代码是

\n\n
public enum PartsOfSpeech2 {\n\n    n("noun"),\n    wp("\xe6\xa0\x87\xe7\x82\xb9"),\n    a("adjective"),\n    d("conjunction"),\n    ...;\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想要哪个

\n\n
public enum PartsOfSpeech2 {\n\n    n("noun"),\n    wp("\xe6\xa0\x87\xe7\x82\xb9"),\n    a("adjective"),\n    d("conjunction"),\n    %("noun");\n
Run Code Online (Sandbox Code Playgroud)\n\n

我可以有一个不在其中的默认值\xef\xbc\x8c 可以将其设置为默认值\xef\xbc\x9f\n因为我有一个类型是“%”,但枚举不支持%,所以我想要一个默认值来解决它

\n

java enums

1
推荐指数
1
解决办法
5万
查看次数

如何使用MockMVC测试使用org.apache.commons.fileupload的控制器?

我的Controller使用“org.apache.commons.fileupload”实现了文件上传。看见:

 @PostMapping("/upload")
    public String upload2(HttpServletRequest request) throws Exception {

        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter = upload.getItemIterator(request);
        boolean uploaded = false;

        while (iter.hasNext() && !uploaded) {
            FileItemStream item = iter.next();
            if (item.isFormField()) {
                item.openStream().close();
            } else {
                String fieldName = item.getFieldName();
                if (!"file".equals(fieldName)) {
                    item.openStream().close();
                } else {

                    InputStream stream = item.openStream();
                    // dosomething here.
                    uploaded = true;
                }
            }
        }
            if (uploaded) {
                return "ok";
            } else {
                throw new BaseResponseException(HttpStatus.BAD_REQUEST, "400", "no file field or data file …
Run Code Online (Sandbox Code Playgroud)

file-upload spring-boot mockmvc

0
推荐指数
1
解决办法
498
查看次数

标签 统计

enums ×1

file-upload ×1

java ×1

mockmvc ×1

spring-boot ×1