Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
louy21
JavaSpring注解练习1
提交
6bbee841
J
JavaSpring注解练习1
项目概览
louy21
/
JavaSpring注解练习1
与 Fork 源项目一致
Fork自
inscode / Java
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JavaSpring注解练习1
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6bbee841
编写于
4月 27, 2023
作者:
6
644a21526180332c2cd69bb9
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto commit
上级
2c0b3118
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
498 addition
and
0 deletion
+498
-0
src/main/java/com.louy/config/JdbcConfig
src/main/java/com.louy/config/JdbcConfig
+29
-0
src/main/java/com.louy/config/MybatisConfig
src/main/java/com.louy/config/MybatisConfig
+24
-0
src/main/java/com.louy/config/SpringConfig
src/main/java/com.louy/config/SpringConfig
+13
-0
src/main/java/com.louy/dao/AccountDao
src/main/java/com.louy/dao/AccountDao
+24
-0
src/main/java/com.louy/domain/Account
src/main/java/com.louy/domain/Account
+51
-0
src/main/java/com.louy/service/AccountService
src/main/java/com.louy/service/AccountService
+14
-0
src/main/java/com.louy/service/impl/AccountServiceImpl
src/main/java/com.louy/service/impl/AccountServiceImpl
+34
-0
src/main/resources/jdbc.properties
src/main/resources/jdbc.properties
+0
-0
src/pom.xml
src/pom.xml
+60
-0
src/test/java/AccountServiceTest
src/test/java/AccountServiceTest
+28
-0
target/classes/com.louy/config/JdbcConfig
target/classes/com.louy/config/JdbcConfig
+29
-0
target/classes/com.louy/config/MybatisConfig
target/classes/com.louy/config/MybatisConfig
+24
-0
target/classes/com.louy/config/SpringConfig
target/classes/com.louy/config/SpringConfig
+13
-0
target/classes/com.louy/dao/AccountDao
target/classes/com.louy/dao/AccountDao
+24
-0
target/classes/com.louy/domain/Account
target/classes/com.louy/domain/Account
+51
-0
target/classes/com.louy/service/AccountService
target/classes/com.louy/service/AccountService
+14
-0
target/classes/com.louy/service/impl/AccountServiceImpl
target/classes/com.louy/service/impl/AccountServiceImpl
+34
-0
target/classes/jdbc.properties
target/classes/jdbc.properties
+4
-0
target/test-classes/AccountServiceTest
target/test-classes/AccountServiceTest
+28
-0
未找到文件。
src/main/java/com.louy/config/JdbcConfig
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
config
;
import
com
.
alibaba
.
druid
.
pool
.
DruidDataSource
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Value
;
import
org
.
springframework
.
context
.
annotation
.
Bean
;
import
javax
.
sql
.
DataSource
;
public
class
JdbcConfig
{
@
Value
(
"${jdbc.driver}"
)
private
String
driver
;
@
Value
(
"${jdbc.url}"
)
private
String
url
;
@
Value
(
"${jdbc.username}"
)
private
String
name
;
@
Value
(
"${jdbc.password}"
)
private
String
pass
;
@
Bean
public
DataSource
dataSource
(){
DruidDataSource
ds
=
new
DruidDataSource
();
ds
.
setDriverClassName
(
driver
);
ds
.
setUrl
(
url
);
ds
.
setUsername
(
name
);
ds
.
setPassword
(
pass
);
return
ds
;
}
}
\ No newline at end of file
src/main/java/com.louy/config/MybatisConfig
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
config
;
import
org
.
mybatis
.
spring
.
SqlSessionFactoryBean
;
import
org
.
mybatis
.
spring
.
mapper
.
MapperScannerConfigurer
;
import
org
.
springframework
.
context
.
annotation
.
Bean
;
import
javax
.
sql
.
DataSource
;
public
class
MybatisConfig
{
@
Bean
public
SqlSessionFactoryBean
sqlSessionFactoryBean
(
DataSource
dataSource
){
SqlSessionFactoryBean
session
=
new
SqlSessionFactoryBean
();
session
.
setTypeAliasesPackage
(
"com.atheima.domain"
);
session
.
setDataSource
(
dataSource
);
return
session
;
}
@
Bean
public
MapperScannerConfigurer
mapperScannerConfigurer
(){
MapperScannerConfigurer
mapper
=
new
MapperScannerConfigurer
();
mapper
.
setBasePackage
(
"com.atheima.dao"
);
return
mapper
;
}
}
src/main/java/com.louy/config/SpringConfig
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
config
;
import
org
.
springframework
.
context
.
annotation
.
ComponentScan
;
import
org
.
springframework
.
context
.
annotation
.
Configuration
;
import
org
.
springframework
.
context
.
annotation
.
Import
;
import
org
.
springframework
.
context
.
annotation
.
PropertySource
;
@
Configuration
@
ComponentScan
(
"com.atheima"
)
@
PropertySource
(
"classpath:jdbc.properties"
)
@
Import
({
JdbcConfig
.
class
,
MybatisConfig
.
class
})
public
class
SpringConfig
{
}
src/main/java/com.louy/dao/AccountDao
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
dao
;
import
com
.
atheima
.
domain
.
Account
;
import
org
.
apache
.
ibatis
.
annotations
.
Delete
;
import
org
.
apache
.
ibatis
.
annotations
.
Insert
;
import
org
.
apache
.
ibatis
.
annotations
.
Select
;
import
org
.
apache
.
ibatis
.
annotations
.
Update
;
import
java
.
util
.
List
;
public
interface
AccountDao
{
@
Insert
(
"insert into tbl_account(name,money)values(#{name},#{money})"
)
void
save
(
Account
account
);
@
Delete
(
"delete from tbl_account where id = #{id}"
)
void
delete
(
Integer
id
);
@
Update
(
"update tbl_account set name = #{name} , money = #{money} where id = #{id}"
)
void
update
(
Account
account
);
@
Select
(
"select * from tbl_account"
)
List
<
Account
>
findAll
();
@
Select
(
"select * from tbl_account where id = #{id}"
)
Account
findById
(
Integer
id
);
}
src/main/java/com.louy/domain/Account
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
domain
;
import
java
.
io
.
Serializable
;
public
class
Account
implements
Serializable
{
private
Integer
id
;
private
String
name
;
private
Double
money
;
public
Account
()
{
}
public
Account
(
Integer
id
,
String
name
,
Double
money
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
money
=
money
;
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Double
getMoney
()
{
return
money
;
}
public
void
setMoney
(
Double
money
)
{
this
.
money
=
money
;
}
@
Override
public
String
toString
()
{
return
"Account{"
+
"id="
+
id
+
", name='"
+
name
+
'\'' +
", money=" + money +
'
}
';
}
}
src/main/java/com.louy/service/AccountService
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
service
;
import
com
.
atheima
.
domain
.
Account
;
import
java
.
util
.
List
;
public
interface
AccountService
{
void
save
(
Account
account
);
void
delete
(
Integer
id
);
void
update
(
Account
account
);
List
<
Account
>
findAll
();
Account
findById
(
Integer
id
);
}
src/main/java/com.louy/service/impl/AccountServiceImpl
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
service
.
impl
;
import
com
.
atheima
.
dao
.
AccountDao
;
import
com
.
atheima
.
domain
.
Account
;
import
com
.
atheima
.
service
.
AccountService
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
stereotype
.
Service
;
import
java
.
util
.
List
;
@
Service
public
class
AccountServiceImpl
implements
AccountService
{
@
Autowired
private
AccountDao
accountDao
;
public
void
save
(
Account
account
)
{
accountDao
.
save
(
account
);
}
public
void
delete
(
Integer
id
)
{
accountDao
.
delete
(
id
);
}
public
void
update
(
Account
account
)
{
accountDao
.
update
(
account
);
}
public
List
<
Account
>
findAll
()
{
return
accountDao
.
findAll
();
}
public
Account
findById
(
Integer
id
)
{
return
accountDao
.
findById
(
id
);
}
}
jdbc.properties
→
src/main/resources/
jdbc.properties
浏览文件 @
6bbee841
文件已移动
src/pom.xml
0 → 100644
浏览文件 @
6bbee841
<?xml version="1.0" encoding="UTF-8"?>
<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"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.louy
</groupId>
<artifactId>
springAocAnli
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
<version>
5.2.10.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jdbc
</artifactId>
<version>
5.2.10.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<version>
5.2.10.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.aspectj
</groupId>
<artifactId>
aspectjweaver
</artifactId>
<version>
1.9.4
</version>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.47
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.1.16
</version>
</dependency>
<dependency>
<groupId>
org.mybatis
</groupId>
<artifactId>
mybatis
</artifactId>
<version>
3.5.6
</version>
</dependency>
<dependency>
<groupId>
org.mybatis
</groupId>
<artifactId>
mybatis-spring
</artifactId>
<version>
1.3.0
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/test/java/AccountServiceTest
0 → 100644
浏览文件 @
6bbee841
import com.atheima.config.SpringConfig;
import com.atheima.domain.Account;
import com.atheima.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class AccountServiceTest {
@Autowired
private AccountService accountService;
@Test
public void test(){
System.out.println(accountService.findAll());
}
@Test
public void testFindById(){
Account ac = accountService.findById(1);
System.out.println(ac);
}
}
\ No newline at end of file
target/classes/com.louy/config/JdbcConfig
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
config
;
import
com
.
alibaba
.
druid
.
pool
.
DruidDataSource
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Value
;
import
org
.
springframework
.
context
.
annotation
.
Bean
;
import
javax
.
sql
.
DataSource
;
public
class
JdbcConfig
{
@
Value
(
"${jdbc.driver}"
)
private
String
driver
;
@
Value
(
"${jdbc.url}"
)
private
String
url
;
@
Value
(
"${jdbc.username}"
)
private
String
name
;
@
Value
(
"${jdbc.password}"
)
private
String
pass
;
@
Bean
public
DataSource
dataSource
(){
DruidDataSource
ds
=
new
DruidDataSource
();
ds
.
setDriverClassName
(
driver
);
ds
.
setUrl
(
url
);
ds
.
setUsername
(
name
);
ds
.
setPassword
(
pass
);
return
ds
;
}
}
\ No newline at end of file
target/classes/com.louy/config/MybatisConfig
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
config
;
import
org
.
mybatis
.
spring
.
SqlSessionFactoryBean
;
import
org
.
mybatis
.
spring
.
mapper
.
MapperScannerConfigurer
;
import
org
.
springframework
.
context
.
annotation
.
Bean
;
import
javax
.
sql
.
DataSource
;
public
class
MybatisConfig
{
@
Bean
public
SqlSessionFactoryBean
sqlSessionFactoryBean
(
DataSource
dataSource
){
SqlSessionFactoryBean
session
=
new
SqlSessionFactoryBean
();
session
.
setTypeAliasesPackage
(
"com.atheima.domain"
);
session
.
setDataSource
(
dataSource
);
return
session
;
}
@
Bean
public
MapperScannerConfigurer
mapperScannerConfigurer
(){
MapperScannerConfigurer
mapper
=
new
MapperScannerConfigurer
();
mapper
.
setBasePackage
(
"com.atheima.dao"
);
return
mapper
;
}
}
target/classes/com.louy/config/SpringConfig
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
config
;
import
org
.
springframework
.
context
.
annotation
.
ComponentScan
;
import
org
.
springframework
.
context
.
annotation
.
Configuration
;
import
org
.
springframework
.
context
.
annotation
.
Import
;
import
org
.
springframework
.
context
.
annotation
.
PropertySource
;
@
Configuration
@
ComponentScan
(
"com.atheima"
)
@
PropertySource
(
"classpath:jdbc.properties"
)
@
Import
({
JdbcConfig
.
class
,
MybatisConfig
.
class
})
public
class
SpringConfig
{
}
target/classes/com.louy/dao/AccountDao
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
dao
;
import
com
.
atheima
.
domain
.
Account
;
import
org
.
apache
.
ibatis
.
annotations
.
Delete
;
import
org
.
apache
.
ibatis
.
annotations
.
Insert
;
import
org
.
apache
.
ibatis
.
annotations
.
Select
;
import
org
.
apache
.
ibatis
.
annotations
.
Update
;
import
java
.
util
.
List
;
public
interface
AccountDao
{
@
Insert
(
"insert into tbl_account(name,money)values(#{name},#{money})"
)
void
save
(
Account
account
);
@
Delete
(
"delete from tbl_account where id = #{id}"
)
void
delete
(
Integer
id
);
@
Update
(
"update tbl_account set name = #{name} , money = #{money} where id = #{id}"
)
void
update
(
Account
account
);
@
Select
(
"select * from tbl_account"
)
List
<
Account
>
findAll
();
@
Select
(
"select * from tbl_account where id = #{id}"
)
Account
findById
(
Integer
id
);
}
target/classes/com.louy/domain/Account
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
domain
;
import
java
.
io
.
Serializable
;
public
class
Account
implements
Serializable
{
private
Integer
id
;
private
String
name
;
private
Double
money
;
public
Account
()
{
}
public
Account
(
Integer
id
,
String
name
,
Double
money
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
money
=
money
;
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
Double
getMoney
()
{
return
money
;
}
public
void
setMoney
(
Double
money
)
{
this
.
money
=
money
;
}
@
Override
public
String
toString
()
{
return
"Account{"
+
"id="
+
id
+
", name='"
+
name
+
'\'' +
", money=" + money +
'
}
';
}
}
target/classes/com.louy/service/AccountService
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
service
;
import
com
.
atheima
.
domain
.
Account
;
import
java
.
util
.
List
;
public
interface
AccountService
{
void
save
(
Account
account
);
void
delete
(
Integer
id
);
void
update
(
Account
account
);
List
<
Account
>
findAll
();
Account
findById
(
Integer
id
);
}
target/classes/com.louy/service/impl/AccountServiceImpl
0 → 100644
浏览文件 @
6bbee841
package
com
.
atheima
.
service
.
impl
;
import
com
.
atheima
.
dao
.
AccountDao
;
import
com
.
atheima
.
domain
.
Account
;
import
com
.
atheima
.
service
.
AccountService
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
stereotype
.
Service
;
import
java
.
util
.
List
;
@
Service
public
class
AccountServiceImpl
implements
AccountService
{
@
Autowired
private
AccountDao
accountDao
;
public
void
save
(
Account
account
)
{
accountDao
.
save
(
account
);
}
public
void
delete
(
Integer
id
)
{
accountDao
.
delete
(
id
);
}
public
void
update
(
Account
account
)
{
accountDao
.
update
(
account
);
}
public
List
<
Account
>
findAll
()
{
return
accountDao
.
findAll
();
}
public
Account
findById
(
Integer
id
)
{
return
accountDao
.
findById
(
id
);
}
}
target/classes/jdbc.properties
0 → 100644
浏览文件 @
6bbee841
jdbc.username
=
root
jdbc.password
=
123456
jdbc.url
=
jdbc:mysql://localhost:3306/spring_db?serverTimezone=UTC
jdbc.driver
=
com.mysql.jdbc.Driver
\ No newline at end of file
target/test-classes/AccountServiceTest
0 → 100644
浏览文件 @
6bbee841
import com.atheima.config.SpringConfig;
import com.atheima.domain.Account;
import com.atheima.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class AccountServiceTest {
@Autowired
private AccountService accountService;
@Test
public void test(){
System.out.println(accountService.findAll());
}
@Test
public void testFindById(){
Account ac = accountService.findById(1);
System.out.println(ac);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录