普通类直接调用spring方法会显示调用的是空指针,查资料解决
//Service接口
public interface TestService {
//查询方法
public String selectData(String params);
}
//service实现类,添加注解@Service
@Service("TestService")
public class TestServiceImpl implements TestService {
@Override
public String selectData(String params) {
return testMapper.selectData(params);
}
}
//Controller类,添加注解@Controller及值
@Controller("TestController")
public class TestController {
/**
* 定义TestService.
*/
@Autowired
private TestService testService;
public String selectData(String params) {
String str = testService.selectData();