ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
绑定一个路由只需要在类用@Controller处理并且方法用@RequestMapping(value="路由规则")处理 ~~~ package server; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import java.util.Map; import javax.annotation.Resource; import org.springframework.jdbc.core.JdbcTemplate; @Controller public class Test { @Resource(name="jdbcTemplate") private JdbcTemplate jdbcTemplate; @RequestMapping(value="/") @ResponseBody public String func(){ return "hello"; } @RequestMapping(value="/t") public String t(){ return "index"; } @RequestMapping(value="/sql") @ResponseBody public String sql(){ String sql = "insert into temp1(title) values('测试')"; jdbcTemplate.update(sql); return "ok"; } @RequestMapping(value="/find") @ResponseBody public String findAll(){ String sql = "select * from temp1;"; java.util.List<Map<String, Object>> r = jdbcTemplate.queryForList(sql); for (Map<String, Object> map : r) { System.out.println(map.get("title")); } return "ok"; } public String find(){ return "ok"; } } ~~~