亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文主要講解如何在Springboot中逐步實現對MyBatis的集成應用。

1、引入依賴

在pom.xml文件中引入mybatis依賴。

// pom.xml
 
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>

2、參數配置

在Application.yml配置文件中寫入mybatis相關配置。

mybatis:
  mapper-locations: classpath:mybatis/mapper/**/*.xml  #注意:一定要對應mapper映射xml文件的所在路徑
  type-aliases-package: com.knight.ygtcloud.base.entity  # 注意:對應實體類的路徑
  # spring boot集成mybatis的方式打印sql
  configuration:
    log-impl: org.Apache.ibatis.logging.nologging.NoLoggingImpl #不打印SQL
    map-underscore-to-camel-case: true #開啟自動下劃線格式轉駝峰格式

3、mapper文件

編寫mapper文件如下:

public interface SysUserMapper {
    int deleteByPrimaryKey(Long id);
 
    int insert(SysUser record);
 
    int insertSelective(SysUser record);
 
    SysUser selectByPrimaryKey(Long id);
 
    int updateByPrimaryKeySelective(SysUser record);
 
    int updateByPrimaryKey(SysUser record);
}

4、MapperScan注解

在主應用Application上通過@MapperScan注解指定mapper文件的掃描路徑。

@MapperScan("com.myApp.dao")
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication .class, args);
    }
 
}

5、xml映射文件

在配置文件指定路徑(classpath:mybatis/mapper/**/*.xml)下編寫mapper對應的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="com.knight.ygtcloud.base.dao.SysUserMapper">
  <resultMap id="BaseResultMap" type="com.knight.ygtcloud.base.entity.SysUser">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="login_name" jdbcType="VARCHAR" property="loginName" />
    <result column="mix_pd" jdbcType="VARCHAR" property="mixPd" />
    <result column="user_name" jdbcType="VARCHAR" property="userName" />
    <
  </resultMap>
  <sql id="Base_Column_List">
    id, login_name, mix_pd, user_name, user_type, user_code, sex, note, mobile, dept_first_id, 
    dept_first_name, dept_second_id, dept_second_name, org_id, org_name, email, state, 
    openId, userId, create_time, create_id, create_name, head_image, phone_image, lock_times, 
    lock_time, account_type, tech_title_key, tech_title_value, is_expert, sickness_id_list, 
    sickness_name_list, duty_key, duty_value, education_key, education_value, create_org_id, 
    create_org_name, wx_nick_name, wx_country, wx_province, wx_city, belong_org_province_id, 
    belong_org_province_name, belong_org_city_id, belong_org_city_name, belong_org_county_id, 
    belong_org_county_name, belong_org_town_id, belong_org_town_name, belong_org_village_id, 
    belong_org_village_name, online_state
  </sql>
  <select id="selectByPrimaryKey" parameterType="JAVA.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from sys_user
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from sys_user
    where id = #{id,jdbcType=BIGINT}
  </delete>
  
</mapper>

分享到:
標簽:SpringBoot
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定