企业🤖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"; } } ~~~