接着 第二章【Maven项目】maven项目的创建及配置ssm框架
测试整合后的ssm框架
1.可以使用mybatis逆向工程生成 pojo mapper 如图:
2.创建如图几个包:
测试框架,使用逆向工程生成的dao就可以,jiu不用考虑dao层
service层
@Service
public class PriceServiceImpl implements PriceService {
@Autowired
private PriceMapper priceMapper;
public Price getPriceById(int id) {
PriceExample example = new PriceExample();
Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(id);
List<Price> list = priceMapper.selectByExample(example);
if (list.size() > 0 && list != null) {
Price price = list.get(0);
return price;
}
return null;
}
}
controller
@Controller
public class PriceController {
@Autowired
private PriceService priceService;
@RequestMapping("/price/{id}")
@ResponseBody
public Price getPriceById(@PathVariable int id) {
Price price = priceService.getPriceById(id);
return price;
}
}
浏览器输入 http://localhost:8080/price/1 如图:
框架测试-OK