首页
\
问答
\
Spring Boot Rest Controller如何返回不同的HTTP状态码?(Spring Boot Rest Controller how to return different HTTP status codes?)
Spring Boot Rest Controller如何返回不同的HTTP状态码?(Spring Boot Rest Controller how to return different HTTP status codes?)
我正在使用Spring Boot创建一个简单的REST API,并且如果某些失败,则返回一个正确的HTTP状态码。
@RequestMapping(value="/rawdata/", method = RequestMethod.PUT) @ResponseBody @ResponseStatus( HttpStatus.OK ) public RestModel create(@RequestBody String data) { // code ommitted.. // how do i return a correct status code if something fails? }
作为Spring和Spring Boot的新手,基本问题是当某件事情确定或失败时,我如何返回不同的状态代码?
I am using Spring Boot for a simple REST API and would like to return a correct HTTP statuscode if something fails.
@RequestMapping(value="/rawdata/", method = RequestMethod.PUT) @ResponseBody @ResponseStatus( HttpStatus.OK ) public RestModel create(@RequestBody String data) { // code ommitted.. // how do i return a correct status code if something fails? }
Being new to Spring and Spring Boot, the basic question is how do i return different status codes when something is ok or fails?
原文:https://stackoverflow.com/questions/24292373
更新时间:2023-03-21 10:03
最满意答案
尝试绑定访问变量,因为它似乎是您想要的数据。
using (NewEntities dc = new NewEntities()) { var visits = (from a in dc.Visits join b in dc.Clients on a.clientID equals b.clientID select new { a, b.Name,b.Surname,b.Address, }); myGridView.DataSource = visits.ToList(); myGridView.DataBind(); }
Try binding the visits variable, as it seems like that's the data you want.
using (NewEntities dc = new NewEntities()) { var visits = (from a in dc.Visits join b in dc.Clients on a.clientID equals b.clientID select new { a, b.Name,b.Surname,b.Address, }); myGridView.DataSource = visits.ToList(); myGridView.DataBind(); }
相关问答
更多-
你需要使用Department表和Lecturer表之间的连接 DataClassesDataContext tdc = new DataClassesDataContext(); var res = (from p in tdc.Lecturers join br in tdc.Departments on p.DepartmentID equals br.DepartmentID select new { ...
-
MVC GridView扩展通过内部的LinqServerModeDataSource对象在功能上支持所谓的“ 服务器模式 ”。 它需要IQueryable对象作为数据源: 直接LINQ查询: http://www.devexpress.com/issue=Q333116 @Html.DevExpress().GridView(...).BindToLINQ(string.Emptry, string.Emptry, (s, e) => { e.KeyExpression = Key_Column_Here ...
-
尝试绑定访问变量,因为它似乎是您想要的数据。 using (NewEntities dc = new NewEntities()) { var visits = (from a in dc.Visits join b in dc.Clients on a.clientID equals b.clientID select new { a, b. ...
-
我编辑的初步答案完全基于对问题的误解。 由于我不熟悉SQLite,我不确定您的Product和BrandInfo模型是通过代码生成还是手动创建的。 如果手动创建,您是否可以将BrandInfo属性添加到Product? 如果可能,您可以使用linq加入product和brandinfo模型的集合,以创建可以在GridView中绑定的集合: void Main() { List
products = new List () { new Product() {Id = ... -
Linq与两个表的实体(Linq to Entities with two tables)[2023-05-31]
如果事情设置正确,您将拥有一个代表外键关系的引用属性,在这种情况下,您应该可以执行如下操作: var q = from c in categories select new {Category = c, Products = c.Products}; If things are set up correctly you'll have a reference property that represents the foreign key relationship, in which ca ... -
从缓存表中停止linq(Stop linq from caching tables)[2022-04-08]
你是如何重新绑定网格的? 它不会缓存结果,所以我不确定为什么这是一个问题。 您必须重新查询上下文以获取新记录...或者,如果要重新绑定对象的记录(就像您绑定客户一样),您可以使用ensurihg,将订单添加到客户对象中的Orders集合中,而且不必重新查询。 所以,如果你以这种方式绑定: grid.DataSource = customer.Orders; 如果您这样做,您只会收到新订单: customer.Orders.Add(newOrder); dc.Orders.InsertOnSubmit(ne ... -
你应该绑定网格 var o = (from i in MDB.Messages select new { Subject = i.Subject, Message_Code = i.ID_Message, Question_date = i.Date, Question_Name = i.aspnet_Membership.aspnet_User.UserName }); EndInboxGrv.DataSource = o; EndInbo ...
-
在所选数据源上找不到名为“P_ID”的字段或属性 该消息是不言自明的,此属性在您使用的类中不可用,但显然您正在尝试绑定到此属性。 由于您在sql查询中选择此列,但将其分配给属性ID您应该绑定到该属性。 ID = Convert.ToInt32(xx["P_ID"]) 侧注:您可以使用逐字字符串文字,这使得在C#中编写SQL查询更容易。 我还建议使用real / ansi连接。 甚至“Oracle建议您使用FROM子句OUTER JOIN语法而不是Oracle连接运算符” 链接 。 string filte ...
-
执行查询并将结果保存到列表(或数组)。 然后将此列表分配给网格。 网格不能直接绑定到查询 GridView1.DataSource = products.ToList(); Execute query and save results to list (or to array). Then assign this list to grid. Grid cannot be bound directly to query GridView1.DataSource = products.ToList();
-
尝试将SelectCommand更改为: SELECT * from CWIPH INNER JOIN CJCMS ON CWIPH.JOB_NO=CJCMS.JOB_NO Try to change your SelectCommand to: SELECT * from CWIPH INNER JOIN CJCMS ON CWIPH.JOB_NO=CJCMS.JOB_NO