----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
package com.curiousby.cn.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import com.curiousby.cn.one.entity.User;import com.curiousby.cn.service.UserService;@Controller@RequestMapping(value="/web/users")public class UserController { @Resource UserService userService; @ResponseBody @RequestMapping(value="/{userId}", method=RequestMethod.GET) public User getUserById(@PathVariable int userId){ return userService .findById(userId); }}
@Transactional@Servicepublic class UserService { @Resource UserDao userDao; public User findById(int userId){ return userDao.findById(userId); }}
@Transactionalpublic interface UserDao extends CrudRepository{ //crud User findById(int id);}
4.0.0 com.curiousby.cn SpringBootWebDemo war 0.0.1-SNAPSHOT SpringBootWebDemo Maven Webapp http://maven.apache.org spring-snapshots http://repo.spring.io/libs-snapshot spring-snapshots http://repo.spring.io/libs-snapshot org.springframework.boot spring-boot-starter-parent 1.3.1.RELEASE UTF-8 1.7 org.springframework.boot spring-boot-starter-redis org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat provided org.apache.tomcat.embed tomcat-embed-jasper provided javax.servlet jstl org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-data-jpa runtime mysql mysql-connector-java runtime com.google.code.gson gson SpringBootWebDemo org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-compiler-plugin 1.7 1.7 org.apache.maven.plugins maven-surefire-plugin false
spring.datasource.url=jdbc:mysql://localhost:3306/databasespring.datasource.username=rootspring.datasource.password=rootspring.datasource.driverClassName=com.mysql.jdbc.Driverspring.jpa.database=MYSQLspring.jpa.show-sql=truespring.jpa.hibernate.ddl-auto=updatespring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategyspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
![](https://yqfile.alicdn.com/img_069a299e14c0d2413cf9c9c3c6071517.png)
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。
:
![](https://yqfile.alicdn.com/img_81e700ed90042f6a809cc76caff4b5a2.png)
![](https://yqfile.alicdn.com/img_74a44b81a2d1f6112585a18c54f87eb5.jpeg)
![](https://yqfile.alicdn.com/img_4979b56769b1a2715573f5ace62e9135.png)