Skip to content

Commit e7ce18c

Browse files
committed
查询的例子改为Example方式
1 parent f3eb8f9 commit e7ce18c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/tk/mybatis/springboot/service/CountryService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.github.pagehelper.PageHelper;
2828
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.stereotype.Service;
30+
import tk.mybatis.mapper.entity.Example;
3031
import tk.mybatis.springboot.mapper.CountryMapper;
3132
import tk.mybatis.springboot.model.Country;
3233

@@ -46,7 +47,15 @@ public List<Country> getAll(Country country) {
4647
if (country.getPage() != null && country.getRows() != null) {
4748
PageHelper.startPage(country.getPage(), country.getRows());
4849
}
49-
return countryMapper.selectAll();
50+
Example example = new Example(Country.class);
51+
Example.Criteria criteria = example.createCriteria();
52+
if (country.getCountryname() != null && country.getCountryname().length() > 0) {
53+
criteria.andLike("countryname", "%" + country.getCountryname() + "%");
54+
}
55+
if (country.getCountrycode() != null && country.getCountrycode().length() > 0) {
56+
criteria.andLike("countrycode", "%" + country.getCountrycode() + "%");
57+
}
58+
return countryMapper.selectByExample(example);
5059
}
5160

5261
public Country getById(Integer id) {

0 commit comments

Comments
 (0)