5.1创建接口
public interface ItemsService {
public Items findById(Integer id);
}
5.2实现这里使用的是注解加配置文件的方式,最后把注解一起写下来
@Service
@Transactional
public class ItemsServiceImpl implements ItemsService {
@Autowired
private ItemsDao itemsDao;
public Items findById(Integer id) {
return itemsDao.findById(id);
}
}
6.web层
@Controller
@RequestMapping("/items")
public class ItemsController {
@Autowired
private ItemsService itemsService;
@RequestMapping("/showDetail")
public String showDetail(Model model){
Items items = itemsService.findById(1);
model.addAttribute("item",items);
return "itemDetail";
}
}
原文:https://www.cnblogs.com/duansuzhexie/p/11027349.html