Spring - 搜索过滤器不起作用

时间:2017-07-15 04:51:14

标签: java json spring jsp

我想从数据库中搜索大学名称或大学课程。我还想对要选择的课程类别的输入应用过滤器(在jsp上选择选项)。

在输入框中输入任何值时,它会将输入框的正确值发送到DAOImpl,但在类别的情况下为null。我已经尝试使用modelAttribute以及commandName。 (参见DAOImpl中的SOP)。

如果我使用String数据类型而不是搜索,则它不会传递任何内容。

搜索“null%”

字符串“%”

我的JSP页面:

<fm:form onsubmit="return false" modelAttribute="Search">
   <div class="wrap-toggle-search floleft">
      <div class="toggle-search-category">
        <fm:select class="toggle-category" id="ccmcategory" name="ccmcategory" path="ccmcategory">
            <option value="Engineering">Engineering</option>
            <option value="Management">Management</option>
            <option value="Information Technology">Information Technology</option>
            <option value="Medical">Medical</option>
            <option value="Education">Education</option>
            <option value="Law">Law</option>
            <option value="Science">Science</option>
            <option value="Accountancy">Accountancy</option>
            <option value="Art">Art</option>
            <option value="Polytechnic">Polytechnic</option>
            <option value="Mass Communication & Journalism">Mass Communication & Journalism</option>
            <option value="Diploma/Certificate">Diploma/Certificate</option>
            <option value="Fashion Technology">Fashion Technology</option>
        </fm:select>
    </div>
        <input type="text" id="tags" name="tags" placeholder="Search College by Name or Course">
  </div>
    <div class="search-btndv">
        <input class="btn-link-default" type="submit" value="Search" />
    </div>
</fm:form>

我的JS页面:

$(document).ready(function() {
$("#tags").autocomplete({
    source : function(request, response) {
        $.getJSON("search/", request, function(result) {
            response($.map(result, function(item) {
                return {
                    label : item.cmcname,
                    value : item.cmcname,
                    link : "collegeDetail/" + item.cmuid,
                };
            }));
        });
    },
    select : function(e, ui) {
        location.href = ui.item.link;
    }
});
});

控制器:

@RequestMapping(value = "/search", method = RequestMethod.GET)
public @ResponseBody List<College> searchCourse(@RequestParam("term") String coursename, @ModelAttribute("Search") Search search) {
    List<College> collegeList = collegeDAO.getCollegeByCourse(coursename, search);
    return collegeList;
}

DAOImpl

public List<College> getCollegeByCourse(String coursename, Search search) {
    String sql = "select distinct cmuid, cmcname from campus_master join campcourse_master on cmuid=ccmcmuid where ( ccmname like '" + coursename + "%' or cmcname like '" + coursename + "%' ) and ccmcategory like '" + search.getCcmcategory() + "%' ;";
    List<College> collegeList = jdbctemp.query(sql, new BeanPropertyRowMapper<College>(College.class));
    return collegeList;
}

    System.out.println(search); //com.example.projectname.model.Search@1cc342e
    System.out.println(search.getCcmcategory()); //null
    System.out.println(sql); //select distinct cmuid, cmcname from campus_master join campcourse_master on cmuid=ccmcmuid where ( ccmname like 'm%' or cmcname like 'm%' ) and ccmcategory like 'null%' ;

模特课程:

@Id private String ccmcategory;
//GETTER
//SETTER

0 个答案:

没有答案