我使用Spring + Mysql的,我可以自动装配成功我的课,从扩展PagingAndSortingRepository<T,E>在我的RepositoryRestController课。
我可以在下面的控制器中自动连接我的存储库。
package com.fallavi.api.user.controller;
import com.fallavi.api.MyConfig;
import com.fallavi.api.purchase.model.Purchase;
import com.fallavi.api.purchase.repository.PurchaseRepository;
import com.fallavi.api.reader.model.Reader;
import com.fallavi.api.reader.repository.ReaderRepository;
import com.fallavi.api.user.calculator.UserCreditHelper;
import com.fallavi.api.user.exceptions.UserCanNotFindException;
import com.fallavi.api.user.model.UserCreditEnoughModel;
import com.fallavi.api.user.model.UserCreditModel;
import com.fallavi.api.user.repository.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@RepositoryRestController
@RequestMapping("/user")
public class UserCreditController {
@Autowired
private ReaderRepository readerRepository;
@Autowired
private UsersRepository usersRepository;
@Autowired
private PurchaseRepository purchaseRepository;
@GetMapping(
value = "/userHasCreditEnough/{reader_id}",
headers = "Content-Type=application/json")
public ResponseEntity<UserCreditEnoughModel> userHasCreditEnough(
@RequestHeader(value = "Authorization") String token,
}
}
千巷猫影
相关分类