1、添加依赖
1.1、修改pom.xml
<dependency>
<groupId>org.nanoframework</groupId>
<artifactId>nano-orm-mybatis</artifactId>
<version>1.2.0-RC1</version>
</dependency>
1.2、在src/main/resources下添加MyBatis数据源 examples-mybatis.properties
mybatis.environment.id=mybatis-examples
mapper.package.name=org.nanoframework.examples.first.webapp.mapper
JDBC.pool.type=DRUID
JDBC.driver=org.h2.Driver
JDBC.url=jdbc:h2:~/test2
JDBC.username=test
JDBC.password=test
JDBC.autoCommit=false
# 省略连接池的属性配置
1.3、修改context.properties
# mapper.package.root=examples,examples2修改为如下内容
mapper.package.root=examples,examples2,mybatis-examples
# 添加如下属性
mapper.package.jdbc.mybatis-examples=/examples-mybatis.properties
2、开发基于Mybatis的服务
2.1、在/src/main/java/org.nanoframework.examples.first.webapp.mapper下添加ExampleMapper接口
public interface ExampleMapper {
List<Test> select();
}
2.2、在/src/main/resources/org.nanoframework.examples.first.webapp.mapper下添加ExampleMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.nanoframework.examples.first.webapp.mapper.ExampleMapper">
<select id="select" resultType="org.nanoframework.examples.first.webapp.domain.Test">
select id, name from t_nano_test
</select>
</mapper>
2.3、添加MybatisExampleComponent组件接口及实现类
@Component
@ImplementedBy(MybatisExampleComponentImpl.class)
@RequestMapping("/mybatis")
public interface MybatisExampleComponent {
@RequestMapping("/find/all")
Object findAll();
}
public class MybatisExampleComponentImpl implements MybatisExampleComponent {
@Inject
private ExampleMapper exampleMapper;
@Override
public Object findAll() {
List<Test> testList = exampleMapper.select();
Map<String, Object> map = ResultMap.create(200, "Find all Test", "SUCCESS")._getBeanToMap();
map.put("records", testList.size());
map.put("rows", testList);
return map;
}
}
3、启动服务后进行以下操作
- http://ip:port/first-webapp/mybatis/find/all
4、至此,基于Mybatis的组件服务开发完成
分享到:
相关推荐
使用springboot框架基础上使用MyBatis简化持久层开发。
该配置文件描述mybatis持久层框架技术的,可有将SQL放到配置文件并且规范数据库连接等
MyBatis数据持久层框架 v3.5.15.zip
MyBatis框架也被称之为ORM(Object/Relationship Mapping,即对象关系映射)框架。所谓的ORM就是一种为了解决面向对象与关系型数据库中数据类型不匹配的技术,它通过描述Java对象与数据库表之间的映射关系,自动将...
是一个数据持久层(ORM)框架。 MyBatis SQL映射器框架使将关系数据库与面向对象的应用程序结合使用变得更加容易。MyBatis使用XML描述符或注释将对象与存储过程或SQL语句耦合。相对于对象关系映射工具,简单性是...
mybtis开发方式主要有三种,基础知识大神请略过,想了解基础的同学可以看看
3.使用myeclipse新建web工程之后将jeecg-mybatis-framework目录下文件复制粘贴到新建的web工程目录下 4.在myeclipse中刷新新建的web工程之后找到resources/jeecg目录下 jeecg_config.properties与jeecg_database....
Java开发系列MyBatis使用以及实现Java开发系列MyBatis使用以及实现Java开发系列MyBatis使用以及实现Java开发系列MyBatis使用以及实现Java开发系列MyBatis使用以及实现Java开发系列MyBatis使用以及实现Java开发系列...
开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2...
SpringCloud及SpringBoot整合使用, 包含zuul, eureka服务, mybatis做持久层, Maven模块划分: boot-test父模块, admin, remote-server, eureka-server, ruul-server, commons-api模块; 其中admin用来提供web服务模块;...
持久层开源工具MyBatis-Plus快速入门,Spring Boot整合MyBatis-Plus简化开发示例代码
jeecg-mybatis-framework20131220.zipjeecg-mybatis-framework20131220.zipjeecg-mybatis-framework20131220.zipjeecg-mybatis-framework20131220.zipjeecg-mybatis-framework20131220.zipjeecg-mybatis-framework...
java 之持久化mybatis3,手册详细的描述了mybatis的使用规范及介绍
Java框架开发技术,MyBatis 是一款优秀的半自动的ORM持久层框架,它支持自定义 SQL、存储过程及高级映射。
iBATIS提供的持久层框架包括SQL Maps和Data Access Objects(DAO),同时还提供一个利用这个框架开发的 JPetStore实例。 在线Javadoc:http://tool.oschina.net/apidocs/apidoc?api=mybatis-3.1.1 标签:...
java框架教材。java框架教材。java框架教材。java框架教材。java框架教材。java框架教材。java框架教材。java框架教材。java框架教材。java框架教材。
开发工具 框架JAR mybatis-3.4.2开发工具 框架JAR mybatis-3.4.2开发工具 框架JAR mybatis-3.4.2开发工具 框架JAR mybatis-3.4.2开发工具 框架JAR mybatis-3.4.2开发工具 框架JAR mybatis-3.4.2开发工具 框架JAR ...
,JDBC,MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Plain Ordinary Java Object,普通的 Java对象)映射成数据库中的记录
3-2_MyBatis持久层框架.pdf
java开发中使用mybatis框架需要用到的独立jar包,java开发中使用mybatis框架需要用到的独立jar包,java开发中使用mybatis框架需要用到的独立jar包,java开发中使用mybatis框架需要用到的独立jar包,