提交 7b3eec68 authored 作者: mry's avatar mry

1

上级 781fd239
......@@ -2,6 +2,7 @@ package com.jpa.jpaspringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class JpaSpringBootApplication {
......
......@@ -3,10 +3,8 @@ package com.jpa.jpaspringboot.controller;
import com.jpa.jpaspringboot.entity.User;
import com.jpa.jpaspringboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -16,17 +14,22 @@ import java.util.List;
@RestController
@CrossOrigin
@RequestMapping("user")
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("find")
@RequestMapping(value = "/find",method = RequestMethod.GET)
public List<User> find(){
return userService.find();
}
@RequestMapping(value = "/add",method = RequestMethod.PUT)
public Object add(){
userService.add();
return 200;
}
}
......@@ -19,4 +19,14 @@ public class UserServiceImpl implements UserService {
public List<User> find() {
return userDao.findAll();
}
@Override
public void add() {
User user = new User();
user.setSex("男");
user.setName("436");
user.setId(12);
user.setName("哈哈哈");
userDao.save(user);
}
}
......@@ -6,4 +6,6 @@ import java.util.List;
public interface UserService {
List<User> find();
void add();
}
package com.jpa.jpaspringboot.utils;
public class JpaUtils {
}
......@@ -8,5 +8,19 @@ spring.jpa.properties.hibernate.hbm2ddl.auto=update
#d端口号设置
server.port=8080
server.tomcat.uri-encoding=UTF-8
#显示数据库执行语句
spring.jpa.show-sql=true
\ No newline at end of file
#Spring Data JPA
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
#视图层控制
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**
\ No newline at end of file
......@@ -6,8 +6,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
class JpaSpringBootApplicationTests {
......@@ -16,10 +14,12 @@ class JpaSpringBootApplicationTests {
@Test
void testFindAll() {
List<User> list = userDao.findAll();
for (User user : list){
System.out.println(user);
}
User user = new User();
user.setSex("男");
user.setName("123");
user.setId(11);
user.setSex("女");
userDao.save(user);
}
}
......@@ -80,5 +80,9 @@ public class ManyToManyTest {
}
@Test
public void test0(){
System.out.println(1);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论