Springboot连MySql demo

这篇博客记录了作者在使用Springboot连接MySQL数据库时遇到的问题及解决方案,包括请求方法错误、HttpMessageNotReadableException、数据库连接异常、时间区问题以及JPA依赖问题。通过调试和查阅资料,作者成功解决了这些问题,完成了第一个Springboot + MySQL项目。
摘要由CSDN通过智能技术生成

今天把工程调出来,发现又有问题:

1. 之前一直可以运行,今天突然报错:

Request method 'GET' not supported

@PostMapping要改成@RequestMapping("/input") 

2. springframework.http.converter.HttpMessageNotReadableException: Required request body is missing

https://blog.csdn.net/IBLiplus/article/details/86491530

3. create connection SQLException, url: jdbc:mysql://localhost:3306/mydb, errorCode 0, state 01S00

java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. 

将spring.datasource.url后加入?serverTimezone=UTC即可解决

  C:\work\code\hello\config\database.properties 
  C:\work\code\hello\src\main\resources\database.properties 
 

4.### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: Column 'name' specified twice

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: Column 'name' specified twice

@Table(name="t_user")
public class UserEntity {


    @Column(name = "name") //删去这行, 重复定义
    private String id;

    private String name;

    private  String data;

}

运行了一下,能把数据配进表格了:

5.想要整理代码时,发现总会有

Error:(8, 25) java: 程序包javax.persistence不存在,maven reimport一下就好

https://blog.csdn.net/Luojun13Class/article/details/81483151 

 

至此,我的第一个JAVA项目(Springboot + Mysql)写好啦~

陆陆续续花了挺久了,不过终于是把基本的后端服务+写到数据库搞了一把~

接下来要搞怎么操作数据库啦 撒花*★,°*:.☆( ̄▽ ̄)/$:*.°★* 。

HelloController

package com.jiayuezh.hello.controller;



import com.jiayuezh.hello.dto.UserDto;
import com.jiayuezh.hello.dto.ResponseDto;

import com.jiayuezh.hello.service.HelloService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HelloController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    private HelloService service;

    private RestTemplate template = new RestTemplate();

    @RequestMapping("/hi")
    private String say(){
        LOGGER.info("sayhi start.");
        return "piu piu piu";
    }

    @RequestMapping("/input")
    public String inputId(@RequestParam("id") String id){
        LOGGER.info("store start.");
        return "POST id:" + id;
    }

    @RequestMapping("/sto
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值