Skip to content

Commit a3c3814

Browse files
committed
Weekend
1 parent 82476ba commit a3c3814

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/tk/mybatis/springboot/controller/CountryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class CountryController {
5151
@RequestMapping
5252
public ModelAndView getAll(Country country) {
5353
ModelAndView result = new ModelAndView("index");
54-
List<Country> countryList = countryService.getAll(country);
54+
List<Country> countryList = countryService.getAllByWeekend(country);
5555
result.addObject("pageInfo", new PageInfo<Country>(countryList));
5656
result.addObject("queryParam", country);
5757
result.addObject("page", country.getPage());

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.stereotype.Service;
3030
import tk.mybatis.mapper.entity.Example;
31+
import tk.mybatis.mapper.weekend.Weekend;
32+
import tk.mybatis.mapper.weekend.WeekendCriteria;
3133
import tk.mybatis.springboot.mapper.CountryMapper;
3234
import tk.mybatis.springboot.model.Country;
3335

@@ -58,6 +60,21 @@ public List<Country> getAll(Country country) {
5860
return countryMapper.selectByExample(example);
5961
}
6062

63+
public List<Country> getAllByWeekend(Country country) {
64+
if (country.getPage() != null && country.getRows() != null) {
65+
PageHelper.startPage(country.getPage(), country.getRows());
66+
}
67+
Weekend<Country> weekend = Weekend.of(Country.class);
68+
WeekendCriteria<Country, Object> criteria = weekend.weekendCriteria();
69+
if (country.getCountryname() != null && country.getCountryname().length() > 0) {
70+
criteria.andLike(Country::getCountryname, "%" + country.getCountryname() + "%");
71+
}
72+
if (country.getCountrycode() != null && country.getCountrycode().length() > 0) {
73+
criteria.andLike(Country::getCountrycode, "%" + country.getCountrycode() + "%");
74+
}
75+
return countryMapper.selectByExample(weekend);
76+
}
77+
6178
public Country getById(Integer id) {
6279
return countryMapper.selectByPrimaryKey(id);
6380
}

0 commit comments

Comments
 (0)