Spring Boot 创建入门项目

您所在的位置:网站首页 戴尔笔记本怎么分磁盘 Spring Boot 创建入门项目

Spring Boot 创建入门项目

#Spring Boot 创建入门项目| 来源: 网络整理| 查看: 265

一:eclipse 创建项目

 如果没有安装sts的可以在eclipse中快速安装

选择MaketPlace

二.在Pom.xml配置文件中添加所需的jar包

com.alibaba druid 1.1.0 org.mybatis.generator mybatis-generator-maven-plugin 1.3.6 ${basedir}/src/main/resources/generator/generatorConfig.xml true true

三.数据库创建表

四.通过Maven build 运行generatorConfig.xml生成Bean和mapper

注意:spring boot启动DemoAplication是需要扫描它下面的Controller等类的,所以将DemoApplication移动到com/demo目录下,各种其他包也得放在该目录下

五.mapper接口创建

package com.example.demo.dao; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import com.example.demo.model.Student; @Mapper public interface StudentMapper { @Select("select *from student ") public Student getAll(); }

六.主函数前面加入浏览包的注解

#默认使用配置 spring: profiles: active: dev #公共配置与profiles选择无关 mapperLocations指的路径是src/main/resources mybatis: typeAliasesPackage: com.example.demo.model mapperLocations: classpath:com.example.demo.mapper/*.xml --- #开发配置 spring: profiles: dev datasource: url: jdbc:mysql://localhost:3306/mysql username: root password: xxxxx driver-class-name: com.mysql.jdbc.Driver # 使用druid数据源 type: com.alibaba.druid.pool.DruidDataSource

七.测试类进行测试

package com.example.demo; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import com.example.demo.model.Student; import com.example.demo.service.studentService; @RunWith(SpringRunner.class) @SpringBootTest public class DemoApplicationTests { @Autowired private studentService studentService; @Test public void contextLoads() { Student student=studentService.showAll(); System.out.println(student); } }



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3