本項目採用mysql,數據層框架用mybatis,基於tk.mybatis包實現基礎的mapper,具體詳見項目工程實例java
pom.xml引入相關的包mysql
<!–mapper –>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>git<!–mybatis –>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>web<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>spring<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>sql
mapper配置springboot
mapper.identity=MYSQL
mapper.mappers[0]=cn.liuhaihua.web.mapper.BaseMapper
mapper.not-empty=false
mybatis.type-aliases-package=cn.liuhaihua.web.modelmybatis
配置掃描包app
通用的mapper框架
/**
* MIT License
* Copyright (c) 2018 haihua.liu
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the 「Software」), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED 「AS IS」, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cn.liuhaihua.web.mapper;import tk.mybatis.mapper.common.ConditionMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
/**
*
* @ClassName: BaseMapper
* @Description: 通用的mapper
* @author Liuhaihua
* @date 2018年6月27日
*
* @param <T>
*/
public interface BaseMapper<T> extends Mapper<T>, MySqlMapper<T>,ConditionMapper<T> {}
/**
* MIT License
* Copyright (c) 2018 haihua.liu
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the 「Software」), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED 「AS IS」, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cn.liuhaihua.web;import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;import cn.liuhaihua.web.model.WpUsers;
import cn.liuhaihua.web.service.WpUsersService;/**
* @ClassName: WpUsersTest
* @Description: 用戶測試類
* @author Liuhaihua
* @date 2018年6月29日
*
*/
public class WpUsersTest extends BaseTest{
@Autowired
private WpUsersService wpUsersService;
/**
* @Title: getUserDetail
* @Description: 測試獲取用戶信息方法
* @param 參數
* @return void 返回類型
* @throws
*/
@Test
public void getUserDetail() {
WpUsers user =wpUsersService.getUserDetail(1l);
Assert.assertEquals(「Harries」, user.getDisplayName());
}
}
運行junit測試用例
項目介紹:
爲了知足Java新手朋友課程要求,我特出此教程,因爲時間倉促的問題,代碼寫得很差之處的地方還請多多包涵。
目標以下
- 優化wordpress效率低下的問題(目前博主文章數量大概10萬+)
- 讓羣裏面初級Java朋友們更快上手springboot應用
GIT地址:gitee.com/jxuasea/JWo…