提交 dd085b12 编写于 作者: W Wenyi Feng

MyBatis-Plus 3.0.1 Lambda

上级 a6c31604
<component name="libraryTable">
<library name="Maven: com.fengwenyi:JavaLib:1.0.1-RELEASE">
<CLASSES>
<root url="jar://D:/Maven/repository/com/fengwenyi/JavaLib/1.0.1-RELEASE/JavaLib-1.0.1-RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/Maven/repository/com/fengwenyi/JavaLib/1.0.1-RELEASE/JavaLib-1.0.1-RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Maven/repository/com/fengwenyi/JavaLib/1.0.1-RELEASE/JavaLib-1.0.1-RELEASE-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: com.google.protobuf:protobuf-java:2.6.0">
<CLASSES>
<root url="jar://D:/Maven/repository/com/google/protobuf/protobuf-java/2.6.0/protobuf-java-2.6.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/Maven/repository/com/google/protobuf/protobuf-java/2.6.0/protobuf-java-2.6.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Maven/repository/com/google/protobuf/protobuf-java/2.6.0/protobuf-java-2.6.0-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: commons-codec:commons-codec:1.11">
<CLASSES>
<root url="jar://D:/Maven/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/Maven/repository/commons-codec/commons-codec/1.11/commons-codec-1.11-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Maven/repository/commons-codec/commons-codec/1.11/commons-codec-1.11-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: mysql:mysql-connector-java:8.0.12">
<library name="Maven: mysql:mysql-connector-java:5.1.47">
<CLASSES>
<root url="jar://D:/Maven/repository/mysql/mysql-connector-java/8.0.12/mysql-connector-java-8.0.12.jar!/" />
<root url="jar://D:/Maven/repository/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/Maven/repository/mysql/mysql-connector-java/8.0.12/mysql-connector-java-8.0.12-javadoc.jar!/" />
<root url="jar://D:/Maven/repository/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Maven/repository/mysql/mysql-connector-java/8.0.12/mysql-connector-java-8.0.12-sources.jar!/" />
<root url="jar://D:/Maven/repository/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apache.httpcomponents:httpclient:4.5.6">
<CLASSES>
<root url="jar://D:/Maven/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/Maven/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Maven/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apache.httpcomponents:httpcore:4.4.10">
<CLASSES>
<root url="jar://D:/Maven/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/Maven/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/Maven/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
此差异已折叠。
......@@ -22,8 +22,7 @@
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.9" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.12" level="project" />
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:2.6.0" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.47" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.0-RC1" level="project" />
......
......@@ -12,8 +12,8 @@
<properties>
<mp.version>3.0-RELEASE</mp.version>
<!--<mp.version>2.3.1</mp.version>-->
<mysql.version>8.0.12</mysql.version>
<!--<mysql.version>5.1.47</mysql.version>-->
<!--<mysql.version>8.0.12</mysql.version>-->
<mysql.version>5.1.47</mysql.version>
<spring.version>5.0.8.RELEASE</spring.version>
</properties>
......
......@@ -27,7 +27,7 @@ public class Utils {
* 执行生成代码
*/
public static void generateCode() {
String packageName = "com.fengwenyi.mpdemo";
String packageName = "com.fengwenyi.password_manage";
//generateByTables(packageName, "t_student", "t_city", "t_idcard");
generateByTables(packageName, null);
}
......@@ -35,14 +35,16 @@ public class Utils {
private static void generateByTables(String packageName, String... tableNames) {
// 数据库信息
String dbUrl = "jdbc:mysql://localhost:3306/mybatis-plus?useSSL=true";
// String dbUrl = "jdbc:mysql://localhost:3306/mybatis-plus?useSSL=true";
String dbUrl = "jdbc:mysql://localhost:3306/password-manage";
DataSourceConfig dataSourceConfig = new DataSourceConfig()
.setDbType(DbType.MYSQL)
.setUrl(dbUrl)
.setUsername("root")
.setPassword("xfsy2017")
//.setDriverName("com.mysql.jdbc.Driver") // mysql 5
.setDriverName("com.mysql.cj.jdbc.Driver") // mysql 8
// .setPassword("xfsy2017")
.setPassword("kU#m5eHY5iTiQj#q")
.setDriverName("com.mysql.jdbc.Driver") // mysql 5
// .setDriverName("com.mysql.cj.jdbc.Driver") // mysql 8
/*.setTypeConvert(new MySqlTypeConvert() {
@Override
public PropertyInfo processTypeConvert(GlobalConfig globalConfig, String fieldType) {
......@@ -56,7 +58,8 @@ public class Utils {
GlobalConfig config = new GlobalConfig()
.setActiveRecord(false)
.setAuthor("Wenyi Feng")
.setOutputDir("/Users/fengwenyi/Workspace/file/codeGen")
// .setOutputDir("/Users/fengwenyi/Workspace/file/codeGen")
.setOutputDir("d:/codeGen")
.setFileOverride(true)
.setActiveRecord(true)// 不需要ActiveRecord特性的请改为false
.setEnableCache(false)// XML 二级缓存
......@@ -87,8 +90,8 @@ public class Utils {
//.setExclude(new String[]{"test"}) // 排除生成的表
.setEntityLombokModel(true) // lombok实体
.setEntityBuilderModel(false) // 【实体】是否为构建者模型(默认 false)
.setEntityColumnConstant(true) // 【实体】是否生成字段常量(默认 false)// 可通过常量名获取数据库字段名
.setLogicDeleteFieldName("is_delete") // 逻辑删除属性名称
.setEntityColumnConstant(false) // 【实体】是否生成字段常量(默认 false)// 可通过常量名获取数据库字段名 // 3.x支持lambda表达式
//.setLogicDeleteFieldName("is_delete") // 逻辑删除属性名称
//.setEntityTableFieldAnnotationEnable
.entityTableFieldAnnotationEnable(true)
;
......
......@@ -24,7 +24,7 @@
<java.version>1.8</java.version>
<swagger2.version>2.9.2</swagger2.version>
<javalib.version>1.0.1-RELEASE</javalib.version>
<JavaLib.version>1.0.4.RELEASE</JavaLib.version>
<mp.version>3.0.1</mp.version>
</properties>
......@@ -72,7 +72,13 @@
<dependency>
<groupId>com.fengwenyi</groupId>
<artifactId>JavaLib</artifactId>
<version>${javalib.version}</version>
<version>${JavaLib.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
</dependencies>
......
package com.fengwenyi.mp3demo.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fengwenyi.javalib.result.Result;
import com.fengwenyi.javalib.util.StringUtil;
import com.fengwenyi.mp3demo.business.AppBusiness;
import com.fengwenyi.mp3demo.enums.GenderEnum;
......@@ -92,5 +94,4 @@ public class AppController {
return null;
return mpStudentService.queryStudentByPage(currentPage);
}
}
......@@ -3,6 +3,8 @@ package com.fengwenyi.mp3demo.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fengwenyi.mp3demo.model.Student;
import java.util.List;
/**
* <p>
* Mapper 接口
......@@ -13,4 +15,6 @@ import com.fengwenyi.mp3demo.model.Student;
*/
public interface StudentDao extends BaseMapper<Student> {
List<Student> selectAll();
}
......@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fengwenyi.mp3demo.model.Student;
import java.util.List;
/**
* <p>
* 服务类
......@@ -20,4 +22,46 @@ public interface MPStudentService extends IService<Student> {
IPage<Student> queryStudentByPage(Long currentPage);
void test1();
void test2();
void test3();
void test4();
void test5();
void test6();
void test7();
//------------------------------------------ 封装接口
/**
* 查询所有数据
* @return List<Student>
*/
List<Student> findAll();
/**
* 查询部分数据
* @return List<Student>
*/
List<Student> findList();
/**
* 查询一条数据
* @return Student
*/
Student findOne();
/**
* 根据主键ID查询数据
* @param id 主键ID,为null,返回null
* @return Student
*/
Student findById(Long id);
//------------------------------------------
}
......@@ -3,15 +3,18 @@ package com.fengwenyi.mp3demo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fengwenyi.javalib.util.Console;
import com.fengwenyi.javalib.util.ExceptionUtil;
import com.fengwenyi.mp3demo.config.ConstantConfig;
import com.fengwenyi.mp3demo.model.Student;
import com.fengwenyi.mp3demo.dao.StudentDao;
import com.fengwenyi.mp3demo.service.MPStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
......@@ -57,4 +60,109 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
public IPage<Student> queryStudentByPage(Long currentPage) {
return page(new Page<>(currentPage, ConstantConfig.PAGE_SITE), null);
}
//--------------------------------------------------test start
// 通过名字进行筛选
@Override
public void test1() {
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Student::getName, "冯文议");
// queryWrapper.lambda().like(Student::getName, "文");
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
}
@Override
public void test2() {
IPage<Student> page = page(
new Page<>(1, 2),
null);
Console.info(new Gson().toJson(page));
}
@Override
public void test3() {
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.eq(Student::getName, "冯文议")
// .eq(Student::getAge, 26)
.eq(Student::getAge, 25);
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
}
@Override
public void test4() {
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.and(obj ->
obj.eq(Student::getName, "冯文议")
.eq(Student::getAge, 26));
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
}
@Override
public void test5() {
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.or(obj1 -> obj1.eq(Student::getName, "冯文议"))
.or(obj2 -> obj2.eq(Student::getName, "1"));
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
}
@Override
public void test6() {
QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda()
.eq(Student::getName, "冯文议")
.or()
.eq(Student::getName, "1");
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
}
@Resource
StudentDao studentDao;
@Override
public void test7() {
List<Student> studentList = studentDao.selectAll();
for (Student student : studentList)
Console.info(new Gson().toJson(student));
}
@Override
public List<Student> findAll() {
return list(null);
}
@Override
public List<Student> findList() {
return list(null);
}
@Override
public Student findOne() {
return getOne(null);
}
@Override
public Student findById(Long id) {
ExceptionUtil.notNull(id, "id must not null.");
return getById(id);
}
//--------------------------------------------------test end
}
......@@ -16,4 +16,9 @@
<result column="city_id" property="cityId" />
</resultMap>
<!--List<Student> selectAll();-->
<select id="selectAll" resultMap="BaseResultMap">
select * from t_student
</select>
</mapper>
package com.fengwenyi.mp3demo.service;
import com.fengwenyi.mp3demo.Mp3DemoApplicationTests;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static org.junit.Assert.*;
/**
* @author Wenyi Feng
* @since 2018-09-11
*/
@Component
public class MPStudentServiceTest extends Mp3DemoApplicationTests {
@Autowired
private MPStudentService mpStudentService;
@Test
public void test1() {
mpStudentService.test1();
}
@Test
public void test2() {
mpStudentService.test2();
}
@Test
public void test3() {
mpStudentService.test3();
}
@Test
public void test4() {
mpStudentService.test4();
}
@Test
public void test5() {
mpStudentService.test5();
}
@Test
public void test6() {
mpStudentService.test6();
}
@Test
public void test7() {
mpStudentService.test7();
}
@Test
public void test8() {
// mpStudentService.find
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册