Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
ZhangKuan
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宽
ZhangKuan
Commits
71aef10b
Commit
71aef10b
authored
Oct 26, 2016
by
胡小根
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coding
parent
7df2af27
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
9 deletions
+78
-9
CountryController.java
...pringMVCProjectTemplate/controller/CountryController.java
+78
-9
No files found.
web/src/main/java/com/haomostudio/SpringMVCProjectTemplate/controller/CountryController.java
View file @
71aef10b
package
com
.
haomostudio
.
SpringMVCProjectTemplate
.
controller
;
package
com
.
haomostudio
.
SpringMVCProjectTemplate
.
controller
;
import
com.haomostudio.SpringMVCProjectTemplate.common.Resp
;
import
com.haomostudio.SpringMVCProjectTemplate.domain.Country
;
import
com.haomostudio.SpringMVCProjectTemplate.service.ActivitiService
;
import
com.haomostudio.SpringMVCProjectTemplate.service.ActivitiService
;
import
com.haomostudio.SpringMVCProjectTemplate.service.CountryService
;
import
com.haomostudio.SpringMVCProjectTemplate.service.CountryService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Date
;
/**
/**
* Created by hxg
qh on 2016/10/
6.
* Created by hxg
on 2016/10/0
6.
*/
*/
@Controller
@Controller
public
class
CountryController
{
public
class
CountryController
{
@Autowired
@Autowired
CountryService
countryService
;
CountryService
countryService
;
@Autowired
@Autowired
HttpServletResponse
response
;
HttpServletResponse
response
;
@RequestMapping
(
value
=
"/countries"
,
@RequestMapping
(
value
=
"/countries/create"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
method
=
RequestMethod
.
GET
,
@ResponseBody
produces
=
"application/json;charset=UTF-8"
)
public
Object
createCountry
(
@RequestParam
(
value
=
"country_id"
,
required
=
false
)
Integer
country_id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
)
{
Country
item
=
new
Country
();
item
.
setCountry_id
(
country_id
);
item
.
setName
(
name
);
countryService
.
create
(
item
);
//若request param为null,但字段定义有默认值,则需从数据库中返回结果
//return countryService.get(id);
return
item
;
}
@RequestMapping
(
value
=
"/countries/{countries_id}/delete"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
deleteCountry
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"countries_id"
)
String
id
)
{
Country
item
=
countryService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be deleted doesn't exist"
);
}
countryService
.
delete
(
id
);
return
Resp
.
succ
(
"delete success"
);
}
@RequestMapping
(
value
=
"/countries/{countries_id}/edit"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
editCountry
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"countries_id"
)
String
id
,
@RequestParam
(
value
=
"country_id"
,
required
=
false
)
Integer
country_id
,
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
)
{
Country
item
=
countryService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
item
.
setCountry_id
(
country_id
);
item
.
setName
(
name
);
countryService
.
update
(
item
);
return
countryService
.
get
(
id
);
}
@RequestMapping
(
value
=
"/countries/{countries_id}"
,
method
=
RequestMethod
.
GET
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
public
Object
getCountry
(
@RequestHeader
(
value
=
"X-Auth-Token"
)
String
token
,
@PathVariable
(
value
=
"countries_id"
)
String
id
)
{
Country
item
=
countryService
.
get
(
id
);
if
(
null
==
item
)
{
response
.
setStatus
(
404
);
return
Resp
.
fail
(
"the asset to be edited doesn't exist"
);
}
return
item
;
}
@RequestMapping
(
value
=
"/countries"
,
method
=
RequestMethod
.
GET
,
produces
=
"application/json;charset=UTF-8"
)
@ResponseBody
@ResponseBody
public
Object
get
C
ountries
(
public
Object
get
c
ountries
(
@RequestHeader
(
value
=
"page_no"
)
Integer
pageNo
,
@RequestHeader
(
value
=
"page_no"
)
Integer
pageNo
,
@RequestHeader
(
value
=
"page_size"
)
Integer
pageSize
,
@RequestHeader
(
value
=
"page_size"
)
Integer
pageSize
,
@RequestHeader
(
value
=
"sort_item"
)
String
sortItem
,
@RequestHeader
(
value
=
"sort_item"
)
String
sortItem
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment