当前位置:首页>开发>正文

springboot怎么学比较快 spring boot怎么启动的

2023-05-18 01:41:26 互联网 未知 开发

 springboot怎么学比较快 spring boot怎么启动的

springboot怎么学比较快

先学spring framework吧,把spring 的原理,配置那些东西学会了,理解了再去用spring boot 很容易上手,其实spring boot 就是把很多spring 的配置都简化了,很多东西在properties配置文件里写了之后,spring boot 就会自动帮你把相关的bean配置上,例如你在配置文件里把数据库连接的相关地址,用户,密码配好后,spring boot就会自动帮你把数据库连接池配置好,当然你也可以不用他提供的自动配置功能,完全可以按照你的需求去集成其他的例如dbcp,c2po,driud的其他的数据库连接池。。其他的类似的配置还很多。自己多看看spring boot autoconfigration 的源码就知道了

spring boot怎么启动的

假设你的应用是 Abc,会有一个AbcApplication.java
1、类里面有一个main方法,
2、类名上使用@SpringBootApplication
然后运行 run 你的项目即可!

如何使用springboot快速构建后台

要Spring
Boot进行功能开发,需要使用Gradle或者Maven作为构建工具。在本例中,我们会使用Eclipse和Maven插件进行开发。要使用Spring
Boot,首先创建一个Maven工程,并修改Maven主要的配置文件pom.xml

如何用springboot连接数据库

新建Spring Boot项目,依赖选择JPA(spring-boot-starter-data-jpa)和Web(spring-bootstarter-web)。

配置基本属性 在application.properties里配置数据源和jpa的相关属性
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.username=root
spring.datasource.password=12345spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent_output=true

定义映射实体类

定义Controller类
@RestControllerpublic class PersonCtroller {
@Autowired PersonServer personServer
@RequestMapping("/rollback")
public Person rollback(Person person){
return personServer.savePersonWithRollBack(person)
}
@RequestMapping("/norollback")
public Person noRollback(Person person){
return personServer.savePersonWithOutRollBack(person)
}
}
定义数据访问层
public interface PersonRepository extends JpaRepository {}
定义Server层
@Servicepublic class PersonServerImp implements PersonServer {
@Autowired
PersonRepository personRepository
@Transactional(rollbackFor = {IllegalArgumentException.class})
@Override
public Person savePersonWithRollBack(Person person) {
Person p = personRepository.save(person)
if (p.getName().equals("xxx")){
throw new IllegalArgumentException("用户已存在,数据会回滚")
}
return p
}
}
浏览器访问

spring boot在eclipse中怎么用

1.Eclipse中安装STS插件:
Help -> Eclipse Marketplace…
Search或选择“Popular”标签,选择Spring Tool Suite (STS) for Eclipse插件,安装:
2.New -> Project…

找到Spring目录,选择Spring Starter Project,Next

3、填写跟项目相关的各种信息,然后Next
4.选择需要的Dependency,然后Next:
5.Next,然后Finsh,新项目就创建好了,各个目录如下:
6.右键MySpringBootApplication中的main方法,Run As -> Spring Boot App,项目就可以启动了。
package com.example
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class, args)
}
}
1234567891011121
由于选择了web dependency默认启动一个Tomcat,8080端口监听
7.把application.properties改名为application.yml(个人喜欢),修改Tomcat的启动端口:
server:
port: 8081

springboot怎么引入静态资源

在SpringBoot中加载静态资源和在普通的web应用中不太一样。默认情况下,spring Boot从classpath下一个叫/static(/public,/resources或/META-INF/resources)的文件夹或从ServletContext根目录提供静态内容。下面我们来写个例子看一下就会一目了然了:首先看一下项目的目录结构:

我们在resources下面的templates目录下建一个home.html的文件,完整目录为:src/main/resources/templates/home.html。内容如下:





ConanZhang的首页

最新文章