Spring boot2.0??????Mybatis
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring boot2.0??????Mybatis相关的知识,希望对你有一定的参考价值。
?????????setname map ?????? ?????? ?????? jdb ?????? tor user
??????Mybatis?????????
??????MyBatis ?????????????????????????????????????????????????????? SQL????????????????????????????????????MyBatis ???????????????????????? JDBC ???????????????????????????????????????????????????MyBatis ????????????????????? XML ?????????????????????????????????????????????????????? Java ??? POJOs(Plain Old Java Objects,????????? Java??????)?????????????????????????????????
??????????????????
<!-- ??????mybatis?????? --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency>
????????????
1 # mybatis 2 mybatis.mapper-locations=classpath:mappings/*.xml 3 mybatis.type-aliases-package=com.qiangu.model
- ??????mapper-locations???????????????src/main/resources
- ??? type-aliases-package????????????????????????Model???????????????????????????com.qiangu.model
??????xml??????-???????????????SQL??????
1 package com.qiangu.model; 2 3 public class User { 4 5 private int id; 6 private String name; 7 private Integer age; 8 9 public int getId() { 10 return id; 11 } 12 13 public void setId(int id) { 14 this.id = id; 15 } 16 17 public String getName() { 18 return name; 19 } 20 21 public void setName(String name) { 22 this.name = name; 23 } 24 25 public Integer getAge() { 26 return age; 27 } 28 29 public void setAge(Integer age) { 30 this.age = age; 31 } 32 }
?????????com.qiangu.mapper????????????UserMapper???
1 @Mapper 2 @Repository 3 public interface UserMapper { 4 5 //??????????????????????????? 6 User findAllUser(); 7 8 }
??????
Mybatis Mapper
<?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="com.qiangu.mapper.UserMapper">
??????<select id="findAllUser" resultType="com.qiangu.model.User">
??????select * from user
??????</select>
</mapper>
以上是关于Spring boot2.0??????Mybatis的主要内容,如果未能解决你的问题,请参考以下文章