当前位置: 首页 > 后端技术 > Java

boot开发踩过的坑

时间:2023-04-01 19:50:23 Java

椤圭洰甯哥敤渚濊禆<dependencies> <!--Springboot鍚姩鍖?-> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!--Springboot 娴嬭瘯鍚姩鍖?-> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!--Springboot Web鏈嶅姟鍖?-> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <scope>compile</scope> </dependency> <!--鍖呯背璞?MybatisPlus鍚姩鍖?-> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.2</version> </dependency> <!--lombok javabean鏍锋澘鍖?-> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.20</version> </dependency> <!--fast json鏁版嵁澶勭悊鍖?-> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.76</version> </dependency> <!--甯哥敤宸ュ叿绫诲寘--> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <!--MySQL鏁版嵁搴撹繛鎺ュ寘--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--寰烽瞾浼婃暟鎹簱杩炴帴姹?-> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.23</version> </dependency> <!-- 閭欢鏈嶅姟 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <!-- Thymeleaf 妯$増锛岀敤浜庡彂閫佹ā鐗堥偖浠?--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--Spring Data Redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency></dependencies>杩愯鍓嶇鏈嶅姟1.鍦ㄥ墠绔枃浠剁洰褰曚笅杩愯鍛戒护绗﹁绐楀彛2.浣跨敤node鍛戒护杩愯涓诲嚱鏁癹s杩愯鍓嶇鏈嶅姟node main.js甯歌鎶ラ敊瑙e喅Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'http-proxy-middleware' imported from D:\study4\test\client\main.js浠栬涓嶈兘鎵惧埌鍖?http-proxy-middleware' 閭f垜浠氨瑕佸幓瀹夎杩欎釜鍖卬pm install http-proxy-middleware --save鏁版嵁琛ㄧ殑鍚嶅瓧瑕佸拰pojo鍚嶆崲绛塎ybatisPlus Page鍔熻兘鏃犳硶浣跨敤鍘熷洜鏄垎椤垫彃浠堕渶瑕佹墜鍔ㄩ厤缃? //鍒嗛〉鎻掍欢 @Bean public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); }/** * 閰嶇疆MP鐨勫垎椤垫彃浠?*/@Configurationpublic class MybatisPlusConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); return mybatisPlusInterceptor; }}LocalTime鎶ラ敊Usage of API documented as @since 1.8+妫€鏌ヤ娇鐢ㄧ殑java鐗堟湰 杩樻湁Module鐨勭紪璇戠増鏈珻ompilation failed: internal java compiler error 瑙e喅鍔炴硶_ruoxiyun鐨勫崥瀹?CSDN鍗氬_internal java errorhttps://blog.csdn.net/ruoxiyu...SpringbootTest鏃跺嚭鐜扮殑闂鎴戝垱寤篵oot椤圭洰鐨勬椂鍊?浣跨敤idea鎻愪緵鐨刴aven鐨勯樋甯曞蹇€熸ā鏉垮垱寤虹殑 瀵艰嚧鐢ㄧ殑鏄疛unit4鐨凾est 杩欎袱涓猅est浼氫骇鐢熷啿绐?涓€鐩寸垎绌烘寚閽堝紓甯歌В鍐虫柟娉曞氨鏄妸JUnit4鐨勬祴璇曢兘骞叉帀 鍏ㄩ儴鎹㈡垚boottestMybatisPlus鑷甫闆姳绠楁硶mybatis-plus闆姳绠楁硶鐢熸垚Id浣跨敤璇﹁В_鏂楄€卂2013鐨勫崥瀹?CSDN鍗氬_mybatis plus 闆姳idhttps://blog.csdn.net/w101407...MybatisPlus鑷姩濉厖鏃堕棿鑷姩濉厖鍔熻兘 | MyBatis-Plushttps://baomidou.com/pages/4c...Boot褰╄壊鏃ュ織spring: output: ansi: enabled: always閫氱敤杩斿洖绫籭mport lombok.Data;import java.util.HashMap;import java.util.Map;/** * 閫氱敤杩斿洖缁撴灉锛屾湇鍔$鍝嶅簲鐨勬暟鎹渶缁堥兘浼氬皝瑁呮垚姝ゅ璞?* @param <T> */@Datapublic class R<T> { private Integer code; //缂栫爜锛?鎴愬姛锛?鍜屽叾瀹冩暟瀛椾负澶辫触 private String msg; //閿欒淇℃伅 private T data; //鏁版嵁 private Map map = new HashMap(); //鍔ㄦ€佹暟鎹? public static <T> R<T> success(T object) { R<T> r = new R<T>(); r.data = object; r.code = 1; return r; } public static <T> R<T> error(String msg) { R r = new R(); r.msg = msg; r.code = 0; return r; } public R<T> add(String key, Object value) { this.map.put(key, value); return this; }}鐘舵€佺粨鏋滄灇涓剧被/** * 缁撴灉绫绘灇涓?*/@Getterpublic enum ResultCodeEnum { SUCCESS(true,20000,"鎴愬姛"), UNKNOWN_ERROR(false,20001,"鏈煡閿欒"), PARAM_ERROR(false,20002,"鍙傛暟閿欒"), NULL_POINT(false, 20003, "绌烘寚閽堝紓甯?quot;), INDEX_OUT_OF_BOUNDS(false, 20004, "涓嬫爣瓒婄晫寮傚父"), ; // 鍝嶅簲鏄惁鎴愬姛 private Boolean success; // 鍝嶅簲鐘舵€佺爜 private Integer code; // 鍝嶅簲淇℃伅 private String message; ResultCodeEnum(boolean success, Integer code, String message) { this.success = success; this.code = code; this.message = message; }}jwt璐熻浇鍐呭 registered claims 宸叉敞鍐岀殑澹版槑杩欎簺鏄竴缁勯瀹氫箟鐨勫0鏄庯紝瀹冧滑涓嶆槸寮哄埗鐨勶紝鑰屾槸鎺ㄨ崘鐨勶紝浠ユ彁渚涗竴缁勬湁鐢ㄧ殑銆佸彲浜掓搷浣滅殑澹版槑銆傛瘮濡傦細iss锛堝彂琛岃€咃級銆乪xp锛堝埌鏈熸椂闂达級銆乻ub锛堜富棰橈級銆乤ud锛堝彈浼楋級鍜屽叾浠栥€係pring Boot璇诲彇Yml閰嶇疆鏂囦欢鐨?绉嶆柟娉? @Value("${user.userName}") private String name;@Data@Component@ConfigurationProperties(prefix = "user")public class Users { private String userName; private Integer age; private String[] tels; private Map<String, Integer> score; private List<Teacher> oldTeachers; private List<Teacher> newTeachers;}YamlMapFactoryBean閫氳繃杩欎釜factoryBean鍙互鐩存帴杩斿洖涓€涓狹ap锛岃€屼笉闇€瑕佷娇鐢↗avaBean鍘绘帴鏀秠ml璇诲彇鐨勫€紁ublic static void main(String[] arg0){ YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean(); //鍙互鍔犺浇澶氫釜yml鏂囦欢 yamlMapFactoryBean.setResources(new ClassPathResource("application.yml")); //閫氳繃getObject()鏂规硶鑾峰彇Map瀵硅薄 Map<String, Object> map = yamlMapFactoryBean.getObject(); System.out.println(map); map.keySet().forEach(item -> { //鍙互灏唌ap涓殑鍊煎己杞负LinkedHashMap瀵硅薄 LinkedHashMap<String, Object> linkedHashMap = (LinkedHashMap<String, Object>) (map.get(item)); System.out.println(linkedHashMap.get("tels")); });http://t.csdn.cn/XQR2Sspring boot:浠巠aml閰嶇疆鏂囦欢涓鍙栨暟鎹殑鍥涚鏂瑰紡(spring boot 2.4.3) - 鍒樺畯缂旂殑鏋舵瀯妫灄 - 鍗氬鍥環ttps://www.cnblogs.com/archi...@Resource鍜孈Autowired鐨勫尯鍒獲Resource榛樿鎸夊悕绉版柟寮忚繘琛宐ean鍖归厤锛孈Autowired榛樿鎸夌被鍨嬫柟寮忚繘琛宐ean鍖归厤銆係pring Boot鏁村悎JWT鐨勫疄鐜版楠ttps://www.jb51.net/article/...http://t.csdn.cn/tMztthttp://t.csdn.cn/45u1R鑷畾涔夊紓甯竝ublic class MyException extends Exception { public MyException() { super(); } public MyException(String str) { super(str); }}throw new MyException("鑷畾涔夐敊璇?quot;)Java鑷畾涔夊紓甯竓ttp://c.biancheng.net/view/1...YApi閮ㄧ讲Windows 鐜涓嬪畨瑁?Yapi 鏁欑▼_ANTeam鐨勫崥瀹?CSDN鍗氬_yapi瀹夎閰嶇疆windowshttps://blog.csdn.net/ANTeam/...Windows鐜閮ㄧ讲YApi鏁欑▼YApi浠嬬粛YApi-楂樻晥銆佹槗鐢ㄣ€佸姛鑳藉己澶х殑鍙鍖栨帴鍙g鐞嗗钩鍙癶ttp://yapi.dapengjiaoyu.com/瑙e喅npm ERR! Cannot read properties of null (reading 鈥榩ickAlgorithm鈥?鎶ラ敊闂_鍗楅鍚逛簯鐨勫崥瀹?CSDN鍗氬https://blog.csdn.net/qq_4375...git clone https://gitee.com/mirrors/YApi vendors鏈湴绾跨▼宸ュ叿绫?** * 鍩轰簬ThreadLocal灏佽宸ュ叿绫伙紝鐢ㄦ埛淇濆瓨鍜岃幏鍙栧綋鍓嶇櫥褰曠敤鎴穒d */public class BaseContext { //瀹氫箟骞惰祴鍊间竴涓湰鍦扮嚎绋嬪壇鏈瑃hreadLocal private static ThreadLocal<Long> threadLocal = new ThreadLocal<>(); /**璁惧畾setCurrentId鏂规硶鐢ㄦ潵瀛樺叆id鐨勫€?/ public static void setCurrentId(Long id){ threadLocal.set(id); } /**璁惧畾getCurrentId鏂规硶鐢ㄦ潵鑾峰彇id鐨勫€?/ public static Long getCurrentId(){ return threadLocal.get(); }}鏂版椂闂碅PILocalDate 锛?鍙惈骞存湀鏃ョ殑鏃ユ湡瀵硅薄LocalTime 锛氬彧鍚椂鍒嗙鐨勬椂闂村璞ocalDateTime 锛?鍚屾椂鍚湁骞存湀鏃ユ椂鍒嗙鐨勬棩鏈熷璞ocalDateTime鐢ㄦ硶_ChampionDragon鐨勫崥瀹?CSDN鍗氬https://blog.csdn.net/xxdw199...鑾峰緱java椤圭洰璺緞Java鑾峰彇椤圭洰璺緞鐨勫绉嶆柟寮廮java_鑴氭湰涔嬪https://www.jb51.net/article/...javapackager -deploy -native image -outdir outdir -outfile outfiles -srcfiles I_Love_You.jar -appclass frame.TestMain -name biaobai520javapackager -deploy -native image -outdir outdir -outfile outfiles -srcfiles I_Love_You.jar -appclass frame.TestMain -name biaobai520vue-simple-uploader浣跨敤vue-simple-uploader涓婁紶鏂囦欢鍜屾枃浠跺す_Hellowebahttps://www.helloweba.net/jav...鍩轰簬vue-simple-uploader灏佽鏂囦欢鍒嗙墖涓婁紶銆佺浼犲強鏂偣缁紶鐨勫叏灞€涓婁紶鎻掍欢 - 澶忓ぇ甯?\https://www.cnblogs.com/xiahj...vue-simple-uploader缁勪欢鐨勪娇鐢ㄦ劅鍙?- 绠€涔ttps://www.jianshu.com/p/da8...SpringBoot+Vue.js鍓嶅悗绔垎绂诲疄鐜板ぇ鏂囦欢鍒嗗潡涓婁紶https://github.com/LuoLiangDS...SpringBoot+Vue.js鍓嶅悗绔垎绂诲疄鐜板ぇ鏂囦欢鍒嗗潡涓婁紶 | Fantasyhttps://luoliangdsga.github.i...鍩轰簬SpringBoot鍜學ebUploader瀹炵幇澶ф枃浠跺垎鍧椾笂浼?鏂偣缁紶.绉掍紶-闃块噷浜戝紑鍙戣€呯ぞ鍖篽ttps://developer.aliyun.com/...hacker-and-painter/springboot-file-uploader: 馃梻锔?SpringBoot瀹炵幇鏂囦欢涓婁紶绯荤粺https://github.com/hacker-and...