私はclientDAOインターフェイスとclientDaoImplクラスを持っています。私はclientDAOでメソッドを宣言し、clientDaoImplでメソッドを定義しました。また、spring-servlet.xml(spring-configファイル)のmysqlデータベース接続をデータソースとして定義します。どのようにDAOメソッドを使用してデータベースにデータを挿入するのですか?
import java.util.Date;
import org.springframework.stereotype.Controller;
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.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
@SessionAttributes
@Controller
public class clientRegistrationController {
@Autowired
private clientDAO clientdao;
@SessionAttributes
@Controller
public class ClientRegistrationController {
@RequestMapping(value="/registration",method = RequestMethod.POST)
public @ResponseBody
String client_registration(@RequestParam(value = "date_of_registration") Date date_of_registration)
// here i want to get pojo object and call method insert method which is
// defined in DAO implement class.
return " Registered successfully";
}
@RequestMapping("/registration")
public ModelAndView showContacts() {
String message = "Hello World, Spring MVC @ Javatpoint";
return new ModelAndView("client_registration", "message",message);
}
}
私は、次のエラーました:私はこれが私のclientdaoあるjavatpoint.com で利用可能/ SpringTilesコードを使用
SEVERE: Servlet [spring] in web application [/SpringTiles] threw load() exception
java.lang.Error: Unresolved compilation problems:
Autowired cannot be resolved to a type
clientDAO cannot be resolved to a type
を:
パッケージDAO。
import com.javatpoint.form.Client_Registration;
public interface clientDAO {
void insertData(Client_Registration patient);
}
は、文脈があるclientDAO –
私達にあなたのクラスを表示しますか? –
コンポーネントスキャンにclientDAOのパッケージを含める必要があります –