spring mvc 与数据库连接

servlet.xml配置:


controller代码:
@Controller
@RequestMapping(value="/test")
public class MainContrlller {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String index() {
        System.out.println(jdbcTemplate.queryForInt("select COUNT(*) from demo_org"));
        return "test";
    }
}


表:



结果:


猜你喜欢

转载自201609032307.iteye.com/blog/2339069