SpringMvc 프레임 워 크 (컨트롤 러)
8507 단어 자바
package test1;
import java.util.Date;
public class User {
private int id;
private String name;
private double sal;
private Date hiredate;
......
}
프로필 웹. xml
demo1
DispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
DispatcherServlet
*.action
CharactorFilter
test.CharactorFilter
encoding
UTF-8
CharactorFilter
/*
프로필 springmvc. xml
페이지
Insert title here
정상 컨트롤 러 파일
package test1;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloAction {
/*
*
* /hello.action,a.action,b.action , HelloAction hello()
* value=
* */
@RequestMapping(value= {"/hello.action","/a.action","/b.action"})
public String hello(Model model) throws Exception{
model.addAttribute("message","hello,helli,hello");
//
return "success";
}
@RequestMapping(value= {"/bye.action","/c.action","/d.action"})
public String bye(Model model) throws Exception{
System.out.println(" /hello.action , HelloAction hello() ");
model.addAttribute("message","bye,bye,bye");
//
return "success";
}
}
매개 변수 수집
package test1;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value="/user")
public class UserAction {
/*
*
*
*
1) , ,springmvc
*
* , GET POST
1) , GET POST
* */
@RequestMapping(value="/register",method=RequestMethod.POST)
public String register(Model model,String username,Double salary) throws Exception{
System.out.println(username+":"+salary);
model.addAttribute("message", " ");
return "success";
}
/*
*
* */
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(Model model,String username,Double salary) throws Exception{
System.out.println(username+":"+salary);
model.addAttribute("message", " ");
return "success";
}
/*
* Request,Response web
1) web , ,
* */
@RequestMapping(value="/registerANDlogin")
public void registerANDlogin(HttpServletRequest request,HttpServletResponse response) throws Exception{
request.getParameter("username");
request.getParameter("salary");
response.sendRedirect(request.getContextPath()+"/register.jsp");
}
/*
* User,Admin
1) 1
2)
3) Model ,Model
* */
@InitBinder
protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(
Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(User user,Model model) throws Exception {
System.out.println(user.getId()+":"+user.getName()+":"+user.getSal()+":"+user.getHiredate());
model.addAttribute("user",user);
return "login";
}
/*
* User
0
1) , user.name admin.name
2) User Admin
* */
@RequestMapping(value = "/User", method = RequestMethod.POST)
public String add(Bean bean,Model model) throws Exception {
System.out.println(bean.getUser());
//System.out.println(bean.getAdmin());
System.out.println("PersonAction::add()::POST");
model.addAttribute("bean",bean);
return "/success.jsp";
/*
* :
* ${bean.user.id }
* */
}
/*
*
* */
@RequestMapping(value="/delete")
public String deleteMethod(int[] ids,Model model) throws Exception{
System.out.println("UserAction::deleteMethod()");
System.out.println(" id :");
for(int id : ids){
System.out.print(id+" ");
}
model.addAttribute("message"," ");
return "/success.jsp";
}
package test1;
public class Bean {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.