내가 원하는 것은 JDBC 연결과 Spring MVC를 사용하여 MS 액세스 데이터베이스에 직원 데이터를 추가하는 것입니다. 나는 Employee (기본적으로 모델) 클래스, Employee에 대한 세부 정보를 입력하는 폼, 확실하지 않은 컨트롤러, web.XML 및 dispatcher-servlet.XML 클래스를 가지고있다. 필자는 문서를 읽었으나 데이터베이스에 데이터를 추가하는 방법을 정확하게 알지 못합니다. 더 많은 수업이나 방법이 필요합니까? applicationcontext 작성이 필요합니까? 좋은 링크 나 일부 코드에서 스프링 MVC를 사용하여 데이터베이스에 추가 된 양식에 입력 된 데이터를 얻을 수있는 곳을 알려주십시오. 내가 지금까지 작성한 코드는 다음과 같습니다Spring MVC의 데이터 흐름에 대해 혼동 스럽습니다.
EmployeeModel.java
package models.app;
public class EmployeeModel {
String emp_id;
String fname;
String lname;
String password;
String e_mail;
int actinout;
String profile;
int offshore;
public int getOffshore() {
return offshore;
}
public void setOffshore(int offshore) {
this.offshore = offshore;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getE_mail() {
return e_mail;
}
public void setE_mail(String e_mail) {
this.e_mail = e_mail;
}
public int getActinout() {
return actinout;
}
public void setActinout(int actinout) {
this.actinout = actinout;
}
public String getEmp_id() {
return emp_id;
}
public void setEmp_id(String emp_id) {
this.emp_id = emp_id;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
양식 페이지 :
<form:form modelAttribute="EmployeeModel" method="POST" action="/jsp/DojoContentPanes.jsp">
<div id= "addemployeedivid">
<center><table>
<tr style="height: 50px">
<td style="width: 150px"><b>EMPLOYEE ID : </b></td>
<td style="width: 600px"><form:input path="pathid" dojoType="dijit.form.ValidationTextBox" id="employeeidid"/>
<span dojoType="dijit.Tooltip" connectId="employeeidid">Enter Name</span></td>
<td style="width: 150px" ><b>OFFSHORE : </b></td>
<td style="width: 600px"><form:input path="pathoffshore" dojoType="dijit.form.ValidationTextBox" id="offshoreid"/>
<span dojoType="dijit.Tooltip" connectId="offshoreid">Enter Name</span></td></tr>
<tr style="height: 50px">
<td style="width: 150px"><b>E-MAIL ID : </b></td>
<td style="width: 600px"><form:input path="pathemail" dojoType="dijit.form.ValidationTextBox" id="emailidid"/>
<span dojoType="dijit.Tooltip" connectId="emailidid">Enter ID</span></td>
<td style="width: 150px"><b>PROFILE : </b></td>
<td style="width: 600px"><form:input path="pathprofile" dojoType="dijit.form.ValidationTextBox" id="profileid"/>
<span dojoType="dijit.Tooltip" connectId="profileid">Enter Name</span></td></tr>
</table></center><br><br>
<center><input type="submit" value= "addemployee"></center>
</div>
</form:form>
web.xml을
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
디스패처-servlet.xml에
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
ManageEmployeeController.java는
package controller.web;
import models.app.EmployeeModel;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class ManageEmployeeController {
@RequestMapping(value = "/jsp/DojoContentPanes.jsp", method = RequestMethod.POST)
public void addemployee(@ModelAttribute("EmployeeModel") EmployeeModel obj, Model model){
System.out.println(obj.getEmp_id());
}
}
난 내가 컨트롤러를 제대로 작성하지 않은 것을 알고있다. 내가 여기서하려고하는 것은 단순히 양식을 통해 얻는 가치를 인쇄하는 것입니다. 양식을 제출할 때와 양식을 컨트롤러에서 수신 할 때 양식 작업 속성에서 URL을 올바르게 전달하는 방법을 알려줄 수 있습니까? 감사합니다