GivePoint 생성
18182 단어 STS
STS 설정
Package Explore
src&test 폴더를 마우스 오른쪽 단추로 클릭하여 [Delete]에서 삭제합니다.
다음은 src/main/java입니다.example.demo에서 Java 클래스 파일을 삭제합니다.
pom.xml<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>GivePoint</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>GivePoint</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<!-- (1) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- (2) -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- (3) -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.lazyluke</groupId>
<artifactId>log4jdbc-remix</artifactId>
<version>0.2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- (3) -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
<!-- (4) -->
</properties>
</project>
App.javapackage com.customer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
/** アプリケーションクラス */
@EnableAutoConfiguration
@ComponentScan
public class App {
/** Spring BOOTはおなじみのmainメソッドから始まる
* @param args Java実行時の引数
* */
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
AppConfig.javapackage com.customer;
import javax.sql.DataSource;
import net.sf.log4jdbc.Log4jdbcProxyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** 設定などを管理するConfigクラス */
@Configuration
public class AppConfig {
// データソース設定のプロパティを格納
@Autowired
DataSourceProperties dataSourceProperties;
// データソース
DataSource dataSource;
@Bean
DataSource realDataSource() {
// データソースインスタンスを作る
DataSourceBuilder factory = DataSourceBuilder.create(this.dataSourceProperties.getClassLoader())
.url(this.dataSourceProperties.getUrl()).username(this.dataSourceProperties.getUsername())
.password(this.dataSourceProperties.getPassword());
this.dataSource = factory.build();
return this.dataSource;
}
// log4JDBCをつかうために
@Bean
DataSource dataSource() {
return new Log4jdbcProxyDataSource(this.dataSource);
}
}
CustomerRestController.javapackage com.customer.api;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.customer.service.CustomerService;
@RestController
public class CustomerRestController {
@Autowired
CustomerService customerService;
@RequestMapping(value = "addpoint/{point}", method = RequestMethod.GET)
int addPoint(@PathVariable int point) {
int appdateRows = customerService.addPoint(point);
return appdateRows;
}
}
ustomerRepository.javapackage com.customer.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;
@Repository
public class CustomerRepository {
@Autowired
NamedParameterJdbcTemplate jdbcTemplate;
public int addPoint(int point) {
SqlParameterSource param = new MapSqlParameterSource()
.addValue("point", point).addValue("id", 1);
int updatedRows = jdbcTemplate.update(
"UPDATE AmountCustomer SET Point = Point + :point WHERE Id = :id", param);
return updatedRows;
}
}
CustomerService.javapackage com.customer.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.customer.repository.CustomerRepository;
@Service
public class CustomerService {
@Autowired
CustomerRepository customerRepository;
public int addPoint(int point) {
int updateRows = customerRepository.addPoint(point);
return updateRows;
}
}
application.propertiesspring.datasource.url=jdbc:mysql://localhost/kigyoudb
spring.datasource.username=user
spring.datasource.password=12345
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=validate
Reference
이 문제에 관하여(GivePoint 생성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ponchan/items/49bf9d9ecad1f51e4648
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>GivePoint</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>GivePoint</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<dependencies>
<!-- (1) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- (2) -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- (3) -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.lazyluke</groupId>
<artifactId>log4jdbc-remix</artifactId>
<version>0.2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- (3) -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
<!-- (4) -->
</properties>
</project>
package com.customer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
/** アプリケーションクラス */
@EnableAutoConfiguration
@ComponentScan
public class App {
/** Spring BOOTはおなじみのmainメソッドから始まる
* @param args Java実行時の引数
* */
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
package com.customer;
import javax.sql.DataSource;
import net.sf.log4jdbc.Log4jdbcProxyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** 設定などを管理するConfigクラス */
@Configuration
public class AppConfig {
// データソース設定のプロパティを格納
@Autowired
DataSourceProperties dataSourceProperties;
// データソース
DataSource dataSource;
@Bean
DataSource realDataSource() {
// データソースインスタンスを作る
DataSourceBuilder factory = DataSourceBuilder.create(this.dataSourceProperties.getClassLoader())
.url(this.dataSourceProperties.getUrl()).username(this.dataSourceProperties.getUsername())
.password(this.dataSourceProperties.getPassword());
this.dataSource = factory.build();
return this.dataSource;
}
// log4JDBCをつかうために
@Bean
DataSource dataSource() {
return new Log4jdbcProxyDataSource(this.dataSource);
}
}
package com.customer.api;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.customer.service.CustomerService;
@RestController
public class CustomerRestController {
@Autowired
CustomerService customerService;
@RequestMapping(value = "addpoint/{point}", method = RequestMethod.GET)
int addPoint(@PathVariable int point) {
int appdateRows = customerService.addPoint(point);
return appdateRows;
}
}
package com.customer.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;
@Repository
public class CustomerRepository {
@Autowired
NamedParameterJdbcTemplate jdbcTemplate;
public int addPoint(int point) {
SqlParameterSource param = new MapSqlParameterSource()
.addValue("point", point).addValue("id", 1);
int updatedRows = jdbcTemplate.update(
"UPDATE AmountCustomer SET Point = Point + :point WHERE Id = :id", param);
return updatedRows;
}
}
package com.customer.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.customer.repository.CustomerRepository;
@Service
public class CustomerService {
@Autowired
CustomerRepository customerRepository;
public int addPoint(int point) {
int updateRows = customerRepository.addPoint(point);
return updateRows;
}
}
spring.datasource.url=jdbc:mysql://localhost/kigyoudb
spring.datasource.username=user
spring.datasource.password=12345
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=validate
Reference
이 문제에 관하여(GivePoint 생성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ponchan/items/49bf9d9ecad1f51e4648텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)