<generatorConfiguration>
<table tableName="litemall_brand">
<generatedKey column="id" sqlStatement="MySql" identity="true" />
</table>
</generatorConfiguration> @Service
public class LitemallBrandService {
@Resource
private LitemallBrandMapper brandMapper;
public List<LitemallBrand> query(int offset, int limit) {
LitemallBrandExample example = new LitemallBrandExample();
example.or().andDeletedEqualTo(false);
PageHelper.startPage(offset, limit);
return brandMapper.selectByExample(example);
}
} @Service
public class StatService {
@Resource
private StatMapper statMapper;
public List<Map> statUser() {
return statMapper.statUser();
}
public List<Map> statOrder(){
return statMapper.statOrder();
}
public List<Map> statGoods(){
return statMapper.statGoods();
}
} <table tableName="litemall_goods">
<columnOverride column="gallery" javaType="java.lang.String[]"
typeHandler="org.linlinjava.litemall.db.mybatis.JsonStringArrayTypeHandler"/>
</table> CREATE TABLE `litemall`.`litemall_demo` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`address` VARCHAR(45) NULL,
PRIMARY KEY (`id`));
INSERT INTO `litemall`.`litemall_demo` (`id`, `name`, `address`)
VALUES ('1', 'hello', 'world'); <generatorConfiguration>
<table tableName="litemall_demo">
<generatedKey column="id" sqlStatement="MySql" identity="true" />
</table>
</generatorConfiguration> @Service
public class LitemallDemoService {
@Resource
private LitemallDemoMapper demoMapper;
public List<LitemallDemo> list() {
LitemallDemoExample example = new LitemallDemoExample();
return demoMapper.selectByExample(example);
}
} @WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class LitemallDemoTest {
@Autowired
private LitemallDemoService demoService;
@Test
public void test() {
List<LitemallDemo> litemallDemoList = demoService.list();
Assert.assertTrue(litemallDemoList.size() != 0);
}
} @RestController
@RequestMapping("/demo")
public class DemoController {
@Autowired
private LitemallDemoService demoService;
@RequestMapping("/list")
public Object list(){
List<LitemallDemo> demoList = demoService.list();
return demoList;
}
}{
errno: 0,
errmsg: '成功',
data: XXX
}{
errno: 非0的XXX,
errmsg: XXX
}public interface Storage {
void store(InputStream inputStream, long contentLength, String contentType, String keyName);
Stream<Path> loadAll();
Path load(String keyName);
Resource loadAsResource(String keyName);
void delete(String keyName);
String generateUrl(String keyName);
} @Target({METHOD, FIELD, PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = OrderValidator.class)
public @interface Order {
String message() default "排序类型不支持";
String[] accepts() default {"desc", "asc"};
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
} public class OrderValidator implements ConstraintValidator<Order, String> {
private List<String> valueList;
@Override
public void initialize(Order order) {
valueList = new ArrayList<String>();
for (String val : order.accepts()) {
valueList.add(val.toUpperCase());
}
}
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if (!valueList.contains(s.toUpperCase())) {
return false;
}
return true;
}
} @RestController
@RequestMapping("/wx/topic")
@Validated
public class WxTopicController {
@GetMapping("list")
public Object list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
...
} @Target({METHOD, FIELD, PARAMETER})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = SortValidator.class)
public @interface Sort {
String message() default "排序字段不支持";
String[] accepts() default {"add_time", "id"};
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
} public class SortValidator implements ConstraintValidator<Sort, String> {
private List<String> valueList;
@Override
public void initialize(Sort sort) {
valueList = new ArrayList<String>();
for (String val : sort.accepts()) {
valueList.add(val.toUpperCase());
}
}
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if (!valueList.contains(s.toUpperCase())) {
return false;
}
return true;
}
} @RestController
@RequestMapping("/wx/topic")
@Validated
public class WxTopicController {
@GetMapping("list")
public Object list(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer limit,
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
...
}

