maven构建SSM工程[应用]4

5.Service
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";
}
}

猜你喜欢

转载自www.cnblogs.com/duansuzhexie/p/11027349.html
今日推荐