如何解决数据被插入/从“ spring_bootcrud”表中获取,而不是从Spring Boot应用程序中的实际表“ DbTable”中获取
这是POJO类,其中我在注释内提到了表名:
@Entity
@Table(name = "DbTable")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SimplePOJO {
@Id
@GeneratedValue
private int id;
private String name;
}
这是控制器类:
@RestController
@RequestMapping("/Myapp")
public class SimpleController {
@Autowired
SimpleDao dao; \\ public interface SimpleDao extends CrudRepository<SimplePOJO,Integer>{}
@PostMapping("/Create")
public String enterData(@RequestBody List<SimplePOJO> spojo){
dao.saveAll(spojo);
return "Number of records entered: "+ spojo.size();
}
@GetMapping("/Read")
public List<SimplePOJO> getData() {
return (List<SimplePOJO>) dao.findAll();
}
}
这是application.properties文件:
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.sqlServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=TestCRUD
spring.datasource.username=sa
spring.datasource.password=mssqlpwD
server.port=8080
spring.jpa.show-sql = true
spring.jpa.hibernate.dialect=org.hibernate.dialect.sqlServer2012Dialect
spring.jpa.hibernate.ddl-auto = validate
现在,运行该应用程序后,我使用邮递员应用程序访问该URL:
POST request> https://localhost:8080/Myapp/Create
Body:
[
{
"name":"fst nme"
},{
"name":"last nme"
}
]
Response 200: Number of records entered: 2
下面是Eclipse控制台日志:
Hibernate: select next value for hibernate_sequence
Hibernate: select next value for hibernate_sequence
Hibernate: insert into spring_bootcrud (name,id) values (?,?)
Hibernate: insert into spring_bootcrud (name,?)
Hibernate: select next value for hibernate_sequence
Hibernate: select next value for hibernate_sequence
Hibernate: insert into spring_bootcrud (name,?)
现在,在MSsql数据库“ TestCRUD”内部,正在创建一个新表“ spring_bootcrud”,并且名称列已由“ NULL”填充。我不知道该“ spring_bootcrud”表是如何创建的。请帮忙!我是Spring Boot的初学者。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。