快速搭建springboot项目并整合easymybatis
2017-10-17 00:00
369 查看
创建springboot项目
访问http://start.spring.io/ 生成一个springboot空项目,Dependencies添加一个Web依赖,如图:然后点击Generate Project,下载demo.zip
导入项目
将下载的demo.zip解压,然后导入项目。eclipse中右键 -> Import... -> Existing Maven Project,选择demo文件夹。导入到eclipse中后等待jar下载。添加easymybatis依赖
jar包下载完成后,打开pom.xml,添加如下依赖:<!-- easymybatis --> <dependency> <groupId>net.oschina.durcframework</groupId> <artifactId>easymybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>
添加数据库配置
在application.properties中添加数据库配置spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull spring.datasource.username=root spring.datasource.password=root
添加Java文件
假设数据库中有张t_user表,我们加入对应的实体类和Dao:TUser.java :
@Table(name = "t_user") public class TUser { // ID @Id @Column(name="id") @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; // 用户名 private String username; // 状态 private Byte state; // 是否删除 private Boolean isdel; // 备注 private String remark; // 添加时间 private Date addTime; // 金额 private BigDecimal money; // 剩下的钱 private Float leftMoney; // 省略 getter setter
实体类文件采用和hibernate相同的方式,您可以使用我们的代码生成工具生成
https://gitee.com/durcframework/easymybatis-generator
TUserDao.java :
public interface TUserDao extends CrudDao<TUser> { }
添加测试用例
public class TUserDaoTest extends DemoApplicationTests { @Autowired TUserDao userDao; @Test public void testGet() { TUser user = userDao.get(3); System.out.println(user); } }
然后运行单元测试,运行成功后表示项目已经搭建完毕了。
最后项目结构图:
相关文章推荐
- SpringBoot1-spirng项目快速搭建+maven+spring的基本配置
- 004-Spring boot 快速入门-项目搭建与启动、SpringBootApplication
- [置顶] WEB开发----Spring Boot项目快速搭建
- 【Spring Boot教程】快速搭建spring boot项目工程
- idea快速搭建springboot项目的操作方法
- 使用Springboot快速搭建项目
- IDEA上搭建maven项目整合springboot+mybatis+shiro
- 快速搭建spring-boot的HelloWord项目
- 使用spring boot搭建与dubbo整合项目
- 4000 教你十分钟快速搭建springBoot项目实战
- 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置
- Spring Boot 学习(一) 快速搭建SpringBoot 项目
- 快速搭建SpringBoot项目
- 快速搭建Spring Boot项目
- SpringBoot之1分钟快速搭建Web项目(一)
- SpringBoot学习:IDEA中快速搭建springboot项目
- Springboot整合Dubbo - 项目创建和环境搭建
- 使用maven 快速搭建springboot项目
- 快速搭建一个简单的springboot项目
- Spring-Boot快速搭建web项目详细总结