SSM框架学习中的问题


Spring和Mybatis整合时遇到的问题

能够按照商品名称和作者同时查询

<select id="findByCondation" parameterType="cn.pojo.Product" resultType="cn.pojo.Product">
        select productid,name,baseprice,writer from product where 1=1
        <if test="name != null and name!=''">
            and name like '%${name}%'
        </if>
        <if test="writer !=null and writer!=''">
            and writer like'%${writer}%'
        </if>

controller中的方法

@RequestMapping("/queryAll.do")
public String queryByCondation(Product product){
    List<Product> list = service.findByCondation(product);
    String json=JSON.toJSONString(list);
    System.out.println(json);
    return json;
}

> jsp页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="jquery-1.8.2.min(1).js"></script>
    <script>
        function a1() {
            $.ajax({
                type:"post",
                url:"queryAll.do",
                data:"name="+$("#name").val()+"&writer="+$("#writer").val()+"&baseprice="+$("#baseprice").val(),
                dataType:"json",
                success: function (result) {
                    var shus=result;
                    $("#table").empty()
                    $("#table").append( "<tr>"+"<td>序号</td>"+
                        "<td>商品名称</td>"+
                        "<td>价格</td>"+
                        "<td>出版社</td>"+"</tr>")
                    for (var i in shus){
                        var item=shus[i]
                        var name=item.name
                        var writer=item.writer
                        var baseprice=item.baseprice
                        var id=item.productid
                        $("#table").append(
                                        "<tr>"+"<td>"+id+"</td>"+
                                         "<td>"+name+"</td>"+
                                         "<td>"+baseprice+"</td>"+
                                         "<td>"+writer+"</td>"+
                        "<td><input type='button' value='删除' οnclick='del("+id+")'></td>"+
                            "<td><input type='button' value='修改' οnclick='upd("+id+")'></td>"+"</tr>")
                    }
                }
            })

        }

        function del(id) {
            $.ajax({
                type:"post",
                data: "id="+id,
                // data: {"id":id},
                url: "delete.do",
                dataType: "json",
                success:function (result) {
                    if (result.boo){
                        location="query.jsp"
                    }
                }
            })

        }

        function upd(id) {
            //?问号传参后面的键值对要紧挨着
            location = "update.jsp?id="+id;


        }
    </script>
</head>
<body>
请输入商品名称:<input type="text" id="name" value=""><br>
请输入价格:<input type="text" value="" id="baseprice"><br>
请输入作者:<input type="text" value="" id="writer"><br>
<input type="button" onclick="a1()" value="查询">
<form>
    <table border="1" id="table">


    </table>
</form>

</body>

运行后报错

[WARNING] Resolved [org.springframework.validation.BindException:
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object ‘product’ on field ‘baseprice’: rejected value
[]; codes
[typeMismatch.product.baseprice,typeMismatch.baseprice,typeMismatch.double,typeMismatch];
arguments
[org.springframework.context.support.DefaultMessageSourceResolvable:
codes [product.baseprice,baseprice]; arguments []; default message
[baseprice]]; default message [Failed to convert property value of
type ‘java.lang.String’ to required type ‘double’ for property
‘baseprice’; nested exception is java.lang.NumberFormatException:
empty String]]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值