您的位置:首页 > 其它

第三章【Maven项目】测试整合后的SSM框架

2018-01-18 14:46 666 查看
接着 第二章【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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  娱乐
相关文章推荐