本项目采用mysql,数据层框架用mybatis,基于tk.mybatis包实现基础的mapper,具体详见项目工程实例
<!--mapper --> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>1.0.0</version> </dependency> <!--mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>mapper配置
mapper.identity=MYSQL mapper.mappers[0]=cn.liuhaihua.web.mapper.BaseMapper mapper.not-empty=false mybatis.type-aliases-package=cn.liuhaihua.web.model
配置扫描包
通用的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新手朋友课程要求,我特出此教程,由于时间仓促的问题,代码写得不好之处的地方还请多多包涵。 目标如下GIT地址:https://gitee.com/jxuasea/JWordpress
- 优化wordpress效率低下的问题(目前博主文章数量大概10万+)
- 让群里面初级Java朋友们更快上手springboot应用