<project xmlns=“http://maven.apache.org/POM/4.0.0”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
com.rosam
ywt
1.0-SNAPSHOT
org.apache.maven.
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
plugins
maven-war-plugin
2.6
false
org.springframework.boot
spring-boot-maven-plugin
org.springframework.boot
spring-boot-starter-parent
1.4.3.RELEASE
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.1
mysql
mysql-connector-java
runtime
在看application.properties中配置mysql,和mybatis中的mapper路径,和实体路径(resources文件夹就可)
#数据库设置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ywttest
spring.datasource.username=root
spring.datasource.password=root
#mybatis_config
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.rosam.ywttest.entity
controller层的代码(com.rosam.ywttest.controller)
package com.rosam.ywttest.controller;
import com.rosam.ywttest.entity.User;
import com.rosam.ywttest.service.YwtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.xml.ws.Action;
@Controller
public class YwtController {
@Autowired
private YwtService ywtService;
@RequestMapping("/ywt/{id}")
public void test(@PathVariable int id){
User user=ywtService.find(id);
System.out.println(user.getName());
}
}
service层的代码:(com.rosam.ywttest.service)
package com.rosam.ywttest.service;
import com.rosam.ywttest.dao.YwtDAO;
import com.rosam.ywttest.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class YwtService {
@Autowired
private YwtDAO ywtDAO;
public User find(int id){
User user=ywtDAO.find(id);
return user;
}
}