复杂更新Sql语句(Complex Update Sql Statement)
我有两个表,一个表有一个
id
和一个username
名表的名称是user
。 我有另一个名为value
表,表有一个id
,用于存储来自user
表的id。 表value
还有一个名为value
的列和item_id
,用于存储项目。我想写一个update语句来更新value
id, value, item_id
中的以下列id, value, item_id
但是我必须执行语句的值是username = $username, value = $value and item_id=$item_id
(基于应用程序)如何编写存储
id
(用户名id),value
和item_id
的更新语句使用更新语句的原因是因为该用户可以随时更改
value
列中的value
I have two tables one table has an
id
and ausername
the name of the table isuser
. I have another table calledvalue
that table has anid
which is to store the id from theuser
table. The tablevalue
also has a column calledvalue
anditem_id
which is used to store the item.I want to write an update statement that updates the following columns within value
id, value, item_id
however the values I have to execute the statement isusername = $username, value = $value and item_id=$item_id
(based on the application)How can I write an update statement that stores the
id
(username id),value
anditem_id
The reason for using an update statement is because that user can change the value within the
value
column at any time
原文:https://stackoverflow.com/questions/17094268
最满意答案
我找到了一个解决方案,但我不确定为什么这会产生问题。 如果您知道为什么会这样,请发布您的答案。
问题是
@EnableWebMvc
注释@Configuration // @EnableWebMvc @Import(MyServiceConfiguration.class) public class MyRestServiceConfiguration { }
删除后,一切正常。
从Spring Boot指南:
通常你会为Spring MVC应用程序添加@EnableWebMvc,但Spring Boot会在类路径上看到spring-webmvc时自动添加它。 这会将应用程序标记为Web应用程序并激活关键行为,例如设置DispatcherServlet。
很明显,
@EnableWebMvc
注释,但为什么会出现问题呢?编辑:
从Spring Boot参考:
完全控制MVC配置的最简单方法是使用@EnableWebMvc注释提供您自己的@Configuration。 这将使所有MVC配置保留在您的手中。
来自Spring的
@EnableWebMvc
文档:将此批注添加到@Configuration类可从WebMvcConfigurationSupport导入Spring MVC配置,例如:
@Configuration @EnableWebMvc @ComponentScan(basePackageClasses = { MyConfiguration.class }) public class MyWebConfiguration { }
所以,问题是
@EnableWebMvc
注释无法解决Spring Boot的默认配置,因为Spring不知道在哪里寻找静态资源。 如果我出错了,请纠正我。I have found a solution, but I am not really sure why this makes problem. Please post your answer if you know why is this happening.
The problem was
@EnableWebMvc
annotation inMyRestServiceConfiguration
@Configuration // @EnableWebMvc @Import(MyServiceConfiguration.class) public class MyRestServiceConfiguration { }
After removing it, everything works as it should.
From Spring Boot guide:
Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.
It's clear that
@EnableWebMvc
annotation is not needed, but why does it make problems?EDIT:
From Spring Boot reference:
The easiest way to take complete control over MVC configuration is to provide your own @Configuration with the @EnableWebMvc annotation. This will leave all MVC configuration in your hands.
From Spring's
@EnableWebMvc
documentation:Adding this annotation to an @Configuration class imports the Spring MVC configuration from WebMvcConfigurationSupport, e.g.:
@Configuration @EnableWebMvc @ComponentScan(basePackageClasses = { MyConfiguration.class }) public class MyWebConfiguration { }
So, the problem was that
@EnableWebMvc
annotation dissabled default Spring Boot's configuration and because of that Spring didn't know where to look for static resources. If I got something wrong, please correct me.
相关问答
更多-
根据Thymeleaf开发人员的说法, Thymeleaf使用RequestDataValueProcessor接口来查找额外隐藏的字段,这些字段会自动添加到表单后面。 org/thymeleaf/spring3/processor/attr/SpringActionAttrProcessor.java中的以下代码显示了这一点。 final Map
extraHiddenFields = RequestDataValueProcesso ... -
使用JSP作为视图引擎注销的spring boot安全性不起作用(spring boot security using JSP as view engine logout does not work)[2021-10-16]
如文档中所述 ,默认情况下启用CSRF保护。 这意味着,只有post请求才能访问/logaout 。 并且帖子请求必须包含CSRF令牌。 所以,你可以做以下事情: 这个表 ... -
我找到了一个解决方案,但我不确定为什么这会产生问题。 如果您知道为什么会这样,请发布您的答案。 问题是@EnableWebMvc注释 @Configuration // @EnableWebMvc @Import(MyServiceConfiguration.class) public class MyRestServiceConfiguration { } 删除后,一切正常。 从Spring Boot指南: 通常你会为Spring MVC应用程序添加@EnableWebMvc,但Spring ...
-
好吧,我最终发现这里发生的事情是由于一个非常简单的疏忽造成的。 我在一个单独的模板中有...部分,并将其包含在其他模板中,如下所示; #include("/pages/common/header.vm") 那么,对于速度的用户来说,很明显上面只是按原样包含模板(即所有内容都被翻译为文本)并且不会解析其中声明的任何速度上下文属性。 所以我只需要将其更改为以下内容 #parse("/pages/common/header.vm") 这可以确保在header.vm模板中声明的任何ve ...
-
如果你用一些模板引擎(例如百里香叶)使用弹簧靴。 您不需要默认设置spring.mvc.view.prefix或spring.mvc.view.suffix 。 您只需将您的模板文件放在src/main/resources/templates/目录下: 你的控制器将会是这样的: @GetMapping("/temp") public String temp(Model model) { model.addAttribute("attr", "attr"); return "index"; } ...
-
我认为这个问题与没有正确下载的损坏的依赖关系有关。 我删除了我的整个.m2文件夹并运行了mvn spring-boot:run再次mvn spring-boot:run ,并且一切正常。 I think the issue was related to a corrupted dependency that did not get downloaded properly. I deleted my entire .m2 folder and ran mvn spring-boot:run again, an ...
-
我已经遇到过这个错误。 我相信你正在扩展错误的课程。 检查此链接 您需要将您的类扩展到此SpringBootServletInitializer @EnableAutoConfiguration @EnableWebMvc @ComponentScan({"org.app.genesis.client.controller","org.app.genesis.commons.service", "org.app.app.commons.security","org.app.genesis.inven ...
-
如何在Spring Boot中创建Apache POI Excel视图配置(How to create Apache POI Excel View Configuration in Spring Boot)[2023-05-24]
使用Spring Boot,你不需要任何额外的配置来生成一个excel文件。 使用AbstractExcelView创建一个返回ModelAndView的控制器: @Controller public class MyController { @RequestMapping(value="/myexcel", method=RequestMethod.GET) public ModelAndView getMyData(HttpServletRequest request, HttpSer ... -
我建议你确保使用最新版本的SpringBoot(在你的pom.xml中):
org.springframework.boot spring-boot-starter-parent 1.4.2.RELEASE < ... -
它自己说的错误就足够了:在类com.example.Journal没有创建createdAsShort这样的字段。 根据你所展示的,你班上肯定没有这样的领域。 The error it self says enough: there is no such field createdAsShort in class com.example.Journal. According to what you've shown definitely there is no such field in your clas ...