spring 入门

本文详细介绍了Spring框架的基础概念,包括如何使用IntelliJ IDEA创建Spring项目,利用Spring Initializr进行快速搭建,以及@RestController注解的使用方法。此外,还深入讲解了application.properties配置文件的应用,热更新的实现,以及如何通过JDBC和MyBatis操作数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.spring是什么介绍

2.intellij idea 接入spring创建

3.使用spring

Spring Initializr - web

自动寻找application同级或下级目录的所有controller

RestController 注解: 该注解是 @Controller 和 @ResponseBody 注解的合体版 ()
     @RequestMapping("/hello") 可以在controller标记方法,浏览器通过/hello进入

application.properties 或 application.yml 配置文件
    yml可配置其他信息(name age info )@Value直接在controller标记使用
    配置bean类名配置信息使用(student)@ConfigurationProperties(prefix = "student") 表示获取前缀为 student 的配置信息(name age),还需要
    @Component:表明当前类是一个 Java Bean,封装好后再在controller种@Autowired标记使用



热更新
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
        </dependency>

jdbc
    spring:下的  datasource:
                 url: jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=UTF8
                 username: root
                 password: 84035860
                 driver-class-name: com.mysql.jdbc.Driver

    然后需要对应bean类后
                    @Mapper
                    public interface TestUserMapper {

                        @Select("SELECT * FROM test_user")
                        List<TestUserBean> findAll();
                    }

              使用的类里

                                  @Autowired TestUserMapper userMapper;

                   @RequestMapping(value = "select_test_user_all")                    
                   private String select_test_user_all(){
                      return "";
                   }

    myBatis

              如果要使用xml方式记录sql语句则要使用myBatis

              mybatis:
                mapper-locations: classpath:mapper/*Mapper.xml
                type-aliases-package: com.myspring.springboot.bean
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值