草庐IT

save_path

全部标签

java - Spring JpaRepository : delete() with subsequent save() in the same transaction

我的实体同时具有自动生成的主键(id)和业务键(命名空间)。我需要通过替换旧记录来更新记录。所以,我正在按业务键搜索它,删除它并保存一个新实体。如果它自己的事务中的每个操作都有效。但是一旦我把它们都放在同一个事务中,当save()被执行时,delete()还没有被执行,所以我得到了一个约束违规。transactionTemplate.execute(status->{MyEntityoldEntity=repository.findByNamespace(namespace);if(oldEntity!=null){repository.delete(oldEntity);}repos

java - Spring 抛出 HttpMediaTypeNotAcceptableException : Could not find acceptable representation due to dot in url path

这个问题在这里已经有了答案:HttpMediaTypeNotAcceptableException:Couldnotfindacceptablerepresentationinexceptionhandler(2个回答)关闭5年前.最终编辑所以在研究了这个之后,因为我所看到的答案并不完全正确,我发现Spring在扩展匹配方面做了一些奇怪的事情。如果我提交这样的请求byNameOrAtlName/myStringHere.1或byNameOrAtlName/myStringHere.12一切都很好,但是byNameOrAtlName/myStringHere.123导致它像byNameO

Spring MVC 3 : How to get path variable in an interceptor?

在SpringMVCController中,我可以使用@PathVariable获取路径变量,以获取在@RequestMapping中定义的变量的值。如何在拦截器中获取变量的值?非常感谢! 最佳答案 Pao链接的帖子对我很有帮助在preHandle()方法中,您可以通过运行以下代码来提取各种PathVariablesMappathVariables=(Map)request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);

java - 带有 { } 大括号的 Spring MVC @Path 变量

我正在使用SpringBoot开发应用程序。在RESTController中,我更喜欢使用路径变量(@PathVariabale注释)。我的代码获取路径变量,但它包含{}大括号,因为它在url中。请任何人建议我解决这个问题@RequestMapping(value="/user/item/{loginName}",method=RequestMethod.GET)publicvoidgetSourceDetails(@PathVariableStringloginName){try{System.out.println(loginName);//itprintlikethis{john

java - 在 spring 中将 Path 变量绑定(bind)到自定义模型对象

我有一个模拟我的请求的类,比如classVenue{privateStringcity;privateStringplace;//Respectivegettersandsetters.}我想支持一个RESTfulURL来获取有关field的信息。所以我有这样的Controller方法。@RequestMapping(value="/venue/{city}/{place}",method="GET")publicStringgetVenueDetails(@PathVariable("city")Stringcity,@PathVariable("place")Stringplace

java - Spring Web MVC : Use same request mapping for request parameter and path variable

有没有办法表示我的SpringWebMVCController方法应该通过将ID作为URI路径的一部分提交的请求来匹配...@RequestMapping(method=RequestMethod.GET,value="campaigns/{id}")publicStringgetCampaignDetails(Modelmodel,@PathVariable("id")Longid){...或者如果客户端将ID作为HTTP请求参数以样式发送...@RequestMapping(method=RequestMethod.GET,value="campaigns")publicStrin

Spring MVC : how to indicate whether a path variable is required or not?

我正在做一个Spring网络。对于Controller方法,我可以使用RequestParam来指示是否需要参数。例如:@RequestMapping({"customer"})publicStringsurveys(HttpServletRequestrequest,@RequestParam(value="id",required=false)Longid,Mapmap)我想使用如下的PathVariable:@RequestMapping({"customer/{id}"})publicStringsurveys(HttpServletRequestrequest,@PathVa

java - 为什么在 Spring Data JPA Repository 上的 save() 之后使用返回的实例?

代码如下:@RepositorypublicinterfaceAccountRepositoryextendsJpaRepository{}JpaRepository来自SpringDataJPA项目。这里是测试代码:publicclassJpaAccountRepositoryTestextendsJpaRepositoryTest{@InjectprivateAccountRepositoryaccountRepository;@InjectprivateAccountaccount;@Test@TransactionalpublicvoidcreateAccount(){Acco

spring - 如何使用 Spring MVC 测试避免 "Circular view path"异常

我的一个Controller中有以下代码:@Controller@RequestMapping("/preference")publicclassPreferenceController{@RequestMapping(method=RequestMethod.GET,produces="text/html")publicStringpreference(){return"preference";}}我只是尝试使用SpringMVC测试来测试它,如下所示:@ContextConfiguration@WebAppConfiguration@RunWith(SpringJUnit4Clas

mysql - 毫秒精度的时间戳 : How to save them in MySQL

我必须使用MySQL开发应用程序,并且必须保存诸如“1412792828893”之类的值,这些值表示时间戳,但精度为毫秒。也就是说,自1.1.1970以来的毫秒数。我将该行声明为timestamp但不幸的是这不起作用。所有值都设置为0000-00-0000:00:00CREATETABLEIFNOTEXISTS`probability`(`id`int(11)NOTNULLAUTO_INCREMENT,`segment_id`int(11)NOTNULL,`probability`floatNOTNULL,`measured_at`timestampNOTNULL,`provider_