你好,我使用springboot,想显示mysql数据库的某条记录,结果出现了这样的错误、
Description:
Parameter 0 of method check in com.example.demo.dao.CangpinDao required a bean of type 'java.lang.String' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'java.lang.String' in your configuration.
这是为什么啊?
附代码
这是Dao层的代码
package com.example.demo.dao;
import com.example.demo.bean.Cangpin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository
public class CangpinDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public void save(Cangpin cangpin){
jdbcTemplate.update("insert into cangpin(xuhao,path2,sys,cangpinname,yuanjia,xianjia,num) values (?,?,?,?,?,?,?)",
cangpin.getXuhao(),cangpin.getPath2(),cangpin.getSys(),cangpin.getCangpinname(),
cangpin.getYuanjia(),cangpin.getXianjia(),cangpin.getNum());
}
@Autowired
public void check(String a){
jdbcTemplate.execute("select * from cangpin where xuhao = "+a);
}
}
这是Bean的代码
package com.example.demo.bean;
public class Cangpin {
private long xuhao;
private String path2;
public String getPath2() {
return path2;
}
public void setPath2(String path2) {
this.path2 = path2;
}
private String sys;
public long getXuhao() {
return xuhao;
}
public void setXuhao(long xuhao) {
this.xuhao = xuhao;
}
public String getSys() {
return sys;
}
public void setSys(String sys) {
this.sys = sys;
}
public String getCangpinname() {
return cangpinname;
}
public void setCangpinname(String cangpinname) {
this.cangpinname = cangpinname;
}
public double getYuanjia() {
return yuanjia;
}
public void setYuanjia(double yuanjia) {
this.yuanjia = yuanjia;
}
public double getXianjia() {
return xianjia;
}
public void setXianjia(double xianjia) {
this.xianjia = xianjia;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
private String cangpinname;
private double yuanjia;
private double xianjia;
private int num;
}
这是Controller
```java
package com.example.demo.controller;
import com.example.demo.bean.Cangpin;
import com.example.demo.dao.CangpinDao;
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.ResponseBody;
@Controller
public class CangpinController {
@Autowired
private CangpinDao cpDao;
@RequestMapping("/save")
public String getCpDao() {
Cangpin cp=new Cangpin();
cp.setXuhao(1);
cp.setPath2("da");
cp.setSys("ss");
cp.setCangpinname("银币");
cp.setYuanjia(188.0);
cp.setXianjia(18.0);
cp.setNum(8844);
cpDao.save(cp);
return "插入成功";
}
@RequestMapping("/check")
public void getCheck()
{
System.out.println("藏品");
}
}
这是为什么呢?请回答。