小编Thi*_*aut的帖子

Spring Rest POST不支持Json RequestBody内容类型

当我尝试使用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对象.有用.

java spring json spring-mvc jackson

53
推荐指数
3
解决办法
8万
查看次数

使用Spring从控制器层调用存储库和服务

我使用Spring Boot和Spring Data.

我不介意将存储库层和服务层分开

所以我有我的UserRepository和CRUD方法以及一些Spring Data方法

  • 找到所有
  • findByUsername

我也有UserService和业务方法.

  • checkPassword(字符串登录,字符串密码)
  • businessMethodAction(String username)

这是我的问题:

在我的控制器中,我必须从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)

你怎么看?

java model-view-controller service spring repository

7
推荐指数
1
解决办法
6505
查看次数

thymeleaf 国际化使用默认文本 html

我将 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 internationalization thymeleaf spring-boot

2
推荐指数
1
解决办法
5955
查看次数