DemoController.java 1.29 KB
package com.springboot.template.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.springboot.template.redis.HelloRedis;
import com.springboot.template.service.JdbcService;

@Controller
@RequestMapping("/demo")
public class DemoController {
	@Autowired
	private JdbcService jdbcService;
	@Autowired
	private HelloRedis helloRedis;
	
	@RequestMapping("/sayHello")
	@ResponseBody
	public String sayHello() {
		return "hello";
	}
	
	@GetMapping("sayFromJdbc")
	@ResponseBody
	public String sayFromJdbc() {
		return this.jdbcService.queryHello();
	}
	
	@GetMapping("sayFromJpa")
	@ResponseBody
	public String sayFromJpa() {
		return this.jdbcService.queryHelloFromJpa();
	}
	
	@GetMapping("sayFromRedis")
	@ResponseBody
	public String sayFromRedis() {
		return this.helloRedis.getName();
	}
	
	@GetMapping("sayFromLogback")
	@ResponseBody
	public String sayFromLogback() {
		Logger log = LoggerFactory.getLogger(this.getClass());
		log.debug("HERE WE ARE!");
		return "wang bin logback";
	}
}