我这里有这段代码可通过AWS部署。 和我在AWS上进行测试的问题如下:
当我按如下方式将值传递给x时:
“ x”:1.0或“ x”:100.0 .... etc(小数部分为零) 它被视为整数,错误表示“ errorMessage”:此行中的“ java.lang.Integer无法转换为java.lang.Double” x_Ptr [i] = str.get(i).doubleValue();
如果x通过分数等于“ x”的分数:1.5或“ x”的分数:0.444,则它有效
这里有什么建议吗?
public class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {
private static final Logger LOG = Logger.getLogger(Handler.class);
@Override
public ApiGatewayResponse handleRequest(Map<String, Object> event, Context context) {
LOG.info("received: " + event);
List<Double> str = new ArrayList<Double>();
str = (ArrayList<Double>)(event.get("x"));
double[] x_Ptr = new double[str.size()];
for (int i = 0; i < x_Ptr.length; i++) {
x_Ptr[i] = str.get(i).doubleValue();
}
System.out.println(x_Ptr[0]);
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
Output bodyout = new Output(x_Ptr);
return ApiGatewayResponse.builder()
.setStatusCode(200)
.setObjectBody(bodyout)
.setHeaders(headers)
.build();
}
}
答案 0 :(得分:0)
为输入类型定义一个POJO,问题是反序列化时类型信息不可用,并且可以从数据中推断出来。
public partial class admin_category : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True");
SqlDataSource sd = new SqlDataSource();
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(" insert into Men Category (CategoryName) values (@CategoryName)",con);
cmd.Parameters.AddWithValue("@CategoryName",Cat_nm.Text);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Category Added Sucessfully');</script>");
}
}