2019-06-12

Spring Boot with Maven

  • Getting Started
    Guides很有用:

https://spring.io/guides#gs
  • 使用了JDBC的项目,必须编辑src/main/application.properties,加入数据库配置,否则会因为test failed而无法构建项目,举例:

spring.datasource.url=jdbc:mysql://localhost/database





spring.datasource.username=username





spring.datasource.password=password





spring.datasource.driver-class-name=com.mysql.jdbc.Driver





  • 想要直接输出内容而不使用模板,可以在控制器中使用@RestController,或在@Controller之后,加入@ResponseBody,当使用@Controller时,返回的字符串为src/main/resources/templates下的模板文件名,不要带扩展名
  • 默认情况下,不定义自己的ViewResolver时,如果路由(如/index)和模板文件重名(如index.html),会无法正确显示模板内容 ,并产生循环引用view的异常,最简单的解决方式是二者不要重名
  • 调式&运行:mvn spring-boot:run
  • 打包项目为jar::mvn package
  • 安装项目依赖:mvn install

没有评论:

发表评论