今天把工程调出来,发现又有问题:
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