2019-01-03凌晨日記,早晨解決spring boot幾個(gè)問(wèn)題

準(zhǔn)備重拾編程。

從java入手,準(zhǔn)備達(dá)到快速搭建web站、開發(fā)Android應(yīng)用的水平。

第一階段:看視頻教程。

因?yàn)楣ぷ鬏^忙,只能走馬觀花地看完了馬士兵的課程,也看了基礎(chǔ)的Android教程。該階段勉強(qiáng)算完成了。

第二階段:看書、看文檔,做簡(jiǎn)單項(xiàng)目。

準(zhǔn)備Spring boot著手,搭建個(gè)簡(jiǎn)單blog。

第三階段:開發(fā)Android APP。

書已經(jīng)買好了,《深入理解Android:WebKit卷》準(zhǔn)備對(duì)著敲一個(gè)瀏覽器出來(lái)。


ps,tip下最近搭建Spring boot 操作數(shù)據(jù)庫(kù)遇到的問(wèn)題

1、由于使用visual studio code開發(fā),不熟悉vs code 開發(fā)spring boot,以至于spring boot新建項(xiàng)目后,缺少各種依賴報(bào)錯(cuò)。

2、添加了依賴,還有配置不對(duì)的。真心煩!

錯(cuò)誤:DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

解決:application.properties增加一行配置

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

3、提示數(shù)據(jù)庫(kù)連接錯(cuò)誤,時(shí)區(qū)不被識(shí)別

錯(cuò)誤:com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '...亂碼' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

解決:application.properties的數(shù)據(jù)庫(kù)URL后設(shè)置下時(shí)區(qū)params,serverTimezone=UTC

spring.datasource.url=jdbc:mysql://localhost:3306/myblog?serverTimezone=UTC

4、spring boot select成功,insert無(wú)效??吹墓俜轿臋n,一步一步敲的代碼!看來(lái)我的理解能力還是差啊,要么是因?yàn)闆](méi)有spring 基礎(chǔ)直接看spring boot了??

package com.test.myblog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path="/")
public class MainController{
    @Autowired
    private UserRepository userRepository;
    
    @GetMapping(path="/adduser")
    public @ResponseBody String addNewUser(@RequestParam String name,@RequestParam String pwd,@RequestParam Integer permission){
        //創(chuàng)建新的Entity類對(duì)象User
        User newUser=new User();
        newUser.setName(name);
        newUser.setPwd(pwd);
        newUser.setPermission(permission);
        //繼承CrudRepository的接口保存該對(duì)象,官方文檔無(wú)該步驟,是我瞎了么?
        userRepository.save(newUser);
        return "Saved Success!";
    }

    @GetMapping(path="/alluser")
    public @ResponseBody Iterable<User> getAllUser(){
        return userRepository.findAll();
    }
}

5、學(xué)習(xí)了簡(jiǎn)書如何添加代碼塊,風(fēng)中凌亂
,不過(guò)我喜歡。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容