我正在构建一个CRUD应用程序,使用embers作为客户端,struts2作为服务器。从ember创建记录的post请求如下所示,
接受:application/json、text/javascript、/;q=0.01接受编码:gzip,deflate,br接受语言:en-GB,en-US;q=0.9,en;q=0.8连接:保持活动内容长度:54内容类型:应用程序/json;字符集=UTF-8主机:本地主机:8080源:http://localhost:4200推荐人:http://localhost:4200/createSec Fetch模式:cors Sec Fetch站点:同一站点用户代理:Mozilla/5.0(Macintosh;Intel Mac OS X 10\u 13\u 3)AppleWebKit/537.36(KHTML,如Gecko)Chrome/79.0.3945.88 Safari/537.36{产品:{“名称”:“iamironman”,“价格”:3000}产品:{“名称”:“iamironman”,“价格”:3000}”
余烬请求有效载荷
Struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="default"/>
<constant name="struts.convention.package.locators" value="controller"/>
<constant name="struts.rest.content.restrictToGET" value="false"/>
<package name="default" namespace="/" extends="rest-default,json-default">
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
<interceptor-stack name="myStack">
<interceptor-ref name="json">
<param name="jsonContentType">application/json</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack" />
<global-allowed-methods>index,show,create,update,destroy</global-allowed-methods>
<action name="products/*" class="controller.ProductsController">
<interceptor-ref name="myStack" />
<result name="index" type="json"></result>
</action>
</package>
</struts>
动作类:
package controller;
import java.util.List;
//import javax.servlet.http.HttpServletRequest;
import dao.Productdao;
import model.product;
//import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import com.opensymphony.xwork2.ModelDriven;
//@InterceptorRef(value="json")
public class ProductsController implements ModelDriven<Object>{
//private static final Logger log = LogManager.getLogger(ProductsController.class);
product p=new product();
Productdao dao=new Productdao();
private List<product> productlist=dao.getAllProduct();
private int id;
private String name;
private double price;
//private HttpServletRequest request;
//private JSONObject Object;
public HttpHeaders show()
{
System.out.println("Showing");
p=dao.getProduct(id);
return new DefaultHttpHeaders("show");
}
public HttpHeaders index() {
System.out.println("i am inside index");
return new DefaultHttpHeaders("index").disableCaching();
}
public String create()
{
System.out.println("order creation : "+name+price);
boolean result=dao.createProduct(name,price);
if(result)
{
System.out.println("product created successfully");
return "success";
}
else
{
System.out.println("product Not created");
return "increated";
}
}
public String update()
{
System.out.println("inside update"+id+name+price);
p.setId(id);
p.setName(name);
p.setPrice(price);
boolean result=dao.updateProduct(p);
if(result)
{
System.out.println("product updated successfully");
return "success";
}
else
{
System.out.println("product not updated");
return "inupdated";
}
}
public String destroy()
{
System.out.println("inside destroy"+id);
boolean result=dao.deleteProduct(id);
if(result) {
System.out.println("deleted successfully");
return "success";
}
else
{
System.out.println("Not deleted");
return "indeleted";
}
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
/*public JSONObject getObject() {
return Object;
}
public void setObject(JSONObject object) {
Object = object;
}
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}*/
@Override
public Object getModel() {
System.out.println("getting model");
return productlist;
}
}
错误:
java.sql.SQLIntegrityConstraintViolationException: Column 'name' cannot be null
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
at dao.Productdao.createProduct(Productdao.java:40)
at controller.ProductsController.create(ProductsController.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at ognl.OgnlRuntime.invokeMethodInsideSandbox(OgnlRuntime.java:1226)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:1211)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1920)
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:98)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:90)
at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1996)
at ognl.ASTMethod.getValueBody(ASTMethod.java:91)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.Ognl.getValue(Ognl.java:537)
at ognl.Ognl.getValue(Ognl.java:501)
at com.opensymphony.xwork2.ognl.OgnlUtil$3.execute(OgnlUtil.java:492)
at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecuteMethod(OgnlUtil.java:544)
at com.opensymphony.xwork2.ognl.OgnlUtil.callMethod(OgnlUtil.java:490)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:438)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:293)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:250)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:179)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:49)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.doIntercept(ConversionErrorInterceptor.java:142)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:137)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:137)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:201)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:67)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:133)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:101)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:142)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:160)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:175)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:99)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:121)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:167)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:203)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:196)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at org.apache.struts2.json.JSONInterceptor.intercept(JSONInterceptor.java:185)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:130)
at com.opensymphony.xwork2.DefaultActionProxy.execute(DefaultActionProxy.java:157)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:574)
at org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:79)
at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:141)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.filters.CorsFilter.handleSimpleCORS(CorsFilter.java:259)
at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:163)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
我做错了什么。提前感谢...!
结果是,我只需要在发送时在客户端序列化我的儿子。
serializeIntoHash(哈希,类型,记录,选项){Ember.assign(哈希,this.serialize(记录,选项));}
这让儿子
{产品:{"名称":"iaminonman","价格": 3000.0}}
到
{“name”:“iaminonman”,“price”:3000.0}
我知道这个话题已经贴了很多次了,但这个问题没有真正的解决办法。 最近,在一些应用程序中,我决定进行更新。这是将库版本(admob)更改为最新版本的一次小更新。我还将targetSdkVersion从25更改为26。几天后,我检查了admob上的统计数据,所有这些应用的填充率都降到了0!请求的数量也增加了。用于横幅和间隙。其他应用程序不受影响。 我认为有一些愚蠢的错误,但我在代码中找不到任何问题。
我遇到了以下问题:当手机应该输入时,我需要实现这种情况的解决方案。这部手机应该有不可移动的部分,最后四个数字应该在开头填写下划线,然后当用户键入下划线时,应该将其更改为数字,例如: < code> 12345____ - 我实现了不可移除的部分。我是这样做的: 但现在我不明白,如何处理下划线的逻辑。我尝试在< code>doAfterTextChanged中添加下划线,比如if
假设我有这样一个模型 和这样的文档。 如果我执行以下操作,页面将永远不会加载。 如果里面有一个实际的ObjectID,它可以正常工作,但当它是空白的时候就不行了。 如果值中没有ObjectID,是否有一种方法可以默认为null?
当创建一个应用时,你将会想将多个控件放入一个窗口控件。我们的第一个 helloworld 范例仅仅使用了一个控件,因而我们可以只是简单地调用一个gtk_container_add()将控件填充到一个窗口控件。但是当你想要向窗口控件中放置超过一个控件时,控制每一个控件的位置和大小就变得很重要了。这就是接下来要讲的填充。 GTK+自带了大量各种布局的容器,这些容器的目的是控制被添加到他们的子控件的布局
主要内容:创建索引在本节中,我们将向Elasticsearch添加一些索引,映射和数据。此数据将用于本教程中解释的示例中。 创建索引 请求正文 它可以包含索引特定的设置,但是现在,它的默认设置为空。 响应 这意味着创建索引成功 创建映射和添加数据 Elasticsearch将根据请求体中提供的数据自动创建映射,我们将使用其批量功能在此索引中添加多个JSON对象。 请求体 响应结果 - 添加另一个索引 创建索引 请求
元素用于在其内容周围添加填充或额外空间。 它可以用于调整大小和定位,例如负填充,这可能导致mpadded的内容与相邻内容的呈现重叠。 语法 (Syntax) 以下是使用此标记的简单语法 - <mpadded> expression </mpadded> 参数 (Parameters) 以下是此标记的所有参数的说明 - expression - 推断多个孩子的分娩。 属性 (Attributes)