问题描述
这是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 (将#修改为@)