SSM框架-Spring+SpringMVC+Mybatis的使用

在上一篇文章中我详细的介绍了如何搭建SSM框架。正所谓工具再好,也要使用在正确的地方。这篇我们来教大家SSM框架如何使用

1.、在Dao层编写dao文件

public interface InfoDao {
	int selectCofirmAllCount();
	}

在xml文件中加载dao文件

<?xml version="1.0" encoding="UTF-8"?>
<!--表明实现mapper层接口的xml -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hqyj.yiqing.dao.InfoDao">

<select id="selectCofirmAllCount" resultType="java.lang.Integer">
	select sum(confirmCount) from info where code &lt; 35;
</select>
</mapper>

在service层调用dao层的方法

@Service
public class InfoService {
	@Autowired
	InfoDao dao;
	public int selectCofirmAllCount(){
		return dao.selectCofirmAllCount();
	}
}

在控制层调用service的方法

@Controller
@RequestMapping("zznb")
public class InfoController {
	@Autowired
	InfoService service;
	//查询截止当日所有确诊人数
	@RequestMapping("allCofirm.do")
	@ResponseBody	
	public int selectCofirmAllCount(){
		return service.selectCofirmAllCount();
	}
}

启动服务器,在地址栏输入:

http://localhost:8080/yiqingdemo/zznb/allCofirm.do
最后的成功结果:
在这里插入图片描述

原创文章 27 获赞 54 访问量 8227

猜你喜欢

转载自blog.csdn.net/qq1140037586/article/details/105411553