当我尝试使用post方法发布新对象时.RequestBody无法识别contentType.Spring已经配置,POST可以与其他对象一起使用,但不是这个特定的对象.
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
Run Code Online (Sandbox Code Playgroud)
如果我尝试相同的请求只是更改requestbody对象.有用.
我使用Spring Boot和Spring Data.
我不介意将存储库层和服务层分开
所以我有我的UserRepository和CRUD方法以及一些Spring Data方法
我也有UserService和业务方法.
这是我的问题:
在我的控制器中,我必须从UserService调用方法,有时从UserRepository调用.目前,我在我的控制器中注入了两个,我称之为服务或存储库
@Inject
UserService userService;
@Inject
UserRepository userRepository;
@RequestMapping("{username}")
private void myMethod(@PathVariable String username){
return userRepository.findOne(username);
}
@RequestMapping("{username}/doBusineesAction")
private void myMethod(@PathVariable String username){
return userService.doLogicalThin(username);
}
Run Code Online (Sandbox Code Playgroud)
我只是在问,因为我很难注入并同时在同一个班级中调用一个或另一个
另一方面,这意味着在服务层中复制方法,就像这样
public User findOne(String username){
return userRepository.findOne(username);
}
Run Code Online (Sandbox Code Playgroud)
你怎么看?
我将 thymeleaf 与 Spring Boot 一起使用,
<span th:text="#{home.welcome}">Welcome Default Message</span>
Run Code Online (Sandbox Code Playgroud)
当在 messages.properties 中找不到密钥时,我有
??home.welcome_en_US??
Run Code Online (Sandbox Code Playgroud)
我不想翻译 messages.properties 中的每条消息。当找不到翻译关键消息时,我希望在 html 页面中写入“欢迎默认消息”。
我怎样才能做到这一点?
spring ×3
java ×2
jackson ×1
json ×1
repository ×1
service ×1
spring-boot ×1
spring-mvc ×1
thymeleaf ×1