java后台接收数据

1、getParameter来获取数据

int userId = Integer.parseInt(this.getgetParameter().getParameter("userId"));
        int tieId = Integer.parseInt(this.getRequest().getParameter("tieId"));

2、java前台–》后台的接收:JSP中直接用属性名称来提交数据:
///后台

@Component(value="tanWeiAction")
public class TanWeiAction extends BaseAction{
    private Ttanwei tanwei;

    public Ttanwei getTanwei() {
        return tanwei;
    }
    public void setTanwei(Ttanwei tanwei) {
        this.tanwei = tanwei;
    }
/**
     * 添加摊位
     */
    public void addTanWei(){
        tanwei.setIsValid(true);
        tanwei.setBeiZhu("");
        tanwei.setCatagoryId(0);
        tanwei.setImgUrl("");
        tanwei.setTanWeiName("");

        int result=this.tanWeiService.addTanWei(tanwei);

        if(result>0){
            MSG="OK";
        }else{
            MSG="NO";
        }
        this.writeJson(MSG);
    }

/前台:

<form id="tanWeiform" method="post" style="margin:0 auto;">
                <input id="tanweiId" name="tanwei.id" type="hidden" /> <input
                    id="imgUrl" name="tanwei.imgUrl" type="hidden" />
                <table style="margin:0 auto">
                    <tr>
                        <th>商品类别:th>
                        <td><input name="tanwei.catagoryId" id="catagoryTree"
                            class="easyui-combotree" data-options="required:true">
                        td>
                    tr>
                    <tr>
                        <th>摊位名称:th>
                        <td><input name="tanwei.tanWeiName" id="rname"
                            class="easyui-validatebox" data-options="required:true">
                        td>
                    tr>

                table>
            form>

3、使用实体类来接收:APP前台发送数据
/字段名要一致!

Tsignature ts = new Tsignature();
        ts.setIsValid(true);
        ts.setSignatrue(encodingFunction.getMethodEncoding(user.getSignature()));
        ts.setUserId(user.getId());
        int i = this.userService.addUserSignature(ts);

实现:ModelDriven

@Component(value = "userAction")
public class UserAction extends BaseAction implements ModelDriven<User> {

    private User user = new User();
    @Override
    public User getModel() {
        return user;
    }
    }

你可能感兴趣的:(java笔记)