gpt4 book ai didi

java - Spring MVC 和 jQuery 自动完成

转载 作者:行者123 更新时间:2023-12-01 05:42:06 26 4
gpt4 key购买 nike

我在我的项目中使用自动完成 Jquery,但我无法得到建议。当我尝试在文本字段中写入内容时,什么也没有发生!!.

代码如下:

fournisseur.jsp

<div>
<input type="text" id="w-input-search" value="">
<span><button id="button-id" type="button">Search</button></span>
</div>

<script type="text/javascript">
$(document).ready(function() {
$('#w-input-search').autocomplete({
serviceUrl: '${pageContext.request.contextPath}/gestionFournisseur/getFournisseur.do',
paramName: "fournisseurName",
delimiter: ",",
transformResult: function(response) {

return {
//must convert json to javascript object before process
suggestions: $.map($.parseJSON(response), function(item) {

return { value: item.referenceFournisseur, data: item.idFournisseur };
})

};

}

});

});
</script>

我的 Controller :

package com.agro.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.agro.model.Fonction;
import com.agro.model.Fournisseur;
import com.agro.model.Pays;
import com.agro.model.PersonneContacter;
import com.agro.service.FonctionService;
import com.agro.service.FournisseurService;
import com.agro.service.PaysService;
import com.agro.service.PersonneContacterService;



@Controller
@RequestMapping(value="/gestionFournisseur")
public class FournisseurController {
public List<Fournisseur> listeFournisseur;

@Autowired
PaysService paysService;

@Autowired
FournisseurService fournisseurService;

@Autowired
FonctionService fonctionService;

@Autowired
PersonneContacterService personneContacterService;



@RequestMapping(value="/listeFournisseur")
public String index(ModelMap model){

listeFournisseur= fournisseurService.getAllFournisseur();
List<Pays> listePays = paysService.getAllPays();
List<Fonction> listeFonction = fonctionService.getAllFonction();

model.addAttribute("listeFourn", listeFournisseur);
model.addAttribute("listePays", listePays);
model.addAttribute("listeFonc", listeFonction);
return "fournisseur";
}

@RequestMapping(value="/addFournisseur", method = RequestMethod.GET)
public @ResponseBody String addFournisseur(String referenceFournisseur,String raisonSocial,String adresse,String adresse2,String tel, String tel2,String fax, String mail,String idPays,
String nomContact,String prenomContact,String telContact, String mailContact, String remarqueContact, String idFonction ){

Pays py = paysService.getPaysById(Integer.parseInt(idPays));
Fonction fctn = fonctionService.getFonctionById(Integer.parseInt(idFonction));

Fournisseur fourn = new Fournisseur(py, referenceFournisseur, raisonSocial, adresse, adresse2, tel, tel2, fax, mail);
PersonneContacter prsnContact = new PersonneContacter(fctn, fourn, nomContact, prenomContact, telContact, mailContact, remarqueContact);

fournisseurService.addFournisseur(fourn);
personneContacterService.addPersonneContacter(prsnContact);

return "ok";
}

@RequestMapping(value = "/getFournisseur", method = RequestMethod.GET)
public @ResponseBody List<Fournisseur> getFournisseur(@RequestParam String fournisseurName){
System.out.println("je suis dans getFournisseur");
List<Fournisseur> result = new ArrayList<Fournisseur>();

for(Fournisseur fourni : listeFournisseur){
if(fourni.getReferenceFournisseur().contains(fournisseurName)){
result.add(fourni);
}
}

return result;
}

}

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Agro</groupId>
<artifactId>Agro</artifactId>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>

<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
<jackson.version>1.9.10</jackson.version>
</properties>


<dependencies>

<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>

<!-- Apache Commons IO -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>

<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>

<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<!-- Base de donnee -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.5.Final</version>
</dependency>

<!-- need this for @Configuration -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

请问有人可以告诉我它到底是如何工作的吗?谢谢!

最佳答案

${pageContext.request.contextPath}/gestionFournisseur/getFournisseur.do

您没有 getFournisseur.do 的任何处理程序映射,但 getFournisseur 除外。去掉那个.do,它应该可以工作。

关于java - Spring MVC 和 jQuery 自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30118028/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com