1
저는 컴퓨터 프로그래밍 세계에 대해 완전히 새롭기 때문에 많은 개념을 깊이있게 이해하는 데 어려움을 겪고 있습니다. 지금 당장 저는 Spring MVC를 구현하는 프로젝트를 진행하고 있습니다. 프로젝트의 첫 번째 단계는 웹 사이트의 로그인 페이지를 만드는 것입니다. 나는 우리가 수업 시간에했던 한 후 모델링 광산을 시도했습니다,하지만 난 내 웹 브라우저에서 다음과 같은 오류 과거를 얻을 수없는 것 :스프링 MVC 오류
package injuryReports;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Login implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private String userName;
private String password;
private int userId;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Login() {
}
public Login(String userName, String password) {
super();
this.userName = userName;
this.password = password;
}
public Login(int userId, String userName2, String password2) {
this.userId = userId;
this.userName = userName2;
this.password = password2;
}
}
: 여기
Unsupported auto value type java.lang.String for field injuryReports.Login.userName
내 로그인 엔티티 클래스입니다
내 LoginDao 등급 :
package injuryReports;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author nGent
*
*/
@Component
public class LoginDao {
@PersistenceContext private EntityManager em;
@Transactional
public void persist(Login user) {
em.persist(user);
}
public List<Login> getAllUsers() {
TypedQuery<Login> query = em.createQuery(
"Select u FROM Login u ORDER BY u.id", Login.class);
return query.getResultList();
}
public Login validateLogin(String userName, String password) {
Login login = null;
TypedQuery<Login> query = em.createQuery(
"Select u From Login u where u.userName = :userName " +
" and u.password = :password", Login.class).setParameter(
"userName", userName).setParameter("password", password);
try {
login = query.getSingleResult();
}
catch (Exception e) {
//TODO: Handle Exception
}
return login;
}
}
그리고 내 인 LoginController 클래스 :
package injuryReports;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class LoginController {
@Autowired
private LoginDao loginDao;
@RequestMapping(value = "/user", method = {RequestMethod.POST})
public ModelAndView userEntry(HttpServletRequest request) {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
if (userName != "" && password != "") {
loginDao.persist(new Login(userName, password));
}
return new ModelAndView("logon.jsp", "loginDao", loginDao);
}
@RequestMapping(value = "/login")
public ModelAndView login(HttpServletRequest request) {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String page = "login.jsp";
if (userName != "" && password != "") {
try {
Login login = loginDao.validateLogin(userName, password);
if (login != null) {
request.getSession().setAttribute("UserId", login.getUserId());
page = "login.jsp";
}
}
catch (Exception e) {
//TODO: Handle Exception
}
}
return new ModelAndView(page, getDaos());
}
@RequestMapping(value = "/logon", method = {RequestMethod.GET})
public ModelAndView logon(HttpServletRequest request) {
//int userId = (Integer) request.getSession().getAttribute("userId");
//request.getSession().setAttribute("UserID", userId);
return new ModelAndView("logon.jsp", getDaos());
}
public Map<String, Object> getDaos() {
Map<String, Object> models = new HashMap<String, Object>();
models.put("loginDao", loginDao);
return models;
}
}
죄송합니다. 약간 길기 때문에 최대한 많은 정보를 제공해 드리고자합니다. 나는 정말 어떤 도움을 주셔서 감사합니다!
; ...,'userId' 필드를 사용하십시오. –