0
Spring Boot | MyBatisMyBatis @Mapper聲明
當我嘗試在控制器中聲明一個mybatis映射器時,它會被IDE強調,並且不會編譯。
@Controller
@RequestMapping("demo")
@MapperScan("com.sample.mapper")
public class MessageController {
private static final String MESSAGE = "message";
private static final String INDEX = "index";
@Autowired
private MessageMapper messageMapper;
@RequestMapping("printMessage/{message}")
public String printMessage(ModelMap modelMap) {
modelMap.addAttribute(MESSAGE, "M");
return INDEX;
}
@RequestMapping("printHello")
public String printHello(ModelMap modelMap) {
modelMap.addAttribute(MESSAGE, "Hello, ");
return INDEX;
}
我得到這個編譯的類莫名其妙近日,但是,當我嘗試使用messageMapper例如,像messageMapper.insert()
因爲它沒有分配任何價值,它給我的NullPointerException。看起來春天由於某種原因不適合我。