springboot项目简单使用

springboot项目连接mysql环境搭建

在之前的ssm中搭建好一个项目配置好环境,和配置文件,服务器这些加起来需要很很长的时间。所以学srpingboot。学完后搭建一个web项目不过几分钟而已。
第一步:file —>new—>project
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这样一个项目就创建成功了
第二步:项目创建好后在pox.xml中添加jar包

<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.2</version>
</dependency>


<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.47</version>
</dependency>

第三步:在application.properties进行相应的配置

##springboot连接数据库
spring.datasource.platform=mysql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/permissionsystem
spring.datasource.username=root
spring.datasource.password=123456
##springboot关联mybatis
##sqlmapper映射文件位置
mybatis.mapper-locations=classpath:/sqlMapper/*Mapper.xml
##下划线到驼峰式命名法映射
mybatis.configuration.map-underscore-to-camel-case=true
##类起别名
mybatis.type-aliases-package=com.lanou.myspringboot.pojo

第三步:找到主类,添加myabtis mapper接口扫描
在MyspringbootApplication类中

@SpringBootApplication
@MapperScan(basePackages = {"com.itzz.myspringboot.mapper"})
public class MyspringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyspringbootApplication.class, args);
    }

}

第四步:完善从数据库中查询全部信息的功能
在resource下创建一个sqlMapper文件夹,在文件夹中创建对应的sql映射文件
在这里插入图片描述
pojo类

public class Role {
    private Integer rId;
    private String rName;

---getter  setter
}

RoleMapper接口

@Component
@Mapper
public interface RoleMapper {
    public List<Role> list();
}

service接口和实现类

public interface RoleService {
    public List<Role> list();
}


@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> list() {
        return roleMapper.list();
    }
}

controller控制层

@RestController
@RequestMapping("role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("find")
    public List<Role> find(){
        return roleService.list();
    }

}

第四步:测试
在这里插入图片描述
在这里插入图片描述
可以看到数据库表中的数据已经获取到了一个springboot的项目就完成了

修改springboot的启动图标

第一次启动springboot默认图标
在这里插入图片描述
在resource下创建一个banner.txt,搜一个喜欢的图标放到
| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
| |
| Xiao Xiao Miao… |
| |
| |
|____________|
(__/) ||
(•ㅅ•) ||
/   づv
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值