在阅读“有效的Java”时,J.Bloch遇到了这一说法
静态工厂的第五个优点是,编写包含该方法的类时,不需要存在返回对象的类。
这是什么意思?有人可以举例说明吗?
我有实体和休息控制器,当我向控制器发出请求时,它会抛出此异常:
java.lang.IllegalArgumentException:参数值 [1] 与预期类型不匹配 [java.lang.Integer (n/a)]
我的控制器:
@GetMapping("/createCharacter")
public Character createCharacters(@RequestParam("userId") Integer userId, @RequestParam("mapId") long mapId) {
return createCharactersService.createCharacters(userId, mapId);
}
Run Code Online (Sandbox Code Playgroud)
我的实体有 int 类型 id:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
Run Code Online (Sandbox Code Playgroud) 我无法将 webjars 依赖项加入到 spring mvc 中的 html 页面中。这是我的 pom.xml
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我使用 webjars-locator,所以我不需要手动将 webjar 添加到资源处理程序。但是当我加载页面时,它会为每个 webjars 依赖项返回 404。
<script src="/webjars/jquery/jquery.min.js"></script>
<script src="/webjars/sockjs-client/sockjs.min.js"></script>
<script src="/webjars/stomp-websocket/stomp.min.js"></script>
Run Code Online (Sandbox Code Playgroud)