为了账号安全,请及时绑定邮箱和手机立即绑定

各位大神看看为啥会报错 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'girlinf0_.cup_size' in 'field list'

package com.springbootdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
   public static void main(String[] args)
   {
      SpringApplication.run(DemoApplication.class, args);
   }
}
package com.springbootdemo.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * Created by Administrator on 2017/6/29.
 */
@Entity
public class GirlInf {
    @Id
    @GeneratedValue
    private Integer id;
    private String name;
    private Integer age;
    private String cupSize;

    public GirlInf() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getCupSize() {
        return cupSize;
    }

    public void setCupSize(String cupSize) {
        this.cupSize = cupSize;
    }
}
package com.springbootdemo.service;

import com.springbootdemo.entity.GirlInf;
import org.springframework.data.jpa.repository.JpaRepository;

/**
 * Created by Administrator on 2017/6/30.
 */

public interface GirlRepository extends JpaRepository<GirlInf, Integer> {
}
package com.springbootdemo.controller;

import com.springbootdemo.entity.GirlInf;
import com.springbootdemo.service.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2017/6/29.
 */
@RestController
@RequestMapping("/hello")
public class helloController {
    @Autowired
    GirlRepository girlRepository;


    @GetMapping("/showGirls")
    public List<GirlInf> showGirls() {
        List<GirlInf> list = girlRepository.findAll();
        return list;
    }

    @PostMapping("/addGirl")
    public void AddGirl(@RequestParam Integer id, String name, Integer age, String cupSize) {
        GirlInf girlInf = new GirlInf();
        girlInf.setName(name);
        girlInf.setAge(age);
        girlInf.setCupSize(cupSize);
        if (id != null) {
            girlInf.setId(id);
            girlRepository.save(girlInf);
        } else {
            girlRepository.save(girlInf);
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.springbootdemo</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
server:
  port: 8081
  address: 127.0.0.1

spring.datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/bootdemo
    username: root

spring.data.jpa:
    hibernate:
      ddl-auto: create
      show-sql: true

http://img1.sycdn.imooc.com//5959b3cd0001c4bf12500427.jpg

正在回答

1 回答

yml跟我的不是很一样:

server:
  port: 80
  context-path: /
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.25.3:3306/girl
    username: root
    password: zzhy
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true


0 回复 有任何疑惑可以回复我~
#1

隽永I 提问者

你这运行不会报错吗? jpa 应该是spring.data 下的啊, 我感觉你这样写会报错
2017-07-05 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
2小时学会Spring Boot
  • 参与学习       151599    人
  • 解答问题       1079    个

Spring Boot入门视频教程,你将学会使用Spring Boot快速构建应用程序

进入课程

各位大神看看为啥会报错 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'girlinf0_.cup_size' in 'field list'

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信