错误:
java.lang.IllegalStateException: Autowired annotation requires at least one argument: public main.java.com.springapp.mvc.controller.DSLRServletController()
DSLRServletController:
package main.java.com.springapp.mvc.controller;
import main.java.com.springapp.mvc.dao.DSLRDAO;
import main.java.com.springapp.mvc.model.DSLR;
import main.java.com.springapp.mvc.pckg.DSLRForm;
import main.java.com.springapp.mvc.pckg.DSLRValidaor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
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;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
@Controller
public class DSLRServletController {
static Logger logger = Logger.getLogger(DSLRServletController.class);
private DSLR DSLR;
private DSLRDAO dslrDAO;
private DSLR dslr;
@Autowired
public DSLRServletController() {
this.dslrDAO = new DSLRDAO();
}
public void init() {logger.error("DSLRServlet.init(): just started"); }
@RequestMapping(value = "/s",method = RequestMethod.GET)
public String showHTMLResponse(@modelattribute("dslrs") DSLR dslrs[],@modelattribute("dslr") DSLR dslr,@modelattribute("dslrErrors") HashMap dslrErrors,@modelattribute ("dslrform") DSLRForm dslrForm,@RequestParam("id") String paramId,@RequestParam("action") String paramAction,Model model){
if(paramId == null || paramId.equals("")){
//show_all_dslrs
dslrs = getAllDslrs(); // DSLR adslrs[] -> to MODEL; HOW?
return "dslrs";
}else{
//show_this_dslr;
HashMap@modelattribute("dslrs") DSLR dslrs[],@modelattribute("dslrErrors") HashMap,?> dslrErrors,@RequestParam("dslr_model") String paramModel,@RequestParam("price") String paramPrice,@RequestParam("description") String paramDescription,Model model){
int iStatusCode = 0;
if(paramAction.equals("save") )
iStatusCode = saveDSLR(paramId,paramModel,paramPrice,paramDescription,dslrErrors,dslrForm); // POST
return "dslrs";
}
private int saveDSLR(String paramId,String paramModel,String paramPrice,String paramDescription,HashMap,?> context_dslrErrors,DSLRForm context_dslrForm
) {
int byte0 = 1;
try {
DSLRValidaor dslrValidaor = new DSLRValidaor();
DSLRForm dslrForm = new DSLRForm();
dslrForm.setDslrId(paramId);
dslrForm.setModel(paramModel);
dslrForm.setPrice(paramPrice);
dslrForm.setDescription(paramDescription);
HashMap hashmap = dslrValidaor.Validate(dslrForm);
if(hashmap.size() > 0) {
context_dslrForm = dslrForm;
context_dslrErrors = hashmap;
byte0 = -1;
} else{
DSLRDAO planedao = new DSLRDAO();
DSLR dslr = new DSLR();
dslr.setDslrId(Integer.parseInt(paramId));
dslr.setModel(paramModel);
dslr.setPrice(Integer.parseInt(paramPrice));
dslr.setDescription(paramDescription);
planedao.update(dslr);
}
}
catch(Exception exception)
{
logger.error((new StringBuilder()).append("DSLRServlet.saveDSLR():").append(exception.getMessage()).toString());
byte0 = -1;
}
return byte0;
}
private DSLR[] getAllDslrs(){
DSLR adslrs[] = null;
try
{
DSLRDAO DSLRDAO = new DSLRDAO();
adslrs = (DSLR[])DSLRDAO.findAll();
}
catch(Exception exception)
{
logger.error((new StringBuilder()).append("PlaneServlet.getAllPlanes():").append(exception.getMessage()).toString());
}
// request.setAttribute("dslrs",adslrs);
return adslrs;
}
private HashMap
最佳答案
原文链接:https://www.f2er.com/spring/431816.html