Skip to content

Commit 36c8b7c

Browse files
committed
@Mapper support like query@
1 parent 94c9a27 commit 36c8b7c

6 files changed

Lines changed: 32 additions & 0 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ dependencies {
1919
compile 'org.mybatis:mybatis-spring:2.0.0'
2020
compile 'org.springframework:spring-jdbc:5.1.5.RELEASE'
2121
compile 'mysql:mysql-connector-java:6.0.5'
22+
annotationProcessor "org.projectlombok:lombok:1.16.8"
2223
}

src/main/java/cn/iwuliao/ds/controller/HeloController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import cn.iwuliao.ds.service.HeloService;
44
import org.springframework.web.bind.annotation.PathVariable;
55
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
67
import org.springframework.web.bind.annotation.RestController;
78

9+
import java.util.List;
10+
811
/**
912
* @author tangyu
1013
* @since 2019-04-22 20:30
@@ -48,4 +51,10 @@ public String tx(@PathVariable("commit") String commit) {
4851
return "i am tx ";
4952
}
5053

54+
55+
@RequestMapping("/like")
56+
public List<String> like(@RequestParam(name = "name") String name) {
57+
return heloService.likeQry(name);
58+
}
59+
5160
}

src/main/java/cn/iwuliao/ds/mapper/dba/AMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.apache.ibatis.annotations.Param;
55
import org.apache.ibatis.annotations.Select;
66

7+
import java.util.List;
8+
79
/**
810
* @author tangyu
911
* @since 2019-04-22 22:25
@@ -19,4 +21,7 @@ public interface AMapper {
1921
Integer insert(@Param("id") int id);
2022

2123

24+
List<String> likeQry(@Param("name") String name);
25+
26+
2227
}

src/main/java/cn/iwuliao/ds/service/HeloService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import cn.iwuliao.ds.core.DsScannerConfigurer;
44
import org.springframework.transaction.annotation.Transactional;
55

6+
import java.util.List;
7+
68
/**
79
* @author tangyu
810
* @since 2019-04-23 00:55
@@ -18,4 +20,6 @@ public interface HeloService {
1820
Integer rollback();
1921

2022
Integer hib();
23+
24+
List<String> likeQry(String name);
2125
}

src/main/java/cn/iwuliao/ds/service/HeloServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.springframework.stereotype.Service;
88
import org.springframework.transaction.annotation.Transactional;
99

10+
import java.util.List;
11+
1012
/**
1113
* @author tangyu
1214
* @since 2019-04-23 00:56
@@ -48,4 +50,9 @@ public Integer hib() {
4850
return id;
4951
}
5052

53+
@Override
54+
public List<String> likeQry(String name) {
55+
return aMapper.likeQry(name);
56+
}
57+
5158
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
33
<mapper namespace="cn.iwuliao.ds.mapper.dba.AMapper">
4+
5+
<select id="likeQry" resultType="string">
6+
SELECT name from a where name like
7+
<bind name="pattern" value="'%' + _parameter.name + '%'" />
8+
#{pattern}
9+
</select>
410
</mapper>

0 commit comments

Comments
 (0)