# SpringBoot **Repository Path**: chenbinghuilove/SpringBoot ## Basic Information - **Project Name**: SpringBoot - **Description**: 学习SpringBoot敏捷开发技术 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2016-11-14 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #SpringBoot敏捷开发 ##开发过程: >###SpringBoot初始化过程 通过`SPRING INITIALIZR`工具产生基础项目,访问地址:`http://start.spring.io/`。直接生产一个空的maven项目目录文件。 >###Maven构建项目 在eclipse中通过import引入现成的maven项目,并进行编译。 在此过程中可能会出现类似的情况,那是因为默认的当前java版本与maven项目的java版本不一致导致的。具体做法如下: ![输入图片说明](http://git.oschina.net/uploads/images/2016/1114/171125_cd3b64a2_370055.png "出错的情况") ![输入图片说明](http://git.oschina.net/uploads/images/2016/1114/171201_9cb6205c_370055.png "修改java版本") ![输入图片说明](http://git.oschina.net/uploads/images/2016/1114/171229_4d5c6357_370055.png "在这里输入图片标题") 正如我项目中的chater1部分,简单地使用了 ###编写HelloWorld服务 1.编写Helloworld控制器服务; 2.启动主程序(run main函数),打开浏览器访问http://localhost:8080/Hello,可以看到页面输出Hello World #SpringBoot结合Mybatis进行敏捷开发 ##开发过程: >###配置pom依赖 1 加入Mybatis以及mysql库还有springboot与mybatis结合的依赖 2 这里用到spring-boot-starter基础和spring-boot-starter-test用来做单元测试验证数据访问 3 引入连接mysql的必要依赖mysql-connector-java 4 引入整合MyBatis的核心依赖mybatis-spring-boot-starter 5 这里不引入spring-boot-starter-jdbc依赖,是由于mybatis-spring-boot-starter中已经包含了此依赖 ```xml org.springframework springloaded 1.2.5.RELEASE org.mybatis.spring.boot mybatis-spring-boot-starter 1.1.1 org.mybatis.spring.boot mybatis-spring-boot-sample-annotation 1.1.1 org.mybatis.spring.boot mybatis-spring-boot-sample-xml 1.1.1 org.mybatis mybatis 3.4.1 org.mybatis mybatis-spring 1.3.0 mysql mysql-connector-java runtime ``` >###数据库的配置文件yml源 这里就是springboot的方便之处,根本不需要再通过xml的形式进行相关的配置,注入springmvc进行管理。 ```xml server: port: 8080 spring: application: name: mybatisAnnotation datasource: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=GMT%2b8 username: root password: driver-class-name: com.mysql.jdbc.Driver ``` >###mapper这里我采用了两种方式进行关联 1. 可以使mybatis的注释注入的方式, ```java @Mapper public interface UserMapper { @Select({"select * from user where id = #{id}"}) User findById(@Param("id") int id); //这里可以使用注释的方式或者是xml的方式都行。 List findAll(); @Insert({"insert into user (name,age) values(#{name},#{age}"}) void saveUser(@Param("name") String name, @Param("age") int age); } ``` 2. 对于复杂的sql操作还是需要使用xml的方式比较方便。 针对findAll()方法进行xml格式进行配置 ```xml ```