springboot整合mybatis

springboot整合mybatis需要依赖org.mybatis.spring.boot,相应数据库的jdbc包当然也是要加的

    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.3.1</version>
    </dependency>

然后在springboot的配置文件中加入数据库连接的相关信息:

spring.datasource.url=jdbc:mysql://192.168.1.207:8066/test?characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

数据库访问的代码:

@Mapper
public interface CustomMapper {

	@Select("select * from custom where id=#{id}")
	public Custom findById(@Param("id")long id);
}

如果是用xml的也是可以的,不需要额外配置:

@Mapper
public interface CustomMapper {

//	@Select("select * from custom where id=#{id}")
	public Custom findById(/*@Param("id")*/long id);
}

<mapper namespace="org.lhc.myspjar.dao.CustomMapper">
	<select id="findById" resultType="org.lhc.myspjar.po.Custom" parameterType="long">
		select * from custom where id=#{id}
	</select>
</mapper>

转载请注明出处:http://blog.csdn.net/redstarofsleep

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值