MyBatis中的模糊查询

Spring3.05+SpringMVC+myBatis3.26整合开发

一.Student为实体对象,有sno,sname,age三个属性;

二.:模糊查询后台代码

   1.mapper层(DAO层)

       StudentMapper.java类

          List<Student> fuzzySearch(@Param("text")String text);

             1> @Param("text")为别名;

                  2>导入Param包:import org.apache.ibatis.annotations.Param;

   2.Student.xml文件

      <sql id="Base_Column_List>

                sno,sname,age

        </sql>

        <select id="fuzzySearch" parameterType="java.lang.String"   resultMap="BaseResultMap">

               select

              <include refid="Base_Column_List"/>

              from dlsoftdb_NBG.dbo.students

              where sname like '%${text}%'

        </select>

   3.service层

    接口:studentService.java:

                public List<Student> fuzzySearch(String sname);

     实现:StuedntServiceImpl.java:

                @Service("studentService")


                @Transactional

               public List<Student> fuzzySearch(String sname){

                         return studentMapper.searchStudentList(sname);

               }

   4.Controller层

      studentController.java

        @Controller

        @RequestMapping("student")

      


        @RequestMapping({"/fuzzySearch"})

        @ResponseBody

         public String searchStudnetList(HttpServletRequest request){

                     List<Student> stu=this.studentService.fuzzySearch(request.getParameter("sname"));

                     JSONObject jsonObjects=new JSONObject();

                     jsonObjects.put("Rows",stu);

                     String message=jsonObjects.toString();

                     return message;

        }

三、模糊查询前台代码:

   ligerUI插件

   1.js代码:

     function fuzzySearch(){

            var text=$("name").val();

            $.ajax({

                 url:'/项目名称/student/fuzzySearch',

                 type:'post',

                 dataType:'json',

                 data:{sname:text},
                 cache:false,

                 success:fucntion(msg){

                       findStduent(msg);

                 }

            });

      function findStudent(data){

          $("#maingrid").ligerGrid({

                     checkbox:true, 

                     columns:[

                       {   display:'学号',

                           name:'sno',

                           width:80,

                           type:'int',

                           editor:{

                               type:'text'

                           }

                      },

                       {   display:'用户名称',

                           name:'sname',

                           width:200,

                           editor:{

                               type:'text'

                           }

                      },

                      {   display:'年龄',

                           name:'age',

                           width:150,

                           editor:{

                               type:'text'

                           }

                      }

                    ],

                 

                   enbledEdit:true,//是否允许编辑

                   clickToEdit:false,//单元格编辑状态

                   isScroll:true,//设置为false时将不会显示滚动条,高度自适应

                   data:data,//数据来源

                   enabledSort:true,//是否允许排序

                   fixedCellHeight:true,//是否固定单元格的高度

                   width:'70%',

                   height:'400px'

                });

            }

   2.<div>

         <input id="name" type="text">

         <input type="button" value="查询" οnclick="fuzzySearch()">

     </div>

                                                                  

                           

 

     



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值