本项目主要演示:
-
SpringBoot项目入门
-
SpringBoot发送邮件
-
SpringBoot集成mybatis-plus
mysql -uroot -p < ./sql/atfu.sql
修改application-dev.properties中你的MySQL密码
# 你的MySQL密码
spring.datasource.password=
# 你的邮箱
spring.mail.username=1751632917@qq.com
# 你的QQ邮箱授权码,获取方式 https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
spring.mail.password=
产品数据接口,展示mybatis-plus的使用 mybatis-plus官网
/**
* 产品分页接口
*
* @param page
* @return com.yuan.atfu.domain.vo.BaseResponse
* @author David Hong
*/
@GetMapping("/{page}")
public BaseResponse products(@PathVariable Integer page) {
IPage<Product> iPage = productService.pageOrderByGmtCreateDesc(page, 10);
Map<String, Object> ret = new HashMap<>(1);
ret.put("list", iPage.getRecords());
ret.put("total", iPage.getTotal());
ret.put("currentPage", page);
return BaseResponse.ok(ret);
}
/**
* 产品搜索分页接口
*
* @param content
* @param page
* @return com.yuan.atfu.domain.vo.BaseResponse
* @author David Hong
*/
@GetMapping("/search/{content}/{page}")
public BaseResponse search(@PathVariable("content")String content, @PathVariable("page")Integer page) {
log.info("search={}, page={}", content, page);
IPage<Product> iPage = productService.search(content, page, 10);
Map<String, Object> ret = new HashMap<>(1);
ret.put("list", iPage.getRecords());
ret.put("total", iPage.getTotal());
ret.put("currentPage", page);
return BaseResponse.ok(ret);
}
mybatis-plus lambda方式拼接MySQL
/**
* 使用mybatis-plus提供的lambda的方式
*
* @param pageNum
* @param pageSize
* @return com.baomidou.mybatisplus.core.metadata.IPage<com.yuan.atfu.domain.entity.Product>
* @author David Hong
*/
@Override
public IPage<Product> pageOrderByGmtCreateDesc(Integer pageNum, Integer pageSize) {
return lambdaQuery()
.orderByDesc(Product::getGmtCreate)
.page(new Page<>(pageNum, pageSize));
}
mybatis-plus mapper注解方式使用MySQL
/**
* MySQL like 查询
*
* @param page
* @param content
* @return com.baomidou.mybatisplus.core.metadata.IPage<com.yuan.atfu.domain.entity.Product>
* @author David Hong
*/
@Select("select * from product where no like #{content} or type like #{content} or brand like #{content} or package_type like #{content} order by gmt_create desc")
IPage<Product> search(IPage<Product> page, String content);
/**
* @author David Hong
* @version 1.0
* @description 询问下单controller
*/
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/intention")
public class IntentionController {
@Autowired
private IntentionService intentionService;
@PostMapping
public BaseResponse post(@RequestBody IntentionForm reqIntention) {
log.info(reqIntention.toString());
Intention intention = new Intention();
BeanUtils.copyProperties(reqIntention, intention);
// 插入 咨询意向 记录
intention.insert();
// 发送邮件
intentionService.sendEmail(intention);
return BaseResponse.ok("我们已收到询价下单请求,我们会尽快联系您!");
}
}