1、json格式形如 

[
    {
        "word": "嗄",
        "oldword": "嗄",
        "strokes": "13",
        "pinyin": "á",
        "radicals": "口",
        "explanation": "嗄〈叹〉\n\n 同啊",
        "more": "嗄 ga、a 部首 口 部首笔画 03 总笔画 13"  
    },
    {
        "word": "吖",
        "oldword": "吖",
        "strokes": "6",
        "pinyin": "ā",
        "radicals": "口",
        "explanation": "喊叫天~地。\n 形容喊叫的声音高声叫~~。",
        "more": "吖 a 部首 口 部首笔画 03 总笔画 06  吖2\nyā\n喊,呼喊" 
    }
]

2、创建对应实体类

public class Chinese {
    private Integer id;

    private String word;

    private String oldword;

    private String strokes;

    private String pinyin;

    private String radicals;

    private String explanation;

    private String more;

   //getter、setter方法省略
}

3、Controller方法

    @GetMapping("/initChinese")
    public String initChinese(){
        try {
            String filePathh = "D:/word.json";//json文件地址
            InputStream inputStream = new FileInputStream(filePathh);
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line=br.readLine())!=null){
                sb.append(line);
            }
            List<Chinese> poets = JSON.parseArray(sb.toString(), Chinese.class);
            for (Chinese poet : poets) {
                chineseMapper.insert(poet);//调用mapper接口
            }

        } catch (IOException e) {
            e.printStackTrace();
        } 
        return "success";
    }

 

 

GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 4 个月前
8c391e04 6 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐