1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-02 23:23:28 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

添加查询书籍;BookDO映射文件更新;DOMapper添加@Repository注解;添加自定义业务异常处理;添加Validation验证

This commit is contained in:
2022-03-15 17:31:12 +08:00
parent e93b52df9b
commit c2079f9064
22 changed files with 1269 additions and 41 deletions

View File

@@ -83,7 +83,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.3.Final</version>
<version>6.2.3.Final</version>
</dependency>
<!--日期时间-->
@@ -307,6 +307,16 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.3</version>
</plugin> -->
<!-- 拉姆达表达式需要支持 Java 8 语法 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,15 +0,0 @@
package plus.bookshelf.Common.Enum;
public enum Language {
SIMPLIFIED_CHINESE(1000, "简体中文"),
ENGLISH(1001, "English"),
TRADITIONAL_CHINESE(1001, "繁体中文");
private Language(Integer langId, String langName) {
this.langId = langId;
this.langName = langName;
}
private Integer langId;
private String langName;
}

View File

@@ -0,0 +1,38 @@
package plus.bookshelf.Common.Error;
public enum BusinessErrorCode implements CommonError {
// 通用错误类型 10001
PARAMETER_VALIDATION_ERROR(10001, "参数不合法"),
UNKNOWN_ERROR(10002, "未知错误"),
// 20000开头为用户信息相关错误定义
USER_NOT_EXIST(20001, "用户不存在"),
USER_LOGIN_FAILED(20002, "用户手机号或密码不正确"),
USER_NOT_LOGIN(20003, "用户还未登录");
private BusinessErrorCode(int errCode, String errMsg) {
this.errCode = errCode;
this.errMsg = errMsg;
}
private int errCode;
private String errMsg;
@Override
public int getErrCode() {
return this.errCode;
}
@Override
public String getErrMsg() {
return this.errMsg;
}
@Override
public CommonError setErrMsg(String errMsg) {
this.errCode = errCode;
this.errMsg = errMsg;
return this;
}
}

View File

@@ -0,0 +1,37 @@
package plus.bookshelf.Common.Error;
/**
* 包装器业务异常类实现
*/
public class BusinessException extends Exception implements CommonError {
private CommonError commonError;
public BusinessException(CommonError commonError) {
super();
this.commonError = commonError;
}
// 接收自定义errMsg的方式构造业务异常
public BusinessException(CommonError commonError,String errMsg){
super();
this.commonError=commonError;
this.commonError.setErrMsg(errMsg);
}
@Override
public int getErrCode() {
return this.commonError.getErrCode();
}
@Override
public String getErrMsg() {
return this.commonError.getErrMsg();
}
@Override
public CommonError setErrMsg(String errMsg) {
this.commonError.setErrMsg(errMsg);
return this;
}
}

View File

@@ -0,0 +1,7 @@
package plus.bookshelf.Common.Error;
public interface CommonError {
public int getErrCode();
public String getErrMsg();
public CommonError setErrMsg(String errMsg);
}

View File

@@ -0,0 +1,35 @@
package plus.bookshelf.Common.Validator;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
public class ValidationResult {
// 校验结果是否有错
private boolean hasErrors = false;
// 存放错误信息的Map
private Map<String, String> errMsgMap = new HashMap<>();
// 实现通用的通过格式化字符串信息获取错误结果的msg方法
public String getErrMsg() {
return StringUtils.join(errMsgMap.values().toArray(), ",");
}
public boolean isHasErrors() {
return hasErrors;
}
public void setHasErrors(boolean hasErrors) {
this.hasErrors = hasErrors;
}
public Map<String, String> getErrMsgMap() {
return errMsgMap;
}
public void setErrMsgMap(Map<String, String> errMsgMap) {
this.errMsgMap = errMsgMap;
}
}

View File

@@ -0,0 +1,37 @@
package plus.bookshelf.Common.Validator;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;
@Component
public class ValidatorImpl implements InitializingBean {
private Validator validator;
// 实现校验方法并返回校验结果
public ValidationResult validate(Object bean) {
ValidationResult result = new ValidationResult();
Set<ConstraintViolation<Object>> constraintViolationSet = validator.validate(bean);
if (constraintViolationSet.size() > 0) {
// 有错误
result.setHasErrors(true);
constraintViolationSet.forEach(constraintViolation -> {
String errMsg = constraintViolation.getMessage();
String propertyName = constraintViolation.getPropertyPath().toString();
result.getErrMsgMap().put(propertyName, errMsg);
});
}
return result;
}
@Override
public void afterPropertiesSet() throws Exception {
// 将Hibernate Validator通过工厂的初始化方式使其实例化
this.validator = (Validator) Validation.buildDefaultValidatorFactory().getValidator();
}
}

View File

@@ -9,11 +9,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Controller.VO.BookVO;
import plus.bookshelf.Service.Model.BookModel;
import plus.bookshelf.Service.Model.CategoryModel;
import plus.bookshelf.Service.Service.BookService;
import java.util.List;
@Api(value = "书籍")
@Controller("book")
@RequestMapping("/book")
@@ -22,7 +26,7 @@ public class BookController extends BaseController {
@Autowired
BookService bookService;
@ApiOperation(value = "获取书籍信息",notes = "获取书籍信息")
@ApiOperation(value = "获取书籍信息", notes = "获取书籍信息")
// @ApiImplicitParam(name = "book", value = "图书详细实体", required = true, dataType = "Book")
@RequestMapping(value = "get", method = {RequestMethod.GET})
@ResponseBody
@@ -36,6 +40,32 @@ public class BookController extends BaseController {
return CommonReturnType.create(bookVO);
}
@ApiOperation(value = "查询书籍列表", notes = "通过指定条件查询书籍列表")
@RequestMapping(value = "search", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType search(@RequestParam(required = false, value = "id") Integer id,
@RequestParam(required = false, value = "bookName") String bookName,
@RequestParam(required = false, value = "author") String author,
@RequestParam(required = false, value = "categoryId") Integer categoryId,
@RequestParam(required = false, value = "publishingHouse") String publishingHouse,
@RequestParam(required = false, value = "language") String language) throws BusinessException {
BookModel bookModel = new BookModel();
bookModel.setId(id);
bookModel.setBookName(bookName);
bookModel.setAuthor(author);
bookModel.setPublishingHouse(publishingHouse);
bookModel.setLanguage(language);
if (categoryId != null) {
CategoryModel categoryModel = new CategoryModel();
categoryModel.setId(categoryId);
bookModel.setCategory(categoryModel);
}
List<BookModel> bookModels = bookService.searchBooks(bookModel);
return CommonReturnType.create(bookModels);
}
private BookVO convertFromModel(BookModel bookModel) {
BookVO bookVO = new BookVO();
BeanUtils.copyProperties(bookModel, bookVO);

View File

@@ -1,7 +1,6 @@
package plus.bookshelf.Controller.VO;
import lombok.Data;
import plus.bookshelf.Common.Enum.Language;
import plus.bookshelf.Service.Model.CategoryModel;
@Data
@@ -26,7 +25,7 @@ public class BookVO {
String publishingHouse;
// 语言
Language language;
String language;
// 来源(版权)信息
String copyright;

View File

@@ -0,0 +1,902 @@
package plus.bookshelf.Dao.DO;
import java.util.ArrayList;
import java.util.List;
public class BookDOExample {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table book_info
*
* @mbg.generated
*/
protected String orderByClause;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table book_info
*
* @mbg.generated
*/
protected boolean distinct;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table book_info
*
* @mbg.generated
*/
protected List<Criteria> oredCriteria;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public BookDOExample() {
oredCriteria = new ArrayList<Criteria>();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public boolean isDistinct() {
return distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table book_info
*
* @mbg.generated
*/
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Integer value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Integer value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Integer value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Integer value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Integer value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Integer value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<Integer> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Integer> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Integer value1, Integer value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Integer value1, Integer value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andBookNameIsNull() {
addCriterion("book_name is null");
return (Criteria) this;
}
public Criteria andBookNameIsNotNull() {
addCriterion("book_name is not null");
return (Criteria) this;
}
public Criteria andBookNameEqualTo(String value) {
addCriterion("book_name =", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameNotEqualTo(String value) {
addCriterion("book_name <>", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameGreaterThan(String value) {
addCriterion("book_name >", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameGreaterThanOrEqualTo(String value) {
addCriterion("book_name >=", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameLessThan(String value) {
addCriterion("book_name <", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameLessThanOrEqualTo(String value) {
addCriterion("book_name <=", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameLike(String value) {
addCriterion("book_name like", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameNotLike(String value) {
addCriterion("book_name not like", value, "bookName");
return (Criteria) this;
}
public Criteria andBookNameIn(List<String> values) {
addCriterion("book_name in", values, "bookName");
return (Criteria) this;
}
public Criteria andBookNameNotIn(List<String> values) {
addCriterion("book_name not in", values, "bookName");
return (Criteria) this;
}
public Criteria andBookNameBetween(String value1, String value2) {
addCriterion("book_name between", value1, value2, "bookName");
return (Criteria) this;
}
public Criteria andBookNameNotBetween(String value1, String value2) {
addCriterion("book_name not between", value1, value2, "bookName");
return (Criteria) this;
}
public Criteria andCategoryIdIsNull() {
addCriterion("category_id is null");
return (Criteria) this;
}
public Criteria andCategoryIdIsNotNull() {
addCriterion("category_id is not null");
return (Criteria) this;
}
public Criteria andCategoryIdEqualTo(Integer value) {
addCriterion("category_id =", value, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdNotEqualTo(Integer value) {
addCriterion("category_id <>", value, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdGreaterThan(Integer value) {
addCriterion("category_id >", value, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdGreaterThanOrEqualTo(Integer value) {
addCriterion("category_id >=", value, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdLessThan(Integer value) {
addCriterion("category_id <", value, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdLessThanOrEqualTo(Integer value) {
addCriterion("category_id <=", value, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdIn(List<Integer> values) {
addCriterion("category_id in", values, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdNotIn(List<Integer> values) {
addCriterion("category_id not in", values, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdBetween(Integer value1, Integer value2) {
addCriterion("category_id between", value1, value2, "categoryId");
return (Criteria) this;
}
public Criteria andCategoryIdNotBetween(Integer value1, Integer value2) {
addCriterion("category_id not between", value1, value2, "categoryId");
return (Criteria) this;
}
public Criteria andPublishingHouseIsNull() {
addCriterion("publishing_house is null");
return (Criteria) this;
}
public Criteria andPublishingHouseIsNotNull() {
addCriterion("publishing_house is not null");
return (Criteria) this;
}
public Criteria andPublishingHouseEqualTo(String value) {
addCriterion("publishing_house =", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseNotEqualTo(String value) {
addCriterion("publishing_house <>", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseGreaterThan(String value) {
addCriterion("publishing_house >", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseGreaterThanOrEqualTo(String value) {
addCriterion("publishing_house >=", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseLessThan(String value) {
addCriterion("publishing_house <", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseLessThanOrEqualTo(String value) {
addCriterion("publishing_house <=", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseLike(String value) {
addCriterion("publishing_house like", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseNotLike(String value) {
addCriterion("publishing_house not like", value, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseIn(List<String> values) {
addCriterion("publishing_house in", values, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseNotIn(List<String> values) {
addCriterion("publishing_house not in", values, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseBetween(String value1, String value2) {
addCriterion("publishing_house between", value1, value2, "publishingHouse");
return (Criteria) this;
}
public Criteria andPublishingHouseNotBetween(String value1, String value2) {
addCriterion("publishing_house not between", value1, value2, "publishingHouse");
return (Criteria) this;
}
public Criteria andLanguageIsNull() {
addCriterion("`language` is null");
return (Criteria) this;
}
public Criteria andLanguageIsNotNull() {
addCriterion("`language` is not null");
return (Criteria) this;
}
public Criteria andLanguageEqualTo(String value) {
addCriterion("`language` =", value, "language");
return (Criteria) this;
}
public Criteria andLanguageNotEqualTo(String value) {
addCriterion("`language` <>", value, "language");
return (Criteria) this;
}
public Criteria andLanguageGreaterThan(String value) {
addCriterion("`language` >", value, "language");
return (Criteria) this;
}
public Criteria andLanguageGreaterThanOrEqualTo(String value) {
addCriterion("`language` >=", value, "language");
return (Criteria) this;
}
public Criteria andLanguageLessThan(String value) {
addCriterion("`language` <", value, "language");
return (Criteria) this;
}
public Criteria andLanguageLessThanOrEqualTo(String value) {
addCriterion("`language` <=", value, "language");
return (Criteria) this;
}
public Criteria andLanguageLike(String value) {
addCriterion("`language` like", value, "language");
return (Criteria) this;
}
public Criteria andLanguageNotLike(String value) {
addCriterion("`language` not like", value, "language");
return (Criteria) this;
}
public Criteria andLanguageIn(List<String> values) {
addCriterion("`language` in", values, "language");
return (Criteria) this;
}
public Criteria andLanguageNotIn(List<String> values) {
addCriterion("`language` not in", values, "language");
return (Criteria) this;
}
public Criteria andLanguageBetween(String value1, String value2) {
addCriterion("`language` between", value1, value2, "language");
return (Criteria) this;
}
public Criteria andLanguageNotBetween(String value1, String value2) {
addCriterion("`language` not between", value1, value2, "language");
return (Criteria) this;
}
public Criteria andCopyrightIsNull() {
addCriterion("copyright is null");
return (Criteria) this;
}
public Criteria andCopyrightIsNotNull() {
addCriterion("copyright is not null");
return (Criteria) this;
}
public Criteria andCopyrightEqualTo(String value) {
addCriterion("copyright =", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightNotEqualTo(String value) {
addCriterion("copyright <>", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightGreaterThan(String value) {
addCriterion("copyright >", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightGreaterThanOrEqualTo(String value) {
addCriterion("copyright >=", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightLessThan(String value) {
addCriterion("copyright <", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightLessThanOrEqualTo(String value) {
addCriterion("copyright <=", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightLike(String value) {
addCriterion("copyright like", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightNotLike(String value) {
addCriterion("copyright not like", value, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightIn(List<String> values) {
addCriterion("copyright in", values, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightNotIn(List<String> values) {
addCriterion("copyright not in", values, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightBetween(String value1, String value2) {
addCriterion("copyright between", value1, value2, "copyright");
return (Criteria) this;
}
public Criteria andCopyrightNotBetween(String value1, String value2) {
addCriterion("copyright not between", value1, value2, "copyright");
return (Criteria) this;
}
public Criteria andIsDeleteIsNull() {
addCriterion("is_delete is null");
return (Criteria) this;
}
public Criteria andIsDeleteIsNotNull() {
addCriterion("is_delete is not null");
return (Criteria) this;
}
public Criteria andIsDeleteEqualTo(Boolean value) {
addCriterion("is_delete =", value, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteNotEqualTo(Boolean value) {
addCriterion("is_delete <>", value, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteGreaterThan(Boolean value) {
addCriterion("is_delete >", value, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteGreaterThanOrEqualTo(Boolean value) {
addCriterion("is_delete >=", value, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteLessThan(Boolean value) {
addCriterion("is_delete <", value, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteLessThanOrEqualTo(Boolean value) {
addCriterion("is_delete <=", value, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteIn(List<Boolean> values) {
addCriterion("is_delete in", values, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteNotIn(List<Boolean> values) {
addCriterion("is_delete not in", values, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteBetween(Boolean value1, Boolean value2) {
addCriterion("is_delete between", value1, value2, "isDelete");
return (Criteria) this;
}
public Criteria andIsDeleteNotBetween(Boolean value1, Boolean value2) {
addCriterion("is_delete not between", value1, value2, "isDelete");
return (Criteria) this;
}
public Criteria andThumbnailIsNull() {
addCriterion("thumbnail is null");
return (Criteria) this;
}
public Criteria andThumbnailIsNotNull() {
addCriterion("thumbnail is not null");
return (Criteria) this;
}
public Criteria andThumbnailEqualTo(String value) {
addCriterion("thumbnail =", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailNotEqualTo(String value) {
addCriterion("thumbnail <>", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailGreaterThan(String value) {
addCriterion("thumbnail >", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailGreaterThanOrEqualTo(String value) {
addCriterion("thumbnail >=", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailLessThan(String value) {
addCriterion("thumbnail <", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailLessThanOrEqualTo(String value) {
addCriterion("thumbnail <=", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailLike(String value) {
addCriterion("thumbnail like", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailNotLike(String value) {
addCriterion("thumbnail not like", value, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailIn(List<String> values) {
addCriterion("thumbnail in", values, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailNotIn(List<String> values) {
addCriterion("thumbnail not in", values, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailBetween(String value1, String value2) {
addCriterion("thumbnail between", value1, value2, "thumbnail");
return (Criteria) this;
}
public Criteria andThumbnailNotBetween(String value1, String value2) {
addCriterion("thumbnail not between", value1, value2, "thumbnail");
return (Criteria) this;
}
public Criteria andAuthorIsNull() {
addCriterion("author is null");
return (Criteria) this;
}
public Criteria andAuthorIsNotNull() {
addCriterion("author is not null");
return (Criteria) this;
}
public Criteria andAuthorEqualTo(String value) {
addCriterion("author =", value, "author");
return (Criteria) this;
}
public Criteria andAuthorNotEqualTo(String value) {
addCriterion("author <>", value, "author");
return (Criteria) this;
}
public Criteria andAuthorGreaterThan(String value) {
addCriterion("author >", value, "author");
return (Criteria) this;
}
public Criteria andAuthorGreaterThanOrEqualTo(String value) {
addCriterion("author >=", value, "author");
return (Criteria) this;
}
public Criteria andAuthorLessThan(String value) {
addCriterion("author <", value, "author");
return (Criteria) this;
}
public Criteria andAuthorLessThanOrEqualTo(String value) {
addCriterion("author <=", value, "author");
return (Criteria) this;
}
public Criteria andAuthorLike(String value) {
addCriterion("author like", value, "author");
return (Criteria) this;
}
public Criteria andAuthorNotLike(String value) {
addCriterion("author not like", value, "author");
return (Criteria) this;
}
public Criteria andAuthorIn(List<String> values) {
addCriterion("author in", values, "author");
return (Criteria) this;
}
public Criteria andAuthorNotIn(List<String> values) {
addCriterion("author not in", values, "author");
return (Criteria) this;
}
public Criteria andAuthorBetween(String value1, String value2) {
addCriterion("author between", value1, value2, "author");
return (Criteria) this;
}
public Criteria andAuthorNotBetween(String value1, String value2) {
addCriterion("author not between", value1, value2, "author");
return (Criteria) this;
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table book_info
*
* @mbg.generated do_not_delete_during_merge
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table book_info
*
* @mbg.generated
*/
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@@ -1,7 +1,12 @@
package plus.bookshelf.Dao.Mapper;
import plus.bookshelf.Dao.DO.BookDO;
import java.util.List;
import org.springframework.stereotype.Repository;
import plus.bookshelf.Dao.DO.BookDO;
import plus.bookshelf.Dao.DO.BookDOExample;
@Repository // 添加这个注解Autowired的时候idea就不会报错了
public interface BookDOMapper {
/**
* This method was generated by MyBatis Generator.
@@ -27,6 +32,22 @@ public interface BookDOMapper {
*/
int insertSelective(BookDO record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
List<BookDO> selectByExampleWithBLOBs(BookDOExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info
*
* @mbg.generated
*/
List<BookDO> selectByExample(BookDOExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table book_info

View File

@@ -1,7 +1,9 @@
package plus.bookshelf.Dao.Mapper;
import org.springframework.stereotype.Repository;
import plus.bookshelf.Dao.DO.CategoryDO;
@Repository
public interface CategoryDOMapper {
/**
* This method was generated by MyBatis Generator.

View File

@@ -1,7 +1,9 @@
package plus.bookshelf.Dao.Mapper;
import org.springframework.stereotype.Repository;
import plus.bookshelf.Dao.DO.FileDO;
@Repository
public interface FileDOMapper {
/**
* This method was generated by MyBatis Generator.

View File

@@ -1,7 +1,9 @@
package plus.bookshelf.Dao.Mapper;
import org.springframework.stereotype.Repository;
import plus.bookshelf.Dao.DO.FileObjectDO;
@Repository
public interface FileObjectDOMapper {
/**
* This method was generated by MyBatis Generator.

View File

@@ -1,7 +1,9 @@
package plus.bookshelf.Dao.Mapper;
import org.springframework.stereotype.Repository;
import plus.bookshelf.Dao.DO.UserDO;
@Repository
public interface UserDOMapper {
/**
* This method was generated by MyBatis Generator.

View File

@@ -1,15 +1,24 @@
package plus.bookshelf.Service.Impl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Validator.ValidationResult;
import plus.bookshelf.Common.Validator.ValidatorImpl;
import plus.bookshelf.Dao.DO.BookDO;
import plus.bookshelf.Dao.DO.BookDOExample;
import plus.bookshelf.Dao.Mapper.BookDOMapper;
import plus.bookshelf.Service.Model.BookModel;
import plus.bookshelf.Service.Model.CategoryModel;
import plus.bookshelf.Service.Service.BookService;
import plus.bookshelf.Service.Service.CategoryService;
import java.util.ArrayList;
import java.util.List;
@Service
public class BookServiceImpl implements BookService {
@@ -19,19 +28,39 @@ public class BookServiceImpl implements BookService {
@Autowired
private CategoryService categoryService;
@Autowired
ValidatorImpl validator;
@Override
@Transactional
public BookModel getBookById(Integer id) {
// 查询得到bookDO
BookDO bookDO = bookDOMapper.selectByPrimaryKey(id);
// 查询得到categoryModel
CategoryModel categoryModel = categoryService.getCategoryById(bookDO.getCategoryId());
BookModel bookModel = convertFromDataObjecct(bookDO, categoryModel);
BookModel bookModel = convertFromDataObjecct(bookDO);
return bookModel;
}
private BookModel convertFromDataObjecct(BookDO bookDO, CategoryModel categoryModel) {
@Override
public List<BookModel> searchBooks(BookModel bookModel) throws BusinessException {
// 校验入参
ValidationResult result = validator.validate(bookModel);
if (result.isHasErrors()) {
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, result.getErrMsg());
}
BookDOExample bookDOExample = new BookDOExample();
BeanUtils.copyProperties(bookModel, bookDOExample);
List<BookDO> bookDOS = bookDOMapper.selectByExample(bookDOExample);
List<BookModel> bookModels = new ArrayList<>();
for (BookDO bookDO : bookDOS) {
bookModels.add(convertFromDataObjecct(bookDO));
}
return bookModels;
}
private BookModel convertFromDataObjecct(BookDO bookDO) {
BookModel bookModel = new BookModel();
if (bookDO == null) {
return null;
@@ -40,11 +69,15 @@ public class BookServiceImpl implements BookService {
bookModel.setBookName(bookDO.getBookName());
bookModel.setDescription(bookDO.getDescription());
bookModel.setAuthor(bookDO.getAuthor());
bookModel.setCategory(categoryModel);
bookModel.setPublishingHouse(bookDO.getPublishingHouse());
bookModel.setCopyright(bookDO.getCopyright());
bookModel.setIsDelete(bookDO.getIsDelete());
bookModel.setThumbnail(bookDO.getThumbnail());
// 查询得到categoryModel
CategoryModel categoryModel = categoryService.getCategoryById(bookDO.getCategoryId());
bookModel.setCategory(categoryModel);
return bookModel;
}
}

View File

@@ -1,7 +1,9 @@
package plus.bookshelf.Service.Model;
import lombok.Data;
import plus.bookshelf.Common.Enum.Language;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
public class BookModel {
@@ -10,6 +12,7 @@ public class BookModel {
Integer id;
// 书名
@NotBlank(message = "书籍名称不能为空")
String bookName;
// 书籍简介
@@ -25,13 +28,13 @@ public class BookModel {
String publishingHouse;
// 语言
Language language;
String language;
// 来源(版权)信息
String copyright;
// 是否删除
Boolean isDelete;
Boolean isDelete = false;
// 缩略图
String thumbnail;

View File

@@ -1,7 +1,11 @@
package plus.bookshelf.Service.Service;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Dao.DO.BookDO;
import plus.bookshelf.Service.Model.BookModel;
import java.util.List;
public interface BookService {
/**
* 通过书籍Id获取书籍
@@ -9,4 +13,10 @@ public interface BookService {
* @return
*/
BookModel getBookById(Integer id);
/**
* 通过搜索条件获取书籍列表
* @return
*/
List<BookModel> searchBooks(BookModel bookModel) throws BusinessException;
}

View File

@@ -23,6 +23,39 @@
-->
<result column="description" jdbcType="LONGVARCHAR" property="description" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
@@ -38,6 +71,46 @@
-->
description
</sql>
<select id="selectByExampleWithBLOBs" parameterType="plus.bookshelf.Dao.DO.BookDOExample" resultMap="ResultMapWithBLOBs">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
'false' as QUERYID,
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from book_info
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="plus.bookshelf.Dao.DO.BookDOExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
'false' as QUERYID,
<include refid="Base_Column_List" />
from book_info
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
<!--
WARNING - @mbg.generated

View File

@@ -39,7 +39,7 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
@@ -59,11 +59,11 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into category_info (id, `name`, is_show,
`order`, `level`, parent_id,
insert into category_info (id, `name`, is_show,
`order`, `level`, parent_id,
description)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{isShow,jdbcType=BIT},
#{order,jdbcType=INTEGER}, #{level,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER},
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{isShow,jdbcType=BIT},
#{order,jdbcType=INTEGER}, #{level,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER},
#{description,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="plus.bookshelf.Dao.DO.CategoryDO">

View File

@@ -21,7 +21,7 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, username, encript_pwd, nickname, user_identity, avatar, phone, weixin_third_party_auth_code,
id, username, encript_pwd, nickname, user_identity, avatar, phone, weixin_third_party_auth_code,
qq_third_party_auth_code
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
@@ -29,7 +29,7 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
select
<include refid="Base_Column_List" />
from user_info
where id = #{id,jdbcType=INTEGER}
@@ -47,12 +47,12 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into user_info (id, username, encript_pwd,
nickname, user_identity, avatar,
insert into user_info (id, username, encript_pwd,
nickname, user_identity, avatar,
phone, weixin_third_party_auth_code, qq_third_party_auth_code
)
values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{encriptPwd,jdbcType=VARCHAR},
#{nickname,jdbcType=VARCHAR}, #{userIdentity,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR},
values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{encriptPwd,jdbcType=VARCHAR},
#{nickname,jdbcType=VARCHAR}, #{userIdentity,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{weixinThirdPartyAuthCode,jdbcType=VARCHAR}, #{qqThirdPartyAuthCode,jdbcType=VARCHAR}
)
</insert>

View File

@@ -74,7 +74,7 @@
<!-- 生成对应表及其类名 -->
<!--<table tableName="book_info" domainObjectName="BookDO" enableCountByExample="false"-->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true"-->
<!-- selectByExampleQueryId="false"></table>-->
<!--<table tableName="book_thumbnail_info" domainObjectName="ThumbnailDO" enableCountByExample="false"-->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->